public T get(T o) { if ( o==null ) return o; int b = getBucket(o); T[] bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (T e : bucket) { if ( e==null ) return null; // empty slot; not there if ( comparator.equals(e, o) ) return e; } return null; }
@Override public V get(Object key) { @SuppressWarnings("unchecked") K typedKey = (K)key; if ( key==null ) return null; int b = getBucket(typedKey); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, typedKey) ) { return e.value; } } return null; }
public boolean removeFast(T obj) { if (obj == null) { return false; } int b = getBucket(obj); T[] bucket = buckets[b]; if ( bucket==null ) { // no bucket return false; } for (int i=0; i<bucket.length; i++) { T e = bucket[i]; if ( e==null ) { // empty slot; not there return false; } if ( comparator.equals(e, obj) ) { // found it // shift all elements to the right down one System.arraycopy(bucket, i+1, bucket, i, bucket.length-i-1); bucket[bucket.length - 1] = null; n--; return true; } } return false; }
@Override public V put(K key, V value) { if ( key==null ) return null; if ( n > threshold ) expand(); int b = getBucket(key); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) { bucket = buckets[b] = new LinkedList<Entry<K, V>>(); } for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, key) ) { V prev = e.value; e.value = value; n++; return prev; } } // not there bucket.add(new Entry<K, V>(key, value)); n++; return null; }
protected T getOrAddImpl(T o) { int b = getBucket(o); T[] bucket = buckets[b]; // NEW BUCKET if ( bucket==null ) { bucket = createBucket(initialBucketCapacity); bucket[0] = o; buckets[b] = bucket; n++; return o; } // LOOK FOR IT IN BUCKET for (int i=0; i<bucket.length; i++) { T existing = bucket[i]; if ( existing==null ) { // empty slot; not there, add. bucket[i] = o; n++; return o; } if ( comparator.equals(existing, o) ) return existing; // found existing, quit } // FULL BUCKET, expand and add to end int oldLength = bucket.length; bucket = Arrays.copyOf(bucket, bucket.length * 2); buckets[b] = bucket; bucket[oldLength] = o; // add to end n++; return o; }
public T get(T o) { if ( o==null ) return o; int b = getBucket(o); T[] bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (T e : bucket) { if ( e==null ) return null; // empty slot; not there if ( comparator.equals(e, o) ) return e; } return null; }
public T get(T o) { if ( o==null ) return o; int b = getBucket(o); T[] bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (T e : bucket) { if ( e==null ) return null; // empty slot; not there if ( comparator.equals(e, o) ) return e; } return null; }
public T get(T o) { if ( o==null ) return o; int b = getBucket(o); T[] bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (T e : bucket) { if ( e==null ) return null; // empty slot; not there if ( comparator.equals(e, o) ) return e; } return null; }
public T get(T o) { if ( o==null ) return o; int b = getBucket(o); T[] bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (T e : bucket) { if ( e==null ) return null; // empty slot; not there if ( comparator.equals(e, o) ) return e; } return null; }
@Override public V get(Object key) { @SuppressWarnings("unchecked") K typedKey = (K)key; if ( key==null ) return null; int b = getBucket(typedKey); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, typedKey) ) { return e.value; } } return null; }
@Override public V get(Object key) { @SuppressWarnings("unchecked") K typedKey = (K)key; if ( key==null ) return null; int b = getBucket(typedKey); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, typedKey) ) { return e.value; } } return null; }
@Override public V get(Object key) { @SuppressWarnings("unchecked") K typedKey = (K)key; if ( key==null ) return null; int b = getBucket(typedKey); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, typedKey) ) { return e.value; } } return null; }
@Override public V get(Object key) { @SuppressWarnings("unchecked") K typedKey = (K)key; if ( key==null ) return null; int b = getBucket(typedKey); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) return null; // no bucket for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, typedKey) ) { return e.value; } } return null; }
public boolean removeFast(T obj) { if (obj == null) { return false; } int b = getBucket(obj); T[] bucket = buckets[b]; if ( bucket==null ) { // no bucket return false; } for (int i=0; i<bucket.length; i++) { T e = bucket[i]; if ( e==null ) { // empty slot; not there return false; } if ( comparator.equals(e, obj) ) { // found it // shift all elements to the right down one System.arraycopy(bucket, i+1, bucket, i, bucket.length-i-1); bucket[bucket.length - 1] = null; n--; return true; } } return false; }
public boolean removeFast(T obj) { if (obj == null) { return false; } int b = getBucket(obj); T[] bucket = buckets[b]; if ( bucket==null ) { // no bucket return false; } for (int i=0; i<bucket.length; i++) { T e = bucket[i]; if ( e==null ) { // empty slot; not there return false; } if ( comparator.equals(e, obj) ) { // found it // shift all elements to the right down one System.arraycopy(bucket, i+1, bucket, i, bucket.length-i-1); bucket[bucket.length - 1] = null; n--; return true; } } return false; }
public boolean removeFast(@Nullable T obj) { if (obj == null) { return false; } int b = getBucket(obj); T[] bucket = buckets[b]; if ( bucket==null ) { // no bucket return false; } for (int i=0; i<bucket.length; i++) { T e = bucket[i]; if ( e==null ) { // empty slot; not there return false; } if ( comparator.equals(e, obj) ) { // found it // shift all elements to the right down one System.arraycopy(bucket, i+1, bucket, i, bucket.length-i-1); bucket[bucket.length - 1] = null; n--; return true; } } return false; }
@Override public V put(K key, V value) { if ( key==null ) return null; if ( n > threshold ) expand(); int b = getBucket(key); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) { bucket = buckets[b] = new LinkedList<Entry<K, V>>(); } for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, key) ) { V prev = e.value; e.value = value; n++; return prev; } } // not there bucket.add(new Entry<K, V>(key, value)); n++; return null; }
@Override public V put(K key, V value) { if ( key==null ) return null; if ( n > threshold ) expand(); int b = getBucket(key); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) { bucket = buckets[b] = new LinkedList<Entry<K, V>>(); } for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, key) ) { V prev = e.value; e.value = value; n++; return prev; } } // not there bucket.add(new Entry<K, V>(key, value)); n++; return null; }
@Override public V put(K key, V value) { if ( key==null ) return null; if ( n > threshold ) expand(); int b = getBucket(key); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) { bucket = buckets[b] = new LinkedList<Entry<K, V>>(); } for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, key) ) { V prev = e.value; e.value = value; n++; return prev; } } // not there bucket.add(new Entry<K, V>(key, value)); n++; return null; }
@Override public V put(K key, V value) { if ( key==null ) return null; if ( n > threshold ) expand(); int b = getBucket(key); LinkedList<Entry<K, V>> bucket = buckets[b]; if ( bucket==null ) { bucket = buckets[b] = new LinkedList<Entry<K, V>>(); } for (Entry<K, V> e : bucket) { if ( comparator.equals(e.key, key) ) { V prev = e.value; e.value = value; n++; return prev; } } // not there bucket.add(new Entry<K, V>(key, value)); n++; return null; }