/** * 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[] oldMasks = masks; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; int[] newMasks = new int[getMaskCapacity(logs, newCapacity)]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) addMask(logs, newData, newMasks, e, getFragment(logs, oldMasks, i)); } this.data = newData; this.masks = newMasks; }
/** * 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[] oldMasks = masks; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; int[] newMasks = new int[getMaskCapacity(logs, newCapacity)]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) addMask(logs, newData, newMasks, e, getFragment(logs, oldMasks, i)); } this.data = newData; this.masks = newMasks; }
/** * 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[] oldMasks = masks; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; int[] newMasks = new int[getMaskCapacity(logs, newCapacity)]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) addMask(logs, newData, newMasks, e, getFragment(logs, oldMasks, i)); } this.data = newData; this.masks = newMasks; }
/** * Inserts a given element into the given slice * * @param s * the slice id * @param e * the elements to be inserted in to the given slice * @return {@code true} if the given element did not occur in the given * slice and thus was inserted. Otherwise {@code false} is returned * and nothing is modified. */ public boolean add(int s, E e) { if (e == null) throw new NullPointerException(); int mask = (1 << s); int oldMask = addMask(logs, data, masks, e, mask); int newMask = oldMask | mask; if (newMask == oldMask) return false; else if (oldMask == 0 && ++occupied == LinearProbing.getUpperSize(data.length)) enlarge(); sizes[s]++; return true; }
/** * Inserts a given element into the given slice * * @param s * the slice id * @param e * the elements to be inserted in to the given slice * @return {@code true} if the given element did not occur in the given * slice and thus was inserted. Otherwise {@code false} is returned * and nothing is modified. */ public boolean add(int s, E e) { if (e == null) throw new NullPointerException(); int mask = (1 << s); int oldMask = addMask(logs, data, masks, e, mask); int newMask = oldMask | mask; if (newMask == oldMask) return false; else if (oldMask == 0 && ++occupied == LinearProbing.getUpperSize(data.length)) enlarge(); sizes[s]++; return true; }
/** * Inserts a given element into the given slice * * @param s * the slice id * @param e * the elements to be inserted in to the given slice * @return {@code true} if the given element did not occur in the given * slice and thus was inserted. Otherwise {@code false} is returned * and nothing is modified. */ public boolean add(int s, E e) { if (e == null) throw new NullPointerException(); int mask = (1 << s); int oldMask = addMask(logs, data, masks, e, mask); int newMask = oldMask | mask; if (newMask == oldMask) return false; else if (oldMask == 0 && ++occupied == LinearProbing.getUpperSize(data.length)) enlarge(); sizes[s]++; return true; }
/** * Decreasing the capacity of the table */ private void shrink() { int oldCapacity = data.length; if (oldCapacity == 1) return; E[] oldData = data; int[] oldMasks = masks; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; int[] newMasks = new int[getMaskCapacity(logs, newCapacity)]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) addMask(logs, newData, newMasks, e, getFragment(logs, oldMasks, i)); } this.data = newData; this.masks = newMasks; }
/** * Decreasing the capacity of the table */ private void shrink() { int oldCapacity = data.length; if (oldCapacity == 1) return; E[] oldData = data; int[] oldMasks = masks; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; int[] newMasks = new int[getMaskCapacity(logs, newCapacity)]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) addMask(logs, newData, newMasks, e, getFragment(logs, oldMasks, i)); } this.data = newData; this.masks = newMasks; }
/** * Decreasing the capacity of the table */ private void shrink() { int oldCapacity = data.length; if (oldCapacity == 1) return; E[] oldData = data; int[] oldMasks = masks; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") E[] newData = (E[]) new Object[newCapacity]; int[] newMasks = new int[getMaskCapacity(logs, newCapacity)]; for (int i = 0; i < oldCapacity; i++) { E e = oldData[i]; if (e != null) addMask(logs, newData, newMasks, e, getFragment(logs, oldMasks, i)); } this.data = newData; this.masks = newMasks; }