\ -*- mode: forth -*-
\ $Id: hash2.gforth,v 1.1 2001/05/25 21:32:46 doug Exp $
\ http://www.bagley.org/~doug/shootout/
\ from Anton Ertl:
0. argc @ 1- arg >number 2drop drop constant NUM
wordlist constant hash1
wordlist constant hash2
: build
get-current hash1 set-current
10000 0 ?do
i 0 <# #s '_ hold 'o hold 'o hold 'f hold #> nextname i constant
loop
set-current ;
: search-new
>r 2dup r@ search-wordlist if
rdrop nip nip
else
nextname get-current r> set-current 0 constant set-current
lastxt
endif ;
: add-to-hash2
dup name>int execute
swap name>string hash2 search-new >body +! ;
: build2
hash1 wordlist-id begin
@ dup
while
dup add-to-hash2
repeat
drop ;
: countdecs
NUM 0 ?do
build2
loop ;
build countdecs
hash1 >order
foo_1 .
foo_9999 .
previous
hash2 >order
foo_1 .
foo_9999 0 .r cr
previous bye