|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Hi Guys, I need some help, making my hash table scripts a bit nicer (shorter in case you wondering) For example this
alias hash-refresh {
hfree Table1
hfree Table2
hfree Table3
hmake Table1 500
hmake Table2 300
hmake Table3 100
hload Table1 txtfile1.txt
hload Table2 txtfile2.txt
hload Table3 txtfile3.txt
hsave Table1 Table1.hsh
hsave Table2 Table2.hsh
hsave Table3 Table3.hsh
}
Can't all this be combined in some way? Basicly I want to perform this refresh every hour, so I want it to be as smooth as possible. Thanks for any idea's!
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
This is what I use for my gaming bot, maybe it'll give you an idea or two. Keep in mind the following is on cleanup, not for a 'refresh'. You'll have to free, create, and load like you have been, but use the same code once per table name.
var %tbl_list = $ctelnet_tables, %t = 1
while ($gettok(%tbl_list,%t,32)) {
var %tbl = $v1, %file = $hashfile(%tbl)
if ($hget(%tbl)) {
/hsave -bo %tbl %file
/hfree %tblk
}
/inc %t
}
$ctelnet_tables is my list of table names. Since I use a loop code in my startup, exit, connect, and disconnect, I only want to update the table listing in one place. $hashtable returns a path to each file. alias -l $ctelnet_tables { return table1 table2 table3 } alias -l $hashfile { return system\hash\ $+ $1 $+ .hsh }
-KingTomato
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Thx for the reply KingTomato, but the alias itself is fine atm, and it's only 3 hash files. I was more thinking of something like this
alias hash-refresh {
hfree Table1, Table2, Table3
hmake Table1 500
hmake Table2 300
hmake Table3 100
hload Table1 txtfile1.txt, Table2 txtfile2.txt, Table3 txtfile3.txt
hsave Table1 Table1.hsh, Table2 Table2.hsh, Table3 Table3.hsh
} Maybe include the hmake commands when loading the txt files? Stuff like that, just less repeating Does this look valid?
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Your hload & hsave commands won't work, as they only support a single table name & file. For your hfree, you might consider /hfree -w Table* That will free all tables that start with Table I don't know if that is accurate for your real table names, but it should give you the idea. Here's one possiblity (based on what you've shown) alias hash-refresh {
hfree -w Table*
var %a = 1, %b = 3
while %a <= %b {
hmake $+(Table,%a) $iif(%a = 1,500,$iif(%a = 2,300,100))
hload $+(Table,%a) $+(txtfile,%a,.txt)
hsave $+(Table,%a) $+(Table,%a,.hsh)
inc %a
}
}
As you should be able to tell, this isn't going to save you much in coding space with only 3 tables, and the names of the tables & files are strictly based on what you've given. If you've just substituted Table and txtfile for the actual names, then what I've written may not work for you.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
You could make an alias and call it multiple times:
alias hash.reload {
;1=tablename, 2=tablesize, 3=loadfile, 4=savefile
hfree $1
hmake $1 $2
hload $1 $3
hsave $1 $4
}
alias hash-refresh {
hash.reload Table1 500 txtfile1.txt Table1.hsh
hash.reload Table2 300 txtfile2.txt Table2.hsh
hash.reload Table3 100 txtfile3.txt Table3.hsh
}
-genius_at_work
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
I see that you say EXAMPLE here, and honestly i dont see much problem with what your doing, but maybe you could do it this way. alias hash-refresh {
hfree Table1 | hmake Table1 500 | hload Table1 txtfile1.txt | hsave Table1 Table1.hsh
hfree Table2 | hmake Table2 300 | hload Table2 txtfile2.txt | hsave Table2 Table2.hsh
hfree Table3 | hmake Table3 100 | hload Table3 txtfile3.txt | hsave Table3 Table3.hsh
}
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Very nice idea's guys! Definately gonna play around with it.
Thanks a lot for all your replies!
|
|
|
|
|