mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Re: $hfind and $hget problems #162441 19/10/06 07:17 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
//echo -a $hget(orion,$hfind(orion,$str(* $+ $chr(9),4) $+ %string $+ $str($chr(9) $+ *,9),1,w).data).data


The $hfind returns a ITEMNAME, from what i read above this happens to be a number, $hget().data is a direct index access using the offset into the hashtable not the ITEMNAME returned by the $hfind, i beleive if it is still matching the correct data it is doing it by shear chance, and that chance is likely to fail as soon as some data is altered.

Re: $hfind and $hget problems #162442 19/10/06 07:24 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Well i did give the alter the hash table option as well, all tho now reading it i didnt actually mention the TABS were ment to be replaced by spaces as well, as the spaces being replaced by 255 so it would have screwed up anyway. this should suit him well enough, and its pretty simple to patch into existing code even.

alias -l data.IN { return $replace($1,$chr(32),$chr(255),$chr(9),$chr(32)) }
alias -l data.OUT{ return $replace($1,$chr(32),$chr(9),$chr(255),$chr(32)) }
;
/VAR %match = $data.OUT( $hget(TABLE,$hfind(Table,& & & & $data.in(%matchtext) *,1,w).data) )
/HADD TABLE itemname $data.IN(%normaldata)
; only thing to watch is the %matchtext also has spaces replaced with $chr(255) as i showed.

Re: $hfind and $hget problems #162443 19/10/06 08:41 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Hm... that shouldn't have had .data at the end.


Invision Support
#Invision on irc.irchighway.net
Re: $hfind and $hget problems #162444 20/10/06 12:41 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Quote:
Is the 1.5 seconds for a match though? Remember it'll only search to the first match, so if it's matching near the 'start' of the hash table it'll be a lot faster than searching for something not in the table at all.


It's the same time regardless of the location in the hash table, or if there are no results.

Here is the code used (fixed thanks to the comment by DaveC):

//echo -a $hget(orion,$hfind(orion,$str(* $+ $chr(9),4) $+ %string $+ *,1,w).data)

The only change is the removal of .data at the end of the original and I also removed the second string of $chr(9)'s since it wasn't needed. Even with that, it was still 1.5s or so.


Invision Support
#Invision on irc.irchighway.net
Re: $hfind and $hget problems #162445 20/10/06 02:48 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
//echo -a $hget(orion,$hfind(orion,$str(* $+ $chr(9),4) $+ %string $+ *,1,w).data)

I would change that to
//echo -a $hget(orion,$hfind(orion,$str(* $+ $chr(9),4) $+ %string $+ $chr(9) $+ *,1,w).data)

To ensure no accidental part matches such as %string = "fred" making *<tab>*<tab>*<tab>*<tab>fred<tab>* which wont mistakenly match to say fredrick

One thing about the 1.5s was it on every match not just ,1, ?
Im also unsure on the order of results of using hfind (i have never checked them) do they come in the order they would appear in a hsave file? I would think it likely is.

Since you have the sample data, try changing it to search for something in say ther 14th token and see if there is a increased delay, i have a feeling there well be.

Side Note: I had this same type of problem with /FILTER i was filtering from different tokens in it in like token number 18 to 22, and the delay was horrible, I finally added a extra token at token 18 that was a unquie value (cant remeber what it was lets say it was ) so then i could filter on *~*~*~*~*~ $+ matchtext $+ ~* (for token match on 22 now token 23)
aka i allow it to jump all the starter tokens and align to where its ment to be using a unique marker on each line to aline with.
(this of course means a adjustment of the data, which isnt always possable)

How often is the code triggered as even 1.5s is pretty high pause rate for mirc if your doing it alot, or your looping.
A /hsave -n followed by a /filter -n on the file giving you a result set with the first word as a backrefrence number to $hget(table,N).data might be faster (if theres a lot of matches to find)
^-- that idea is the same princible as the sorting hashtable values thing with using /filter -n (hope im making my self clear enough here)

Re: $hfind and $hget problems #162446 20/10/06 01:48 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
I would change that to
//echo -a $hget(orion,$hfind(orion,$str(* $+ $chr(9),4) $+ %string $+ $chr(9) $+ *,1,w).data)

- This won't work correctly. You must explicitly specify every token delimiter in order to ensure it only matches the correct token. Using your code it could match any item which has %string as token 5-13.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $hfind and $hget problems #162447 20/10/06 02:35 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I'm not sure why the regular expression $hfind was dismissed, but it seems to work best (most accurate) out of all the examples given. I wrote up a test alias to show the regex working:

Code:
alias re_hfind {
if ($1 == $null) { echo -a Syntax: /re_hfind &lt;matchtext&gt; | return }

;;;;;; Create a table for testing ;;;;;;
  if ($hget(test)) hfree test

  echo -a Making Table
  hmake test 100
  var %c = 0, %cc = 3000
  while (%c &lt; %cc) {
    inc %c
    hadd test %c $+($rand(100,999),$chr(9),$rand(100,999),$chr(9),$rand(100,999),$chr(9),$rand(100,999),$chr(9),$rand(100,999),$chr(9),$rand(100,999),$chr(9),$rand(100,999))
  }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


  var %ticks = $ticks
  var %matchtext = $re_escape($1)
  var %regex = /^(?:\S+\s+){4}( $+ %matchtext $+ )/i
  echo -a %regex
  var %h, %c = 0, %cc = $hfind(test,%regex,0,r).data
  echo 0&gt; $calc($ticks - %ticks) ms

  echo -a $hfind(test,*,0,w) items; %cc matches

  while (%c &lt; %cc) {
    inc %c
    %h = $hfind(test,%regex,%c,r).data
    echo -a Match: Ticks- $calc($ticks - %ticks) $+ ms Item- %h Data- $hget(test,%h)

  }
  echo X&gt; $calc($ticks - %ticks) ms
}

alias re_escape return $regsubex($1,/([^\w\s])/g,\\t)


It creates a test hash table (with numbers as values) each time the alias is called (to provide different test conditions). Simply a matchtext as $1 when calling the alias, and various bits of data will be shown on the screen.

I ran the code, and it seemed to take about 50ms per $hfind call.

-genius_at_work

Re: $hfind and $hget problems #162448 20/10/06 03:18 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
hehehe i was reading this thinking the figures dont add up seeing as you prooved regex hfind is not slow (atleast not as slow as 60 seconds on 3000 items) i wont anymore :tongue:

First thing i noticed noone asked how the OP was using the regex find in his loop.
Quote:

Hmm, the 60 seconds are possibly because it is part of a loop.
Basicly it takes a piece of text, and searches the hash table.

In total it searches for like 300 items in that loop.
But still, with the original code, it takes like 5 seconds. The only problem is that it matches wildmatch stuff, on several tokens. So I get wrong results.


which should be the reason for the large execution time.


$maybe
Re: $hfind and $hget problems #162449 20/10/06 03:55 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
DaveC: That won't matter because the search param always has quotes around it and nothing else does. However, if he did want to search other tokens, you're correct that it would need that extra $chr(9).

starbucks_mafia: Same thing... because there are quotes around it, it's not going to be a problem. However, if he does want to search other params, it should include all tokens.


In either case, the search returns the result in 1.5s regardless which way it is handled. I'll throw back in the remaining tokens as I originally had it.


Invision Support
#Invision on irc.irchighway.net
Re: $hfind and $hget problems #162450 20/10/06 07:14 PM
Joined: Apr 2006
Posts: 464
O
OrionsBelt Offline OP
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Well, the delay has been solved in my opinion.
If searching for 1 item takes 1.5 second, searching for 50 items will take about 75 seconds, which is 1.5 minute.

And that is exactly what my script does.
Just repeating the same find command several times.

For now I'll use:
$hget(Table,$hfind(Table,$str(* $+ $chr(9),4) $+ $chr(34) $+ %matchtext $+ $chr(34) $+ $str($chr(9) $+ *,9),1,w).data)
As that actually returns the results I was looking for cool

Thank you all for thinking along.

Page 2 of 2 1 2