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
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
}
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.