Class: Array

Inherits:
Object show all
Defined in:
lib/andromeda/patch/array_bin_search.rb

Defined Under Namespace

Classes: Tag

Instance Method Summary collapse

Instance Method Details

#bin_search(elem, low = 0, high = -1)) ⇒ Fixnum

Binary search for the first elem that is leq elem in this array in the range (low..high-1)

The array is expected to be sorted in descending order.

Parameters:

  • elem (Object)

    elem to search for

  • low (Fixnum) (defaults to: 0)

    lower bound (inclusive)

  • high (Fixnum) (defaults to: -1))

    upper bound (inclusive, -1 for last element)

Returns:

  • (Fixnum)

    index of first occurence leq than elem in self, or -1 if not found



35
36
37
38
# File 'lib/andromeda/patch/array_bin_search.rb', line 35

def bin_search(elem, low = 0, high = -1)
  high = size - 1 if high < 0
  _bin_search elem, low, high
end

#tag!self

Wraps all objects in self into ::Array::Tag instances using the provided block to extract a key

Returns:

  • (self)


45
# File 'lib/andromeda/patch/array_bin_search.rb', line 45

def tag! ; map! { |e| Tag.new (yield e), e } end

#untag!self

Untags Array::Tag instances, i.e. replaces them with their value

Returns:

  • (self)


51
# File 'lib/andromeda/patch/array_bin_search.rb', line 51

def untag! ; map! { |e| e.untagged } end