mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 3 1 2 3
#199058 08/05/08 03:35 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
What's the difference between hsh and txt files? Is one better then the other? If so, why is it better?


I registered; you should too.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Nothing but the extension. You can save data using any extension you like... even ones used by other programs (such as .avi). It doesn't really matter, though it could be confusing to use something that another program uses. It's the contents that make the difference... not the extension.

Often, people use .hsh when saving hash tables just so that they know it's hash table data, but that's entirely up to the individual.


Invision Support
#Invision on irc.irchighway.net
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Why do people use hash files much more then text files? Is there a benefit? mIRC /help hash says "Hash tables allow you to efficiently store large amounts of information which can be quickly referenced and retrieved later on." You can store large amounts of information with text files too. So what are the pro's and con's of each kind?


I registered; you should too.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Hash tables are stored in RAM
Files are stored on your hard drive, so they are speed limited by the speed of your hard drive. Even the fastest drives that I know of, 10000 rpms, are so much slower than the slowest ram, that it's almost not worth bothering with a test.

If you want to see a test, I can do one later on a customized system built to those specifications.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The benefit isn't in the files. Once you've loaded a file into a hash table using the /hload command the data is stored in memory, which means it's several orders of magnitude faster than accessing a file directly each time.

Alternatively you could read the contents of a text file into multiple global variables in order to speed up access, but it's generally uglier in terms of code and you lose efficiency of the powerful built-in searching capabilities available to hash tables via $hfind.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Okay, so I read up on the mIRC /help HASH

First, you /hmake

I dont understand "eg. if you expect that you'll be storing 1000 items in the table, a table of N set to 100 is quite sufficient."

Lets say I'm expecting 10,000 userhost. Why wouldn't the /hmake be set to 10,000?

Also, how can i visualize a hash table?

name info1 info2 info3
apple qwe wrtg sdgf
orange sdfg gdrty utgh

???


I registered; you should too.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
If you set 10,000 you will be using 10 thousand times more memory than if you used.. say, 1000, which would be sufficient according to the docs.

Of course generally speaking we're only talking about 200kb to 2mb more memory (depending on the internal size of the hash table), but it's still plenty more. If you're making many of these tables they will add up.

The reason is a hash table expands dynamically.. there's some hash table theory behind the size of N that can be explained on google, it's a bit too heavy to go into detail here. The rule of thumb is "expected size divided by 10" if the expected size is big. If you know the exact size and it's relatively small, you can set that exactly.. like N=100

To visualize a table you can loop through it with $hget(name, %i) .. There is probably a snippet out there somewhere to do this... check http://www.mirc.net or http://www.mircscripts.org for that.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
/hmake (creates table in memory)
/hload (loads file into memory - does this load the whole file?)
/hadd (to add/replace item
/hfind (to find an item)
/hget (to look up an item)
/hdel (to delete an item)
/hfree (to free an existing table from memory)
/hsave (to save a table from memory to file)

Do I understand this correctly?


I registered; you should too.
Joined: Jan 2006
Posts: 111
N
Vogon poet
Offline
Vogon poet
N
Joined: Jan 2006
Posts: 111
This is an old discussion and I can remember that I said that ini files are stored in memory too. See /help /flushini. I think working with ini files is much more easier than working with hsh files.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
You'd be wrong if you said that.

ini files are *cached* by Windows but *not* necessarily in active memory. They're likely to be paged out onto disk, in fact. The file access cache is still slower than active memory. Working with ini files is not easier, by any means. The only caveat of hash files is using them in write-mode.. of course, /writeini doesn't cache at all, so hash tables are still more efficient, just a bit more work to save them periodically (if you need to write out changes).


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Okay I want to start out with making a very small hash file. I have a checkbot alias:


Code:
botcheck %nick %host %chan

alias botcheck {
  if ($istok(1.2.3.4 5.6.7.8 2.3.4.5 6.7.8.9 3.4.5.6 7.8.9.0, $2, 32)) {
    echo 4 -s $1 at $2 on $3
    echo 4 -s -
    msg $3 bot: $1
  }
  return
}


So to change it to use a hash table:

Code:
botcheck %nick %host %chan

alias botcheck {
  if ($hfind(bots, $2, 1)) {
    echo 4 -s $1 at $2 on $3
    echo 4 -s -
    msg $3 bot: $1
  }
  return
}


I registered; you should too.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
AWEstun:

It's all in the help file. If you have a specific issue, feel free to ask the question.. but if you're asking us to read the help file to you then I don't see the point.

edit:

Your code has no hash table stuff in it. Why not start out by adding your hash table code and *then* asking if it's right/wrong? ...Actually, you only really need to ask if it's wrong smile

Last edited by argv0; 08/05/08 06:51 PM.

- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Please don't be SO FORWARD. I am reading the mIRC /help and I have questions. I appreciate all the help from people. I want to learn how to start using hash tables.

This is in the remote.ini file:

Code:
botcheck %nick %host %chan

alias botcheck {
  if ($hfind(bots, $2, 1)) {
    echo 4 -s $1 at $2 on $3
    echo 4 -s -
    msg $3 bot: $1
  }
  return
}


This is in the alias.ini file:

Code:
/mbot //hmake -s bots 1
/mbots //hmake -s bots 1
/lbot //hload -s bots bots.hsh
/addbot //hadd -s bots $$1
/delbot //hdel -s bots $$1
/sbots //hsave -s bots bots.hsh
/freebot //hfree -s bots


I registered; you should too.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
You never want to use "1" as the size of the hash table, you should really use a minimum of 100. I forgot to mention that.. the "rule of thumb" applies to large values, not small ones.

You also should design your htable to make as little use of $hfind as possible..

$hget(name, ITEM) is the fastest way to access data associated with ITEM (it's the point of hash tables after all).. Try to use $hget to access your data unless you really need to *search*.. I doubt you do.

Do you have any specific issues with the code? I'm not sure what else to say... Like I said, you get better answers if you ask specific questions.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
So instead of $hfind, I can use $hget, like this?

Code:
alias botcheck {
  if ($hget(bots, $2)) {
    echo 4 -s $1 at $2 on $3
    echo 4 -s -
    msg $3 bot: $1
  }
  return
}


I registered; you should too.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
It depends. is $2 the key?

Question: Do you know how ini files work? Because hash tables work exactly the same way.

An ini file is like:

[section]
key=value

a hash table is like:

[tablename]
key=value

But in memory.. not a file

So $hget(tablename, key) would be value, just like $readini(file, section, key)



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
$2 is the host which is the IP: 1.2.3.4

Haven't used hash or ini tables until now.

I'm just starting to learn how hash tables work.


I registered; you should too.
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
How would I 'echo' out the contents of of a table with a echo line command at the command promt?

Somethings not right with that $hget command. When I tried:

if ($hget(bots,$2)) {

where $2 is the current user's host, it wasn't executing for the hosts inside the bots table. I saw several of the bot hosts in the bots table not tribber.

When I put:

$hfind(bots,$2,1)

it started working again.


I registered; you should too.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You probably wouldn't want to echo the entire contents of the table, but if you did, here's what you would use from the command prompt. Replace all occurances of <table> with the name of the hash table created using the /hmake command.

Code:
//var %a = 1, %b = $hget(<table>,0).item | while %a <= %b { echo -a $hget(<table>,%a).item is $hget(<table>,%a) | inc %a }

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thanks. I just wanted to verify the 6 hosts in the table. They are there.

Do you have any idea why the $hfind works for me, but the $hget doesn't?


I registered; you should too.
Page 1 of 3 1 2 3

Link Copied to Clipboard