-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
5 lines (4 loc) · 766 Bytes
/
README
File metadata and controls
5 lines (4 loc) · 766 Bytes
1
2
3
4
5
# RandomHashMap
RandomHashMap is a C# extension to Dictionary (HashTable) which adds a getter for random access to its elements.
#### Implementation details
Data is stored in both a Dictionary and LinkedList. The Dictionary is used to support constant time access to any element via its key. Inserting a key adds the item to the Dictionary and randomly appends/prepends the key into the LinkedList. Remove takes the element out of the Dictionary. To get a random element, we pop a key off the LinkedList and check if it exists in the dictionary. If yes, the key is randomly appended/prepended to the LinkedList and the corresponding value is returned from the Dictionary. If no, we discard the key and recall the get random function until it returns a value.