This is an old revision of the document!
You are required to implement a hashtable between words and number of occurrences, using the D programming language. Your hashtable must provide the following interface:
Method | Description |
---|---|
add <word> | add a new word to the hashtable, or increase the number of occurrences |
remove <word> | remove the word from the hashtable; the word doesn't necessarily have to exist |
get <word, defaultValue> | return the number of occurances for the given word, or defaultValue if the word doesn't exist in the hashtable |
clear | clear the table |
resizeDouble | double the size of the hashtable |
resizeHalve | halve the size of the hashtable. Excess memory must be freed. |
bucketToString <index_bucket> | returns a string containing all the pairs <word, numOcc>, separated by one space (” ”) character |
toString | returns a string containing all the pairs <word, numOcc> in the hashtable, starting with index 0 |
The implemented hashtable will contain SIZE buckets. Each bucket will contain a pair consisting of the word and number of occurrences.
1. You are not allowed to use the built-in Associative Array type, nor other library implementations of a hashtable
2. You are allowed to use any other features/built-in types that the language provides
3. You must use the globally available `hashOf` function, as your hash function:
string phrase = "Bran got the Throne"; size_t hashValue = hashOf(phrase);
4. Inserting in a bucket list always adds at the end of the list
5. When halving, if the size is odd (2k + 1), the new size must be k