private static @Nullable PageImpl findPageOrInsertionIndex(final @NotNull AtomicReferenceArray<PageImpl> pages,
                                                             final int pageIndex,
                                                             final @Nullable IntRef insertionIndexRef) {
    final int length = pages.length();
    final int initialSlotIndex = hash(pageIndex) % length;
    final int probeStep = 1; // = linear probing

    int firstTombstoneIndex = -1;
    for (int slotIndex = initialSlotIndex, probeNo = 0;
         probeNo < length;
         probeNo++) {
      final PageImpl page = pages.get(slotIndex);

      if (page == null) {
        //end of the probing sequence reached: no such page
        if (insertionIndexRef != null) {
          final int insertionIndex = firstTombstoneIndex >= 0 ? firstTombstoneIndex : slotIndex;
          insertionIndexRef.set(insertionIndex);
        }
        return null;
      }

      if (page.isTombstone()) {
        //Tombstone: page was removed -> look up further, but remember the position
        if (firstTombstoneIndex < 0) {
          //first tombstone is a place to insert new item _if already existent not found_
          // -> we still need to scan until the end of probing sequence to ensure no page
          // with pageIndex exist, but then we'll use firstTombstoneIndex to insert a new page:
          firstTombstoneIndex = slotIndex;
        }
      }
      else if (page.pageIndex() == pageIndex) {
        if (insertionIndexRef != null) {
          insertionIndexRef.set(slotIndex);
        }
        return page;
      }

      slotIndex = (slotIndex + probeStep) % length;
    }

    //no page found AND no space to insert -> need resize
    if (insertionIndexRef != null) {
      insertionIndexRef.set(-1);
    }
    return null;
  }
private static @Nullable PageImpl findPageOrInsertionIndex(final @NotNull AtomicReferenceArray<PageImpl> pages,
                                                             final int pageIndex,
                                                             final @Nullable IntRef insertionIndexRef)