mIRC Homepage
Posted By: AWEstun Hash data search not working correctly - 09/06/08 12:54 AM
Can someone tell me what is wrong with this:

Code:
/search3 {
  set %hash seen
  set %search QUIT
  var %a = $hfind(%hash,* $+ %search $+ *,0,w).data
  echo -s total: %a
  while (%a) {
    echo -s %a : $hfind(%hash,* $+ %search $+ *,%a,w).data is $hget(%hash,%a).data
    dec %a
  }
}

It's showing weird results, items that down have *QUIT* in them.
Posted By: Wims Re: Hash data search not working correctly - 09/06/08 01:02 AM
Code:
/search3 {
  var %hash seen ,%search QUIT ,%a = $hfind(%hash,$+(*,%search,*),0,w).data
  echo -s total: %a
  while (%a) {
  var %h $hfind(%hash,$+(*,%search,*),%a,w).data
  echo -s %h is $hget(%hash,%h)
    dec %a
  }
}


Edit : It was showing weird result because your code was false, The data of the Nth item is not for sure the data of the N match
Posted By: AWEstun Re: Hash data search not working correctly - 09/06/08 02:44 AM
Originally Posted By: Wims
Code:
/search3 {
  var %hash seen ,%search QUIT ,%a = $hfind(%hash,$+(*,%search,*),0,w).data
  echo -s total: %a
  while (%a) {
  var %h $hfind(%hash,$+(*,%search,*),%a,w).data
  echo -s %h is $hget(%hash,%h)
    dec %a
  }
}


Edit : It was showing weird result because your code was false, The data of the Nth item is not for sure the data of the N match


Thanks, I'd wondered about that, but I didn't know how to fix it. What about this code to wildcard search item names? It worked the way I had it, but I updated it to correct the wildcard string. Same result.

Code:
/search {
  var %hash = seen ,%search = apple, %a = 1
  while ($hfind(%hash,$+(*,%search,*),%a,w)) {
    echo -s %a : $hfind(%hash,$+(*,search,*),%a,w) is $hget(%hash,%a).data
    inc %a
  }
}
Posted By: RusselB Re: Hash data search not working correctly - 12/06/08 05:58 AM
You have to use the data location returned by the $hfind in the $hget to reference the correct item in the hash table.

For example your code could be searching for the 3rd item that matches the required data, but the 3rd match might be the 50th entry, so $hget(table,3) <which you're currently using> would be the incorrect entry.

Instead try
Code:
/search {
  var %hash = seen ,%search = apple, %a = 1, %b = $hget(%hash,0).item
  while %a <= %b {
    %entry = $hfind(%hash,$+(*,%search,*),%a,w)
    if %entry {
      echo -s %a : %entry is $hget(%hash,%entry).data
    }
    inc %a
  }
} 
Posted By: AWEstun Re: Hash data search not working correctly - 16/06/08 12:22 PM
Originally Posted By: RusselB
You have to use the data location returned by the $hfind in the $hget to reference the correct item in the hash table.

For example your code could be searching for the 3rd item that matches the required data, but the 3rd match might be the 50th entry, so $hget(table,3) <which you're currently using> would be the incorrect entry.

Instead try
Code:
/search {
  var %hash = seen ,%search = apple, %a = 1, %b = $hget(%hash,0).item
  while %a <= %b {
    %entry = $hfind(%hash,$+(*,%search,*),%a,w)
    if %entry {
      echo -s %a : %entry is $hget(%hash,%entry).data
    }
    inc %a
  }
} 


echo -s %a : %entry is $hget(%hash,%entry).data

should be

echo -s %a : %entry is $hget(%hash,%entry)

so the data is shown
Posted By: AWEstun Re: Hash data search not working correctly - 16/06/08 01:01 PM
Thank you for bringing this to my attention. I have adjusted the search modeules and the usermatch module.
© mIRC Discussion Forums