code: private static int findIndex(int[] buckets, int i) {      
          // Hash the value of i into a slot.  Note that because we're using the
          // bitwise-and to perform the mod, the slot will always be positive even
          // if i is negative.
          int slot = i & (buckets.length - 1);
          int initial = slot;
  
          int firstDeletedSeen = -1;
          do {
              int val = buckets[slot];
              // Record the first DELETED slot we see, but don't return until
              // after we've progressed to either an emtpy slot or the slot with
              // the value.  This ensures that if we somehow delete a sequence of
              // values preceding the slot with the desired value the iteration
              // continues.  However, by recording this slot, if we don't find the
              // value, we can return this index to indicate whether the slot
              // would go.
              if (val == DELETED_MARKER && firstDeletedSeen < 0)
                  firstDeletedSeen = slot;
              // If we found the value itself, then return the slot
              else if (val == i)
                  return slot;  
              // Otherwise, if we found an EMPTY slot, then check whether the
              // value should be placed (potentially) in this slot or in a prior
              // slot that contains a deleted value.
              else if (val == EMPTY_MARKER) {
                  return (firstDeletedSeen < 0) ? slot : firstDeletedSeen;
              }
          } while ((slot = (slot + 1) % buckets.length) != initial);
  
          // If the linear probe has wrapped all the way around the array and if
          // so, return a negative index.  This should only happen if the array is
          // completely full and cannot be grown.
          return -1;           
      }
docs: Returns the index where {@code i} would be in the provided array (which
  include the case where an open slot exists) or {@code -1} if the probe
  was unable to find both {@code i} and any position where {@code i} might
  be stored.