class Hamster::SortedSet

def find_index(obj = (missing_obj = true), &block)

Returns:
  • (Integer) - The index of the object, or `nil` if not found.

Other tags:
    Yieldreturn: - True if this is element matches

Other tags:
    Yield: - An element in the sorted set

Overloads:
  • find_index
  • find_index(obj)

Parameters:
  • obj (Object) -- The object to search for
def find_index(obj = (missing_obj = true), &block)
  if !missing_obj
    # Enumerable provides a default implementation, but this is more efficient
    node = @node
    index = node.left.size
    while !node.empty?
      direction = node.direction(obj)
      if direction > 0
        node = node.right
        index += (node.left.size + 1)
      elsif direction < 0
        node = node.left
        index -= (node.right.size + 1)
      else
        return index
      end
    end
    nil
  else
    super(&block)
  end
end