Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does anyone know how to solve this?

Problem
Using only primitive types, implement a fixed-size hash map that associates string keys with arbitrary data object references (you don't need to copy the object). Your data structure should be optimized for algorithmic runtime and memory usage. You should not import any external libraries, and may not use primitive hash map or dictionary types in languages like Python or Ruby.

The solution should be delivered in one class (or your language's equivalent) that provides the following functions:

constructor(size): return an instance of the class with pre-allocated space for the given number of objects.
boolean set(key, value): stores the given key/value pair in the hash map. Returns a boolean value indicating success / failure of the operation.
get(key): return the value associated with the given key, or null if no value is set.
delete(key): delete the value associated with the given key, returning the value on success or null if the key has no value.
float load(): return a float value representing the load factor (`(items in hash map)/(size of hash map)`) of the data structure. Since the size of the dat structure is fixed, this should never be greater than 1.
If your language provides a built-in hashing function for strings (ex. `hashCode` in Java or `__hash__` in Python) you are welcome to use that. If not, you are welcome to do something naive, or use something you find online with proper attribution.

Instructions
Please provide the source, tests, runnable command-line function and all the resources required to compile (if necessary) and run the following program. You are free to use any coding language that compiles/runs on *nix operating systems and requires no licensed software.
Posted
Comments
Patrice T 10-Oct-15 18:57pm    
Nice definition !
What about starting to work ?
We don't do HomeWork.
Stefan_Lang 12-Oct-15 2:35am    
In addition to the other comments I'd like to add that it seems odd you set the keyword 'C++' even though the task at hand offers you a free choice of language - if you wish to implement this in C++, you should state that explicitely! And, of course, you should state the specific issue you encountered within the code you've already written.

1 solution

Yes, there are quite some people around here who know how to solve this! But this is YOUR homework and we wouldn't do you a favor by just giving you the answer. Look into your course notes and start working on it yourself.

If you decide to start working and get stuck, present what you have and what your specific problem is. Then I think you will receive plenty of help here. And in the end you will find that it wasn't that hard at all.

If you hate even trying to do this homework, I guess programming is not for you. You might in the end be better off trying a different course. So, it's up to you. Good luck anyway.
 
Share this answer
 
Comments
Patrice T 10-Oct-15 20:12pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900