public void add(long key, byte[] value) { if (keyValueMap.containsKey(key)) { int index = keyValueMap.get(key); array[index].addValue(value); } else { if (count >= array.length) { // Grow. FastLongHashMapElement[] newArray = new FastLongHashMapElement[array.length * 2]; System.arraycopy(array, 0, newArray, 0, count); array = newArray; } array[count] = new FastLongHashMapElement(key, value); keyValueMap.put(key, count); count++; } }
public long addRandomExisting(byte[] value, Random r) { Preconditions.checkState(count > 0); int index = r.nextInt(count); array[index].addValue(value); return array[index].getKey(); }