mIRC Homepage
Posted By: OrFeAsGr Hashtables Question.. - 02/09/16 11:47 AM
Hi!
I'm creating something lately, a long term project as my time is kinda limited for now.
In that project there is a "database" with registered users and info and other stuff.
I don't have any problem with hashtables, not anymore, i can make, save, load, edit them very easily.. but i was wondering...
Right nw i am using 1 hashtable where each item is a user and data is some info seperated with ~ so i can use spaces in each part of info and still be able to get them seperately with $gettok .
But it would be a lot easier to get the info i need if i had a diff hashtable for each user.
So at last, my question is: should i keep using one hadhtable or try out seperate for each user? Would that make mirc heavy or slower? And apart from that what do you find more efficient and "right".
Thanks!
-OrFeAsGr
Posted By: Wims Re: Hashtables Question.. - 02/09/16 01:13 PM
It depends on the data you want to store and what you are doing to do with it.
if you are going to have unknown data, then your current method is a bad idea because ~ could appear in there, screwing up the tokens. If you're going to have at least two optional data, it's the same idea (with only one optional data, you can put it as the last token).
For accessing data, one hash table per users would be better, but for finding data, you would need to loop through all the hash tables while with the current method, a good $hfind will do the trick, so even efficiency wise, it depends on what you're going to do.
Posted By: FroggieDaFrog Re: Hashtables Question.. - 05/09/16 08:55 PM
An alternative would be instead of storing data for each user as a single item, with its data seperated by ~, you could use an item naming convention to break up a user's data into multiple items:

For example lets say your user data was akin to:
Code:
Item: SomeUser Data: John~Doe~20~Male


Instead, use something similar to the following:
Code:
Item: FirstName.SomeUser Data: John
Item: LastName.SomeUser  Data: Doe
Item: Age.SomeUser       Data: 20
Item: Gender.SomeUser    Data: Male


This has the benefit of being able to search and retrieve a user's data using just native identifiers.
Posted By: Y4kuzi Re: Hashtables Question.. - 06/09/16 12:53 AM
In Provision IRC Services I use ':' as a separator.
Never had any problems, will most certainly use the same method for ProvisionIRCd.

This will be executed upon a successful NickServ registration command:
Code:

hadd rnicks %nick $+($5,:,$6,:,$ctime,:,$ctime,:,$live_chost(%nick),:,$live_rhost(%nick),:dW5rbm93bg==,:,$encode($rname(%nick),m))

Format:
password:email:regtime:lastseen:cloakhost:realhost:quitmsg:realname

If, for example, the cloakhost changes, all you need to do is change the 5th position.
But in the end, it all depends on your own personal preference.
© mIRC Discussion Forums