Help with Eiffel program please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shane Fitz
    New Member
    • Nov 2010
    • 4

    #1

    Help with Eiffel program please

    I can't seem to get my program to setup the hashed dictionary correctly. It seems to keep the last entry in, and references every key to that entry.

    Code:
    dictsetup(h:HASHED_DICTIONARY [HASHED_SET[STRING], STRING]; fname:STRING) is
    		local
    			in_file: TEXT_FILE_READ;
    			t, t0: STRING
    		do
    			from
    				!!in_file.connect_to(fname)
    				!!set.make
    			until
    				in_file.end_of_input
    			loop
    				in_file.read_word
    				t := in_file.last_string
    				t.to_lower
    				
    				t0 := t.twin
    				sortstring(t0)
    				
    				if h.has(t0) then
    					h.at(t0).add(t)
    				else
    					set.clear_count
    					set.add(t)
    					h.put(set,t0)
    				end
    				
    				
    			end
    			in_file.disconnect
    		end
    I want the method to take in each word from the file, get a sorted version of that word and add it to the dictionary. It gets added in a set of words that have the same key (sorted version). If the sorted version of the word has been met before then we add it to the set referenced by that word, else we create a new set with that word and add it to the dictionary with the sorted word as a key.

    Help needed urgently :(
Working...