int put()

in src/main/software/amazon/event/ruler/IntIntMap.java [116:146]


    int put(final int key, final int value) {
        if (key < 0) {
            throw new IllegalArgumentException("key cannot be negative");
        }
        if (value < 0) {
            throw new IllegalArgumentException("value cannot be negative");
        }
        long cellToPut = (((long) key) & KEY_MASK) | (((long) value) << 32);
        int idx = getStartIndex(key);
        do {
            long cell = table[idx];
            if (cell == EMPTY_CELL) {
                // found an empty cell
                table[idx] = cellToPut;
                if (size >= threshold) {
                    rehash(table.length * 2);
                    // 'size' is set inside rehash()
                } else {
                    size++;
                }
                return NO_VALUE;
            }
            if (((int) (cell & KEY_MASK)) == key) {
                // found a non-empty cell with a key matching the one we're writing, so overwrite it
                table[idx] = cellToPut;
                return (int) (cell >> 32);
            }
            // continue walking the chain
            idx = getNextIndex(idx);
        } while (true);
    }