@Override
    int findElementToRemove(Object key) {
        if (key == null || size() == 0) {
            return INVALID_INDEX;
        }
        int slot = slot(elements, key);
        int bestSlot = INVALID_INDEX;
        for (int seen = 0; seen < elements.length; seen++) {
            Element element = elements[slot];
            if (element == null) {
                return bestSlot;
            }
            if (key == element) {
                return slot;
            } else if (element.elementKeysAreEqual(key)) {
                bestSlot = slot;
            }
            slot = (slot + 1) % elements.length;
        }
        return INVALID_INDEX;
    }
Find an element matching an example element.

@param key               The element to match.

@return                  The match index, or INVALID_INDEX if no match was found.
clients/src/main/java/org/apache/kafka/common/utils/ImplicitLinkedHashMultiCollection.java