-- -*- mode: eiffel -*-
-- $Id: hash2.se,v 1.2 2001/04/26 07:23:16 doug Exp $
-- http://www.bagley.org/~doug/shootout/

class HASH2
   
creation make
   
feature -- Initialization
   
   make is
      local
     n, i, prev : INTEGER
     hash1 : DICTIONARY[INTEGER, STRING]
     hash2 : DICTIONARY[INTEGER, STRING]
     it: ITERATOR[STRING]
      do
     n := argument(1).to_integer

     !!hash1.with_capacity(10000);
     !!hash2.with_capacity(10000);
     
     -- std_output.put_string("building hash1")
     -- std_output.put_character('%N')
     from  i := 0
     until i = 10000
     loop
        -- std_output.put_integer(i)
        -- std_output.put_character('%N')
        hash1.put(i, "foo_" + i.to_string)
        i := i + 1
     end

     from  i := 0
     until i = n
     loop
        -- std_output.put_string("building hash2")
        -- std_output.put_character('%N')
        it := hash1.get_new_iterator_on_keys
        from  it.start
        until it.is_off
        loop
           if hash2.has(it.item) then
          prev := hash2.at(it.item)
           else
          prev := 0
           end
           hash2.put(prev + hash1.at(it.item), it.item)
           it.next;
        end
        i := i + 1
     end

         std_output.put_integer(hash1.at("foo_1"))
         std_output.put_string(" ")
         std_output.put_integer(hash1.at("foo_9999"))
         std_output.put_string(" ")
         std_output.put_integer(hash2.at("foo_1"))
         std_output.put_string(" ")
         std_output.put_integer(hash2.at("foo_9999"))
         std_output.put_character('%N')
      end

end -- class HASH2