class SISFC::SortedArray
the SortedArray
class was taken from the ruby cookbook
Public Class Methods
new(*args, &sort_by)
click to toggle source
Calls superclass method
# File lib/sisfc/sorted_array.rb, line 6 def initialize(*args, &sort_by) @sort_by = sort_by || Proc.new { |x,y| x <=> y } super(*args) sort! &sort_by end
Public Instance Methods
<<(el)
click to toggle source
# File lib/sisfc/sorted_array.rb, line 33 def <<(el) insert(0, el) end
insert(i, v)
click to toggle source
Calls superclass method
# File lib/sisfc/sorted_array.rb, line 12 def insert(i, v) if size == 0 or v < self[0] super(0, v) elsif v > self[-1] super(-1, v) else left = 0 right = size - 1 middle = (left + right)/2 while left < right if v >= self[middle] left = middle + 1 else right = middle end middle = (left + right)/2 end super(middle, v) end end
reverse!()
click to toggle source
# File lib/sisfc/sorted_array.rb, line 55 def reverse! # do nothing: reversing the array would disorder it. end