# $Id: hash.pliant,v 1.0 2002/02/07 14:45:00 dada Exp $
# http://dada.perl.it/shootout/

module "/pliant/language/context.pli"

gvar (Index Str Int) hash1
gvar (Dictionary Str Int) hash2
gvar Str k
gvar Int i
gvar Pointer:Int v
gvar Str s_n := cast ((pliant_script_args translate Address 1) map CStr) Str
if (s_n parse (gvar Int n))
  for (i) 0 9999
    hash1 insert "foo_"+(string i) i
  for (i) 1 n
    v :> hash1 first
    k := hash1 key v    
    if addressof:(hash2 first k)<>null
      hash2:k += hash1:k
    else
      hash2 insert k hash1:k
    while addressof:v<>null
      if addressof:(hash2 first k)<>null
        hash2:k += hash1:k
      else
        hash2 insert k hash1:k
      v :> hash1 next v
      if addressof:v<>null
        k := hash1 key v
  console hash1:"foo_1" " " hash1:"foo_9999" " " hash2:"foo_1" " " hash2:"foo_9999" eol
else
  console "usage: hash2.pliant <number>" eol