@Override public T[] toArray() { T[] a = createBucket(size()); int i = 0; for (T[] bucket : buckets) { if ( bucket==null ) { continue; } for (T o : bucket) { if ( o==null ) { break; } a[i++] = o; } } return a; }
if (bucketLength == 0) { newBucket = createBucket(initialBucketCapacity); newTable[b] = newBucket;
if (bucketLength == 0) { newBucket = createBucket(initialBucketCapacity); newTable[b] = newBucket;
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; }
if (bucketLength == 0) { newBucket = createBucket(initialBucketCapacity); newTable[b] = newBucket;
@Override public T[] toArray() { T[] a = createBucket(size()); int i = 0; for (T[] bucket : buckets) { if ( bucket==null ) { continue; } for (T o : bucket) { if ( o==null ) { break; } a[i++] = o; } } return a; }
if (bucketLength == 0) { newBucket = createBucket(initialBucketCapacity); newTable[b] = newBucket;
@Override public T[] toArray() { T[] a = createBucket(size()); int i = 0; for (T[] bucket : buckets) { if ( bucket==null ) { continue; } for (T o : bucket) { if ( o==null ) { break; } a[i++] = o; } } return a; }
if (bucketLength == 0) { newBucket = createBucket(initialBucketCapacity); newTable[b] = newBucket;
@Override public T[] toArray() { T[] a = createBucket(size()); int i = 0; for (T[] bucket : buckets) { if ( bucket==null ) { continue; } for (T o : bucket) { if ( o==null ) { break; } a[i++] = o; } } return a; }
@Override public T[] toArray() { T[] a = createBucket(size()); int i = 0; for (T[] bucket : buckets) { if ( bucket==null ) { continue; } for (T o : bucket) { if ( o==null ) { break; } a[i++] = o; } } return a; }
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; }
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; }
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; }
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; }