I've finished up the MAP.GET and MAP.DELETE functions and added in the lowering and raising so that I can add values that are multivalued. That was all straightforward.
Now that I have that working, I need to write a routine to get the list of linux words into a hashmap. I don't want to have to rebuild the hashmap each time so I'm going to generate the hashmap first, save it and then read it in when testing my MAP.GET function. After all the goal is to get a constant time access for every word in the list.
*
T1 = TIME()
*
OPEN '','CONTROL-FILE' TO CONTROL.FILE ELSE
PRINT 'Unable to open file: CONTROL-FILE':
STOP
END
*
OPEN '','WORDS' TO WORDS.FILE ELSE
PRINT 'Unable to open file: WORDS':
STOP
END
*
READ HAYSTACK FROM WORDS.FILE,'linux.words' ELSE HAYSTACK = ''
*
EQU SIZE TO 50000
DIM MAP(SIZE)
MAT MAP = ''
*
NUMBER.OF.WORDS = DCOUNT(HAYSTACK,@AM)
*
FOR I = 1 TO NUMBER.OF.WORDS
WORD = HAYSTACK<I>
CALL MAP.ADD(MAT MAP,SIZE,WORD,WORD)
PRINT I,WORD
NEXT I
*
MATBUILD MAP.MATRIX FROM MAP
*
WRITE MAP.MATRIX ON CONTROL.FILE,'WORDS.MAP'
*
T2 = TIME()
PRINT 'Took: ' : T2 - T1 : 's'
*
* END OF PROGRAM
*
END
*
I have a pointer to the words directory, /usr/share/dict/ and from that pointer I can then read in linux.words. I then loop through that list of words and add it to the hashmap.
Once the hashmap is done, I can then build a dynamic array and write it out directly to the control file. With that we are done! I can now read in the hashmap and use it without the overhead of creating it.