A hash table-backed Map implementation. Provides amortized constant time access to elements via get(), remove(), and put() in the best case. Assumes null keys will never be inserted, and does not resize down upon remove(). @author YOUR NAME HERE
| 10 | * @author YOUR NAME HERE |
| 11 | */ |
| 12 | public class MyHashMap<K, V> implements Map61B<K, V> { |
| 13 | |
| 14 | /** |
| 15 | * Protected helper class to store key/value pairs |
| 16 | * The protected qualifier allows subclass access |
| 17 | */ |
| 18 | protected class Node { |
| 19 | K key; |
| 20 | V value; |
| 21 | |
| 22 | Node(K k, V v) { |
| 23 | key = k; |
| 24 | value = v; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /* Instance Variables */ |
| 29 | private Collection<Node>[] buckets; |
| 30 | // You should probably define some more! |
| 31 | |
| 32 | /** Constructors */ |
| 33 | public MyHashMap() { } |
| 34 | |
| 35 | public MyHashMap(int initialCapacity) { } |
| 36 | |
| 37 | /** |
| 38 | * MyHashMap constructor that creates a backing array of initialCapacity. |
| 39 | * The load factor (# items / # buckets) should always be <= loadFactor |
| 40 | * |
| 41 | * @param initialCapacity initial size of backing array |
| 42 | * @param loadFactor maximum load factor |
| 43 | */ |
| 44 | public MyHashMap(int initialCapacity, double loadFactor) { } |
| 45 | |
| 46 | /** |
| 47 | * Returns a new node to be placed in a hash table bucket |
| 48 | */ |
| 49 | private Node createNode(K key, V value) { |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns a data structure to be a hash table bucket |
| 55 | * |
| 56 | * The only requirements of a hash table bucket are that we can: |
| 57 | * 1. Insert items (`add` method) |
| 58 | * 2. Remove items (`remove` method) |
| 59 | * 3. Iterate through items (`iterator` method) |
| 60 | * |
| 61 | * Each of these methods is supported by java.util.Collection, |
| 62 | * Most data structures in Java inherit from Collection, so we |
| 63 | * can use almost any data structure as our buckets. |
| 64 | * |
| 65 | * Override this method to use different data structures as |
| 66 | * the underlying bucket type |
| 67 | * |
| 68 | * BE SURE TO CALL THIS FACTORY METHOD INSTEAD OF CREATING YOUR |
| 69 | * OWN BUCKET DATA STRUCTURES WITH THE NEW OPERATOR! |
nothing calls this directly
no outgoing calls
no test coverage detected