mIRC Home    About    Download    Register    News    Help

Print Thread
#154122 27/07/06 08:14 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Hi Guys,

I need some help, making my hash table scripts a bit nicer (shorter in case you wondering) laugh

For example this
Code:
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!

#154123 27/07/06 08:21 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
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.

Code:
  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
#154124 27/07/06 08:42 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
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
Code:
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 crazy
Does this look valid?

#154125 27/07/06 10:19 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
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)
Code:
 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.

#154126 28/07/06 12:57 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
You could make an alias and call it multiple times:

Code:
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

#154127 28/07/06 07:15 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
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.

Code:
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
}

#154128 28/07/06 03:34 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Very nice idea's guys!
Definately gonna play around with it.

Thanks a lot for all your replies!


Link Copied to Clipboard