public String toString() { final StringBuffer s = new StringBuffer(); s.append("[ "); for (int i = 0; i < n; i++) { if (i != 0) s.append(", "); s.append(CharArrayList.wrap(getArray(i)).toString()); } s.append(" ]"); return s.toString(); }
@SuppressWarnings("unchecked") public void remove() { if (last == -1) throw new IllegalStateException(); if (pos < -1) { // We're removing wrapped entries. Char2ObjectOpenCustomHashMap.this.remove(wrapped.getChar(-pos - 2)); last = -1; return; } size--; if (shiftKeys(last) == pos && c > 0) { c++; nextEntry(); } last = -1; // You can no longer remove this entry. if (ASSERTS) checkTable(); }
/** * Shifts left entries with the specified hash code, starting at the specified position, and * empties the resulting free entry. If any entry wraps around the table, instantiates lazily * {@link #wrapped} and stores the entry key. * * @param pos a starting position. * @return the position cleared by the shifting process. */ protected final int shiftKeys(int pos) { // Shift entries with the same hash. int last, slot; for (; ; ) { pos = ((last = pos) + 1) & mask; while (used[pos]) { slot = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode(key[pos]))) & mask; if (last <= pos ? last >= slot || slot > pos : last >= slot && slot > pos) break; pos = (pos + 1) & mask; } if (!used[pos]) break; if (pos < last) { // Wrapped entry. if (wrapped == null) wrapped = new CharArrayList(); wrapped.add(key[pos]); } key[last] = key[pos]; value[last] = value[pos]; } used[last] = false; value[last] = null; return last; }
public int nextEntry() { if (!hasNext()) throw new NoSuchElementException(); c--; // We are just enumerating elements from the wrapped list. if (pos < 0) { final char k = wrapped.getChar(-(last = --pos) - 2); // The starting point. int pos = (it.unimi.dsi.fastutil.HashCommon.murmurHash3(strategy.hashCode(k))) & mask; // There's always an unused entry. while (used[pos]) { if ((strategy.equals((key[pos]), (k)))) return pos; pos = (pos + 1) & mask; } } last = pos; // System.err.println( "Count: " + c ); if (c != 0) { final boolean used[] = Char2ObjectOpenCustomHashMap.this.used; while (pos-- != 0 && !used[pos]) ; // When here pos < 0 there are no more elements to be enumerated by scanning, but wrapped // might be nonempty. } return last; }