private boolean put()

in graphjet-core/src/main/java/com/twitter/graphjet/hashing/IntToIntPairConcurrentHashMap.java [174:209]


  private boolean put(
      int key,
      int firstValue,
      int secondValue,
      ReaderAccessibleInfo currentReaderAccessibleInfo,
      boolean updateCounters) {
    int primaryHashValue = primaryHashFunction(key);
    int hashedValue = primaryHashValue & currentReaderAccessibleInfo.bitMask;
    int position = hashedValue * NUM_INTS_PER_KEY;
    long currentKey = currentReaderAccessibleInfo.array.getEntry(position);
    if (currentKey == defaultReturnValue) {
      return setEntries(
          position,
          key,
          firstValue,
          secondValue,
          currentReaderAccessibleInfo.array,
          updateCounters);

    } else if (currentKey == key) {
      // otherwise if the bucket already has the key, return
      return true;
    }
    // If the primary location has some other element, then open address using double hashing
    // Double hashed probing is given by: h1(key) + i * h2(key)
    int secondaryHashKey = secondaryHashFunction(key, currentReaderAccessibleInfo.bitMask);
    do {
      hashedValue =
          (int) (((long) hashedValue + secondaryHashKey) & currentReaderAccessibleInfo.bitMask);
      position = hashedValue * NUM_INTS_PER_KEY;
      currentKey = currentReaderAccessibleInfo.array.getEntry(position);
    } while ((currentKey != defaultReturnValue) && (currentKey != key));
    // At this point we either find an empty bucket or the bucket that currently contains the key
    return setEntries(
        position, key, firstValue, secondValue, currentReaderAccessibleInfo.array, updateCounters);
  }