|
|
Joined: Jan 2003
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: Jan 2003
Posts: 127 |
I need help on making hash table! I need to save the nick of a query open, and when the query is close and open again, the nick of the query would be save again! When disconnected, table is purge? Any help
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
On *:OPEN:?: hadd -m MyTable $nick [data] On *:CLOSE:?: if ($hget(MyTable)) hdel MyTable $nick [data] On *:DISCONNECT: if ($hget(MyTable)) hfree MyTable
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
on *:start: {
if ($hget(nicks) == $null) {
hmake nicks 60
if ($exists(nicks.hsh) == $true) { hload nicks nicks.hsh }
}
}
on *:exit: {
if ($hget(nicks) != $null) { hsave -o nicks nicks.hsh }
}
on *:disconnect: {
if ($hget(nicks) != $null) { hsave -o nicks nicks.hsh }
}
on *:OPEN:*:?: {
hadd -m query_nicks $nick true
}
I am most probably wrong. I really don't understand the concept of hash tables.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
If Raccoon knows it then I must have been wrong.
|
|
|
|
Joined: Jan 2003
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: Jan 2003
Posts: 127 |
So is your suggestion wrong? How do we check if the saved_nick in the hash table exist?
Last edited by littlecramp; 03/07/03 04:49 PM.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
$hget(MyTable,$nick) will return [data] if it exists. If the nicks don't need any data associated with them, then just use '1' as data or something, but it must be filled to use $hget effeciently.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
This is a long shot but would this work?
on *:OPEN:*:?: {
if ($nick == $hget(nicks,$nick)) {
hadd -m nicks $nick true
}
}
|
|
|
|
Joined: Jan 2003
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: Jan 2003
Posts: 127 |
"hsave -o nicks nicks.hsh". Can I say that a file(save using hsave) can contain mutiple table? It is a must to load table in order to retrieve the table or item value?
Sorry to ask so much, but I dont know how to use hash table, been using /write /writeini $read $readini $ini all the while!
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
* Raccoon wonders if his answers didn't answer your questions, or if there is something he left out.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Handy (for me at least) shortcut: instead of if $hget(name) { hfree name } you could use hfree -w name
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
ooh, nifty keen. damn j00 hax0r
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
|
|