mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
lets say Hash Table data is
HashTable Name DataTest
Test1 = 1
Test2 = 2
Test3 = 20
Test4 = 150

how would i go about searching table DataTest to find highest Data number then output results like
.msg $chan $hget(DataTest,0).item here $hget(DataTest,0).data here


Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
When you put the data into the hashtable compare it to the current highest value and maintain that index instead of searching the table every time.

If you lose track of it or need to search every time for some reason loop through with the .data suffix

$hget(table,n).data

Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
thanks for reply but that doesnt actually tell me how i would code finding the highest data in the table

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
If you are creating this by adding the fields one by one, just have a 'highest' index to keep track at the point you're adding them.

Code:
var %item = myitem
var %data = 10
hadd table %item %data
if (%data > $hget(table,highest)) hadd table highest %item

var %highest = $hget(table,highest)
echo -ag Highest item is %highest, data is $hget(table,%highest)


If you need to loop though an existing table:
Code:
var %i = 1, %n = $hget(table,0).data, %high.item, %high.data
while (%i <= %n) {
  if ($hget(table,%i).data > %high.item) {
    %high.item = $hget(table,%i).item
    %high.data = $v1
  }
  inc %i
}

Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
tyvm ^5s

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
A late reply because I was gone for a week, but in a case where you might want more than just the top value, such as a top 10, you can use /filter.

Code:
  // Sort table in descending order into a temp file (this can also be done in a custom window)
  hsave -n table file.tmp
  filter -ffcuten 2 32 file.tmp file.tmp

  // Get the Nth top value
  echo -a $hget(table,$gettok($read(file.tmp,N),1,32)).item


Just note that your values should all be numerical for this to work correctly.


Invision Support
#Invision on irc.irchighway.net
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
tyvm Riamus2 you are a God smile <3 this is a better way for what i wanted to do works with perfection ^^

Last edited by DaRkCaSTLe1974; 10/06/13 02:27 AM.

Link Copied to Clipboard