@Override public void clear() { values.clear(); keyToValue.clear(); valueToKey.clear(); }
private void put(short key, String value) { keyToValue.put(key, value); valueToKey.put(value, key); }
/** * Returns true if we have seen this stringValue before, and it hasn't been removed. * <p> * NOTE: An answer of true does not imply that the column still contains the value, only that * it is in the dictionary map */ private boolean contains(String stringValue) { return valueToKey.containsKey(stringValue); }
private VarNominal() { this.reverse = new Object2ShortOpenHashMap<>(); this.reverse.put("?", (short) 0); this.dict = new ArrayList<>(); this.dict.add("?"); data = new short[0]; rows = 0; }
/** {@inheritDoc} */ @Override public short mergeShort(final K k, final short v, final java.util.function.BiFunction<? super Short, ? super Short, ? extends Short> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) { insert(-pos - 1, k, v); return v; } final Short newValue = remappingFunction.apply(Short.valueOf(value[pos]), Short.valueOf(v)); if (newValue == null) { if (((k) == null)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue).shortValue(); } /*
@Override public void putAll(Map<? extends K, ? extends Short> m) { if (f <= .5) ensureCapacity(m.size()); // The resulting map will be sized for m.size() elements else tryCapacity(size() + m.size()); // The resulting map will be tentatively sized for size() + m.size() // elements super.putAll(m); } @SuppressWarnings("unchecked")
/** {@inheritDoc} */ @Override public short computeShortIfPresent(final K k, final java.util.function.BiFunction<? super K, ? super Short, ? extends Short> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) return defRetValue; final Short newValue = remappingFunction.apply((k), Short.valueOf(value[pos])); if (newValue == null) { if (((k) == null)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue).shortValue(); } /** {@inheritDoc} */
if (((k) == null)) { if (containsNullKey) return addToValue(n, incr); pos = n; containsNullKey = true; return addToValue(pos, incr); while (!((curr = key[pos = (pos + 1) & mask]) == null)) if (((curr).equals(k))) return addToValue(pos, incr); value[pos] = (short) (defRetValue + incr); if (size++ >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable();
/** * Returns a new DictionaryMap that is a deep copy of the original */ ShortDictionaryMap(DictionaryMap original) throws NoKeysAvailableException { valueToKey.defaultReturnValue(DEFAULT_RETURN_VALUE); for (int i = 0; i < original.size(); i++) { String value = original.getValueForIndex(i); append(value); } }
/** {@inheritDoc} */ @Override public short replace(final K k, final short v) { final int pos = find(k); if (pos < 0) return defRetValue; final short oldValue = value[pos]; value[pos] = v; return oldValue; } /** {@inheritDoc} */
@Override public boolean contains(short v) { return containsValue(v); } @Override
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { rows = in.readInt(); dict = new ArrayList<>(); reverse = new Object2ShortOpenHashMap<>(); int len = in.readInt(); for (int i = 0; i < len; i++) { dict.add(in.readUTF()); reverse.put(dict.get(i), (short) i); } data = new short[rows]; for (int i = 0; i < rows; i++) { data[i] = in.readShort(); } }
/** {@inheritDoc} */ @Override public short computeShort(final K k, final java.util.function.BiFunction<? super K, ? super Short, ? extends Short> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); final Short newValue = remappingFunction.apply((k), pos >= 0 ? Short.valueOf(value[pos]) : null); if (newValue == null) { if (pos >= 0) { if (((k) == null)) removeNullEntry(); else removeEntry(pos); } return defRetValue; } short newVal = (newValue).shortValue(); if (pos < 0) { insert(-pos - 1, k, newVal); return newVal; } return value[pos] = newVal; } /** {@inheritDoc} */
/** * Returns a new DictionaryMap that is a deep copy of the original */ ShortDictionaryMap(DictionaryMap original) throws NoKeysAvailableException { valueToKey.defaultReturnValue(DEFAULT_RETURN_VALUE); for (int i = 0; i < original.size(); i++) { String value = original.getValueForIndex(i); append(value); } }
/** {@inheritDoc} */ @Override public boolean replace(final K k, final short oldValue, final short v) { final int pos = find(k); if (pos < 0 || !((oldValue) == (value[pos]))) return false; value[pos] = v; return true; } /** {@inheritDoc} */
@Override public void setLevels(String... dict) { List<String> oldDict = this.dict; if (dict.length > 0 && !dict[0].equals("?")) { String[] newDict = new String[dict.length + 1]; newDict[0] = "?"; System.arraycopy(dict, 0, newDict, 1, dict.length); dict = newDict; } if (this.dict.size() > dict.length) { throw new IllegalArgumentException("new levels does not contains all old labels"); } this.dict = new ArrayList<>(); this.reverse = new Object2ShortOpenHashMap<>(dict.length); this.dict.add("?"); this.reverse.put("?", (short) 0); short[] pos = new short[oldDict.size()]; for (int i = 0; i < dict.length; i++) { String term = dict[i]; if (!reverse.containsKey(term)) { this.dict.add(term); this.reverse.put(term, (short) this.reverse.size()); } if (i < oldDict.size()) pos[i] = this.reverse.getShort(term); } for (int i = 0; i < rows; i++) { data[i] = pos[data[i]]; } }
@Override public void clear() { Object2ShortOpenHashMap.this.clear(); } /** {@inheritDoc} */
/** * Creates a new hash map using the elements of two parallel arrays. * * @param k * the array of keys of the new hash map. * @param v * the array of corresponding values in the new hash map. * @param f * the load factor. * @throws IllegalArgumentException * if {@code k} and {@code v} have different lengths. */ public Object2ShortOpenHashMap(final K[] k, final short[] v, final float f) { this(k.length, f); if (k.length != v.length) throw new IllegalArgumentException( "The key array and the value array have different lengths (" + k.length + " and " + v.length + ")"); for (int i = 0; i < k.length; i++) this.put(k[i], v[i]); } /**