mIRC Home    About    Download    Register    News    Help

Print Thread
#136011 21/11/05 09:31 AM
B
bapplander
bapplander
B
Well I think i kinda know what hashtables are, but would someone give me a two minutes lesson about it?

Basiclly, its faster to use a hashtable than reading the same datas from a .txt file (filter)?
Can you make fields in the table (like Age, Sex,, Location) and then search those fields?
What happends with the hashtable if computer is rebooted or mirc closed?
Is there any way i can see which hashtables i have?
How is data added/sorted to the hashtable? Like newest entry first? And is it possible to f.ex. limit the hashtable to 50k inputs, and delete the oldest everytime a new datat is added?

Ty. smile

#136012 21/11/05 10:00 AM
Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Hash tables are the fastest way of storing and retrieving information, even over variables, which are faster than txt or ini files.
Regarding fields, in a manner of speaking they can be used, and hash tables can be searched
Unless a hash table is saved to your hard drive, if your computer gets rebooted, then you'll loose anything that was in the hash table, since the tables are stored in your computers RAM. This is why most scripts that use hash tables have sections like
Code:
 on *:exit:{ .hsave <table> <file> }
on *:disconnect:{ .hsave <table> <file> }
 


Where <table> is the name of the hash table, and <file> is the name of the file that you want the table to be stored in.

I normally use a file that has the same name as the table and a .hsh extension

Regarding viewing a hash table, I personally like using Hash Sandwich by Mr Foot

Data is added to a hash table using the following command structure
Code:
 /hadd -m &lt;table&gt; &lt;item&gt; &lt;data&gt; 

<table> is the name of the hash table
<item> would be like the field
<data> is the information

Data in a hash table is not sorted by default, although there are ways of sorting it. If you have information stored in a hash table in an item, and go to add informtion with that same item, the old information gets overwritten (for lack of a better term)

There are a couple of Hash table tutorials on http://www.mircscripts.org but I've not used them, so I don't know how good they are.

I strongly recommend reading the mIRC help file on Hash Tables, it's actually pretty good.

Hope this helps, and if you have any further questions, I'm quite sure that someone will be happy to try to answer them, but please note that the best answers come from being able to see a script/code that you've started or are working on, and where you have a specific question about how to do something or why something isn't working.

#136013 21/11/05 11:30 AM
B
bapplander
bapplander
B
Thanx Russel. =)

Short questiuon about storing and item.
What exactly would item (have to) be?
Lets say i want to store a cityname in my hashtable called 'city'.
Code:
/hadd -m city SinCity

What would happend if i another time tried to store exactly the same city into the table? Or could i first create fields in the table, aka <ctime> <city> and then check if existing <ctime> is lower than current, and if true=do nothing..? :X

#136014 21/11/05 01:30 PM
Joined: Jan 2003
Posts: 247
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 247
if you re-use an existing key, the data will be overwritten.

#136015 21/11/05 08:29 PM
Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
The way that I keep information in the hash tables from being overwritten is to do one or more of the following:
A) Use $address as the item
Code:
 /hadd -m Names $address $nick 

B) Use $address in conjunction with other items
Code:
 /hadd -m Info $+(Name.,$address) $nick 

C) Use tokens to store multiple entries in one item
Code:
  ON *:NICK:{
.hadd -m Info $+(Name.,$address) $addtok($hget(Info,$+(Name.,$address)),$newnick,32)
} 

#136016 22/11/05 08:01 AM
D
DaveC
DaveC
D
Here is a very simple explanation of what a hash table is
If you understand what variables are, you already almost understand what a hashtable is.

A hashtable can be looked at like a special box for variables, and you can set, retrieve, search and sort(somewhat) the variables in the box, you can even save and reload the whole box in one shoot.

What i mean by that above...

When you set a variable say %blah to 123T you go /set %blah 123T
When you set a variable in a hashtable you loose the % but gain the hashtable name, lets call the hashtable GOBS, so you go /hadd -m GOBS blah 123T

When accessing a variable its just %blah but from a hashtable its $hget(BOBS,blah) ie $hget(<tablename>,<variablename>)

So some of the questions you asked I hope can instantly become clearer to you, ie: if you change a variable to something else, you loose the old contents, well exactly the same rules apply for hashtables.


Link Copied to Clipboard