/** * Returns <tt>true</tt> if the receiver contains the specified key. * * @return <tt>true</tt> if the receiver contains the specified key. */ public boolean containsKey(double key) { return indexOfKey(key) >= 0; } /**
/** * Returns <tt>true</tt> if the receiver contains the specified value. * * @return <tt>true</tt> if the receiver contains the specified value. */ public boolean containsValue(int value) { return indexOfValue(value) >= 0; } /**
/** * Trims the capacity of the receiver to be the receiver's current * size. Releases any superfluous internal memory. An application can use this operation to minimize the * storage of the receiver. */ public void trimToSize() { // * 1.2 because open addressing's performance exponentially degrades beyond that point // so that even rehashing the table can take very long int newCapacity = nextPrime((int)(1 + 1.2*size())); if (table.length > newCapacity) { rehash(newCapacity); } } /**
/** * Ensures that the receiver can hold at least the specified number of associations without needing to allocate new internal memory. * If necessary, allocates new internal memory and increases the capacity of the receiver. * <p> * This method never need be called; it is for performance tuning only. * Calling this method before <tt>put()</tt>ing a large number of associations boosts performance, * because the receiver will grow only once instead of potentially many times and hash collisions get less probable. * * @param minCapacity the desired minimum capacity. */ public void ensureCapacity(int minCapacity) { if (table.length < minCapacity) { int newCapacity = nextPrime(minCapacity); rehash(newCapacity); } } /**
int i = indexOfInsertion(key); if (i<0) { //already contained i = -i -1; int newCapacity = chooseGrowCapacity(this.distinct+1,this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity); return put(key, value); int newCapacity = chooseGrowCapacity(this.distinct+1,this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity);
/** * Removes the given key with its associated element from the receiver, if present. * * @param key the key to be removed from the receiver. * @return <tt>true</tt> if the receiver contained the specified key, <tt>false</tt> otherwise. */ public boolean removeKey(double key) { int i = indexOfKey(key); if (i<0) return false; // key not contained this.state[i]=REMOVED; //this.values[i]=0; // delta this.distinct--; if (this.distinct < this.lowWaterMark) { int newCapacity = chooseShrinkCapacity(this.distinct,this.minLoadFactor, this.maxLoadFactor); /* if (table.length != newCapacity) { System.out.print("shrink rehashing "); System.out.println("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ..."); } */ rehash(newCapacity); } return true; } /**
byte newState[] = new byte[newCapacity]; this.lowWaterMark = chooseLowWaterMark(newCapacity,this.minLoadFactor); this.highWaterMark = chooseHighWaterMark(newCapacity,this.maxLoadFactor); if (oldState[i]==FULL) { double element = oldTable[i]; int index = indexOfInsertion(element); newTable[index]=element; newValues[index]=oldValues[i];
int capacity = initialCapacity; super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity==0) capacity=1; // open addressing needs at least one FREE slot at any time. this.highWaterMark = chooseHighWaterMark(capacity, this.maxLoadFactor);
int i = indexOfInsertion(key); if (i<0) { //already contained i = -i -1; int newCapacity = chooseGrowCapacity(this.distinct+1,this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity); return put(key, value); int newCapacity = chooseGrowCapacity(this.distinct+1,this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity);
/** * Removes the given key with its associated element from the receiver, if present. * * @param key the key to be removed from the receiver. * @return <tt>true</tt> if the receiver contained the specified key, <tt>false</tt> otherwise. */ public boolean removeKey(double key) { int i = indexOfKey(key); if (i<0) return false; // key not contained this.state[i]=REMOVED; //this.values[i]=0; // delta this.distinct--; if (this.distinct < this.lowWaterMark) { int newCapacity = chooseShrinkCapacity(this.distinct,this.minLoadFactor, this.maxLoadFactor); /* if (table.length != newCapacity) { System.out.print("shrink rehashing "); System.out.println("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ..."); } */ rehash(newCapacity); } return true; } /**
byte newState[] = new byte[newCapacity]; this.lowWaterMark = chooseLowWaterMark(newCapacity, this.minLoadFactor); this.highWaterMark = chooseHighWaterMark(newCapacity, this.maxLoadFactor); if (oldState[i] == FULL) { double element = oldTable[i]; int index = indexOfInsertion(element); newTable[index] = element; newValues[index] = oldValues[i];
/** * Ensures that the receiver can hold at least the specified number of associations without needing to allocate new internal memory. * If necessary, allocates new internal memory and increases the capacity of the receiver. * <p> * This method never need be called; it is for performance tuning only. * Calling this method before <tt>put()</tt>ing a large number of associations boosts performance, * because the receiver will grow only once instead of potentially many times and hash collisions get less probable. * * @param minCapacity the desired minimum capacity. */ public void ensureCapacity(int minCapacity) { if (table.length < minCapacity) { int newCapacity = nextPrime(minCapacity); rehash(newCapacity); } } /**
int capacity = initialCapacity; super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity==0) capacity=1; // open addressing needs at least one FREE slot at any time. this.highWaterMark = chooseHighWaterMark(capacity, this.maxLoadFactor);
int i = indexOfInsertion(key); if (i < 0) { // already contained i = -i - 1; int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity); return put(key, value); int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity);
/** * Trims the capacity of the receiver to be the receiver's current * size. Releases any superfluous internal memory. An application can use this operation to minimize the * storage of the receiver. */ public void trimToSize() { // * 1.2 because open addressing's performance exponentially degrades beyond that point // so that even rehashing the table can take very long int newCapacity = nextPrime((int)(1 + 1.2*size())); if (table.length > newCapacity) { rehash(newCapacity); } } /**
/** * Removes the given key with its associated element from the receiver, if * present. * * @param key * the key to be removed from the receiver. * @return <tt>true</tt> if the receiver contained the specified key, * <tt>false</tt> otherwise. */ public boolean removeKey(double key) { int i = indexOfKey(key); if (i < 0) return false; // key not contained this.state[i] = REMOVED; // this.values[i]=0; // delta this.distinct--; if (this.distinct < this.lowWaterMark) { int newCapacity = chooseShrinkCapacity(this.distinct, this.minLoadFactor, this.maxLoadFactor); /* * if (table.length != newCapacity) { * System.out.print("shrink rehashing "); * System.out.println("at distinct=" * +distinct+", capacity="+table.length * +" to newCapacity="+newCapacity+" ..."); } */ rehash(newCapacity); } return true; }
byte newState[] = new byte[newCapacity]; this.lowWaterMark = chooseLowWaterMark(newCapacity,this.minLoadFactor); this.highWaterMark = chooseHighWaterMark(newCapacity,this.maxLoadFactor); if (oldState[i]==FULL) { double element = oldTable[i]; int index = indexOfInsertion(element); newTable[index]=element; newValues[index]=oldValues[i];
/** * Ensures that the receiver can hold at least the specified number of * associations without needing to allocate new internal memory. If * necessary, allocates new internal memory and increases the capacity of * the receiver. * <p> * This method never need be called; it is for performance tuning only. * Calling this method before <tt>put()</tt>ing a large number of * associations boosts performance, because the receiver will grow only once * instead of potentially many times and hash collisions get less probable. * * @param minCapacity * the desired minimum capacity. */ public void ensureCapacity(int minCapacity) { if (table.length < minCapacity) { int newCapacity = nextPrime(minCapacity); rehash(newCapacity); } }
int capacity = initialCapacity; super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity == 0) capacity = 1; // open addressing needs at least one FREE slot at any this.highWaterMark = chooseHighWaterMark(capacity, this.maxLoadFactor);
/** * Returns <tt>true</tt> if the receiver contains the specified value. * * @return <tt>true</tt> if the receiver contains the specified value. */ public boolean containsValue(int value) { return indexOfValue(value) >= 0; }