internal V Remove(long key) { LongMapNode <V> n = table[Index(key)]; LongMapNode <V> prior = null; while (n != null) { if (n.key == key) { if (prior == null) { table[Index(key)] = n.next; } else { prior.next = n.next; } size--; return(n.value); } prior = n; n = n.next; } return(default(V)); }
private void Insert(LongMapNode <V> n) { int idx = Index(n.key); n.next = table[idx]; table[idx] = n; }
internal V Get(long key) { for (LongMapNode <V> n = table[Index(key)]; n != null; n = n.next) { if (n.key == key) { return(n.value); } } return(default(V)); }
private void Grow() { LongMapNode <V>[] oldTable = table; int oldSize = table.Length; table = CreateArray <V>(oldSize << 1); growAt = (int)(table.Length * LOAD_FACTOR); for (int i = 0; i < oldSize; i++) { LongMapNode <V> e = oldTable[i]; while (e != null) { LongMapNode <V> n = e.next; Insert(e); e = n; } } }
internal V Put(long key, V value) { for (LongMapNode <V> n = table[Index(key)]; n != null; n = n.next) { if (n.key == key) { V o = n.value; n.value = value; return(o); } } if (++size == growAt) { Grow(); } Insert(new LongMapNode <V>(key, value)); return(default(V)); }