CDS239

Hash Map

Last Revised: 12/28/16

 

This routine simulates a simple hash map in memory. A hash map provides a way to store and retrieve data for a given key.

Calling Format:

CALL "CDS239", GLB$, METHOD$, KEY$, { VAL$, MAP$ }

CDS239 Arguments
Argument Passed To/From Description
GLB$ To The name of the global variable where the hash map will be stored. CDS239 will assign and manage the contents of this variable. Note this is the name of the global variable not the value. See example.
METHOD$ To

Note: The method value can be upper or lower case, and only the first character is used.

Short Long Note
c CLEAR Clear all keys and values, if any. Recommended before adding keys to a new map to insure it is empty.
p PUT Store VAL$ for given KEY$. Existing VAL$ will be replaced if present.
g GET Retrieve VAL$ given KEY$. VAL$ will be null if KEY$ does not exist.
d DELETE Remove from hash map the Key and Value associated with KEY$. No error if KEY$ does not exist.

Note that the hash map is not sorted and only provides retrieval of a value given a key. It does not currently provide a way to sort the map by key or value.

KEY$ To The key associated with the value. Leading and trailing blanks are removed. All keys do not have to be the same size. The key cannot include characters $00$, $01$, nor $02$.
VAL$ To/From The value associated with the key. The value cannot include characters $00$, $01$, nor $02$. Not required for the DELETE action.
MAP$ From Optional string variable that will return the hash map itself. This may be useful when it is necessary to iterate over the list of keys in the map.
Example

1800 TEST:

1810 CALL "CDS239","states","c"

1820 CALL "CDS239","states","p","OH","Ohio"

1830 CALL "CDS239","states","p","PA","Pennsylvania"

1840 CALL "CDS239","states","p","NY","New York"

1850 CALL "CDS239","states","g","PA",VAL$

1860 PRINT VAL$

1870 CALL "CDS239","states","d","PA"

1880 CALL "CDS239","states","g","PA",VAL$

1890 PRINT LEN(VAL$)

Pennsylvania

0