Class: Mongoose::LinearSearch
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #between(search_start, search_end, start_inclusive = false, end_inclusive = false) ⇒ Object
-
#initialize(col) ⇒ LinearSearch
constructor
A new instance of LinearSearch.
- #one_of(*other) ⇒ Object
- #search_table(&search) ⇒ Object
Constructor Details
#initialize(col) ⇒ LinearSearch
Returns a new instance of LinearSearch.
4 5 6 |
# File 'lib/mongoose/linear_search.rb', line 4 def initialize(col) @col = col end |
Instance Method Details
#<(other) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/mongoose/linear_search.rb', line 60 def <(other) return search_table do |table_value| if table_value.nil? false else table_value < other end end end |
#<=(other) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/mongoose/linear_search.rb', line 70 def <=(other) return search_table do |table_value| if table_value.nil? false else table_value <= other end end end |
#==(other) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/mongoose/linear_search.rb', line 80 def ==(other) return search_table do |table_value| if table_value.nil? false else table_value == other end end end |
#>(other) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/mongoose/linear_search.rb', line 40 def >(other) return search_table do |table_value| if table_value.nil? false else table_value > other end end end |
#>=(other) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/mongoose/linear_search.rb', line 50 def >=(other) return search_table do |table_value| if table_value.nil? false else table_value >= other end end end |
#between(search_start, search_end, start_inclusive = false, end_inclusive = false) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/mongoose/linear_search.rb', line 96 def between(search_start, search_end, start_inclusive=false, end_inclusive=false) return search_table do |table_value| if table_value < search_start false elsif table_value == search_start and not start_inclusive false elsif table_value == search_end and not end_inclusive false elsif table_value > search_end false else true end end end |
#one_of(*other) ⇒ Object
90 91 92 93 94 |
# File 'lib/mongoose/linear_search.rb', line 90 def one_of(*other) return search_table do |table_value| other.include?(table_value) end end |
#search_table(&search) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongoose/linear_search.rb', line 8 def search_table(&search) col_index = nil @col.tbl_class.columns.each_with_index do |c,i| if c.name == @col.name col_index = i break end end result = [] @col.tbl_class.with_table do |fptr| begin while true fpos = fptr.tell rec_arr = Marshal.load(fptr) next if rec_arr[0] value = rec_arr[col_index+1] if search.call(value) result << rec_arr[1] end end rescue EOFError end return result end end |