mIRC Home    About    Download    Register    News    Help

Print Thread
Hash data search not working correctly #200640 09/06/08 12:54 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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.


I registered; you should too.
Re: Hash data search not working correctly [Re: AWEstun] #200641 09/06/08 01:02 AM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
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

Last edited by Wims; 09/06/08 01:05 AM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Hash data search not working correctly [Re: Wims] #200647 09/06/08 02:44 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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
  }
}


I registered; you should too.
Re: Hash data search not working correctly [Re: AWEstun] #200798 12/06/08 05:58 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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
  }
} 

Re: Hash data search not working correctly [Re: RusselB] #200992 16/06/08 12:22 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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


I registered; you should too.
Re: Hash data search not working correctly [Re: AWEstun] #200994 16/06/08 01:01 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Thank you for bringing this to my attention. I have adjusted the search modeules and the usermatch module.


I registered; you should too.