boolean (final int key, final int value) { checkNotNoValue("key", key); checkNotNoValue("value", value); final int capacity = capacity(); final int startIndex = Math.abs(key % capacity); int firstTombstoneIndex = -1; for (int probe = 0; probe < capacity; probe++) { final int slotIndex = (startIndex + probe) % capacity; final int slotKey = table[slotIndex * 2]; final int slotValue = table[slotIndex * 2 + 1]; if (slotKey == key && slotValue == value) { return false;//record already here, nothing to add } if (slotKey == NO_VALUE) { if (slotValue != NO_VALUE) { //slot removed -> remember index, but continue lookup if (firstTombstoneIndex == -1) { firstTombstoneIndex = slotIndex; } } else { //(NO_VALUE, NO_VALUE) -> free slot -> end of probing sequence, no (key, value) found -> insert it: final int insertionIndex = firstTombstoneIndex >= 0 ? firstTombstoneIndex : slotIndex; table[insertionIndex * 2] = key; table[insertionIndex * 2 + 1] = value; aliveValues++; break; } } } if (aliveValues > capacity * loadFactor) { //resize: final Int2IntMultimap newMMap = new Int2IntMultimap(capacity * 2, loadFactor); forEach((_key, _value) -> { newMMap.put(_key, _value); return true; }); this.table = newMMap.table; this.aliveValues = newMMap.aliveValues; this.filledSlots = newMMap.aliveValues; } return true; }