Link to home
Start Free TrialLog in
Avatar of danchuee
danchuee

asked on

tree or linklist

I'm working on a chat system right now.

Say I have one State (or room) (name Ohio) and within that state are counties, say 2 of them ( name Orange, Apple) and within each county is a city (name A,B,C,D,E,F). Each person can be part of a group. Now because someone is part of a group doesn't mean that they are in the same county.

Each person can only be in one state, county and city at a time. A person can be in county and not in a city. A person can't be county and in a city.

                     Ohio
                    /     \
              Orange        Apple
             /   |   \    /   |   \
            A    B    C  D    E    F

I'm planning to handle 5-10 people at a time. (I would like to have something to handle more but it's not needed right now). I'm trying to find out which would be faster and more effecient and how to code it. I'm thinking a tree would be better suited to handle this because I wouldn't have to go thru each member if I know exactly which level of the tree I wanted to transmit too. (did I say that right).

But then I run into the problem that 'Hey I want to tell my friend hi'. Well the program doesn't know where exactly that person is so it would have to go thru the whole tree to find that person. Then maybe a linklist would be better since I wouldn't have to create a tree and the code would be much smaller.

Maybe I could use a database to store where people are? That way, I could find them pretty quickly? But then if people are telling people hi alot, then processing for the database would rise significantly.

I haven't started with the actual code because I want to get some information and a better idea on what might be better.
Avatar of wad4ever
wad4ever

Consider using a hash map to identify exactly where the user is. I assume that usernames are unique, so the hash key would just me the username (or user ID number, if such an animal exists). Also, this is nice because it will easily handle massive numbers of users.

Hope this helps!

--- Eric
ASKER CERTIFIED SOLUTION
Avatar of mathbiol
mathbiol

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with mathbiol