/** * Decreasing the capacity of the table */ private void shrink() { int oldCapacity = data.length; if (oldCapacity == 1) return; E[] oldData = data; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) LinearProbing.add(newData, e); } this.data = newData; }
/** * Decreasing the capacity of the table */ private void shrink() { int oldCapacity = data.length; if (oldCapacity == 1) return; E[] oldData = data; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) LinearProbing.add(newData, e); } this.data = newData; }
/** * Decreasing the capacity of the table */ private void shrink() { int oldCapacity = data.length; if (oldCapacity == 1) return; E[] oldData = data; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) LinearProbing.add(newData, e); } this.data = newData; }
/** * Increasing the capacity of the table */ private void enlarge() { int oldCapacity = data.length; if (oldCapacity == LinearProbing.MAXIMUM_CAPACITY) throw new IllegalArgumentException( "The set cannot grow beyond the capacity: " + LinearProbing.MAXIMUM_CAPACITY); E[] oldData = data; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) LinearProbing.add(newData, e); } this.data = newData; }
/** * Increasing the capacity of the table */ private void enlarge() { int oldCapacity = data.length; if (oldCapacity == LinearProbing.MAXIMUM_CAPACITY) throw new IllegalArgumentException( "The set cannot grow beyond the capacity: " + LinearProbing.MAXIMUM_CAPACITY); E[] oldData = data; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) LinearProbing.add(newData, e); } this.data = newData; }
/** * Increasing the capacity of the table */ private void enlarge() { int oldCapacity = data.length; if (oldCapacity == LinearProbing.MAXIMUM_CAPACITY) throw new IllegalArgumentException( "The set cannot grow beyond the capacity: " + LinearProbing.MAXIMUM_CAPACITY); E[] oldData = data; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) LinearProbing.add(newData, e); } this.data = newData; }
@Override public boolean add(E e) { if (e == null) throw new NullPointerException(); boolean added = LinearProbing.add(data, e); if (added && ++size == LinearProbing.getUpperSize(data.length)) enlarge(); return added; }
@Override public boolean add(E e) { if (e == null) throw new NullPointerException(); boolean added = LinearProbing.add(data, e); if (added && ++size == LinearProbing.getUpperSize(data.length)) enlarge(); return added; }
@Override public boolean add(E e) { if (e == null) throw new NullPointerException(); boolean added = LinearProbing.add(data, e); if (added && ++size == LinearProbing.getUpperSize(data.length)) enlarge(); return added; }