hashmap.h
Functions | |
This type is the ADT used to represent a map from strings to values. | |
Allocates a new map with no entries. | |
Frees the storage associated with the map. | |
Returns the number of elements in the map. | |
Returns true if the map has no entries. | |
Removes all entries from the map. | |
Creates a copy of the map. | |
Associates key with value in the map. | |
Returns the value associated with key in the map, or NULL , if no such value exists. | |
Checks to see if the map contains the specified key. | |
Removes the key and its value from the map. | |
Iterates through the map and calls the function fn on each entry. |
typedef struct HashMapCDT *HashMap;
HashMap newHashMap(void);
Usage:
map = newHashMap();
void freeHashMap(HashMap map);
Usage:
freeHashMap(map);
int size(HashMap map);
Usage:
n = size(map);
bool isEmpty(HashMap map);
true
if the map has no entries.
Usage:
if (isEmpty(map)) . . .
void clear(HashMap map);
Usage:
clear(map);
HashMap clone(HashMap map);
clone
function copies
only the first level of the structure and does not copy the individual
elements.
Usage:
newmap = clone(map);
void put(HashMap map, string key, void *value);
key
with value
in the map.
Each call to put
supersedes any previous definition
for key
.
Usage:
put(map, key, value);
void *get(HashMap map, string key);
key
in the map,
or NULL
, if no such value exists.
Usage:
void *value = get(map, key);
bool containsKey(HashMap map, string key);
Usage:
if (containsKey(map, key)) . . .
void remove(HashMap map, string key);
Usage:
remove(map, key);
void map(HashMap map, proc fn, void *data);
fn
on
each entry. The callback function takes the following arguments:
data
pointer
data
pointer allows the client to pass state
information to the function fn
, if necessary. If no such
information is required, this argument should be NULL
.
Usage:
map(map, fn, data);