summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-15 12:58:49 -0600
committermo khan <mo.khan@gmail.com>2020-05-15 12:58:49 -0600
commitaccc110fbc970e4734b4b85bfecddaf64d964b19 (patch)
treec6f9af99a613de68b036d217df70c553ae60a394 /lib
parent95ba331e0ffbddf945d11270946c4687174b1bf9 (diff)
Make #scan a private method
Diffstat (limited to 'lib')
-rw-r--r--lib/spandx/core/index_file.rb31
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/spandx/core/index_file.rb b/lib/spandx/core/index_file.rb
index 31b63c7..bf5f886 100644
--- a/lib/spandx/core/index_file.rb
+++ b/lib/spandx/core/index_file.rb
@@ -21,24 +21,15 @@ module Spandx
end
end
- def search
- min = 0
- max = size
-
+ def search(min: 0, max: size)
scan do |reader|
until min >= max
- mid = (max - min) == 1 ? min : (((max - min) / 2) + min)
+ mid = mid_for(min, max)
row = reader.row(mid)
- return if row.nil? || row.empty?
-
comparison = yield row
return row if comparison.zero?
- if comparison.positive?
- min = mid + 1
- else
- max = mid
- end
+ comparison.positive? ? (min = mid + 1) : (max = mid)
end
end
end
@@ -59,12 +50,6 @@ module Spandx
entry
end
- def scan
- data_file.open_file(mode: 'rb') do |io|
- yield Relation.new(io, self)
- end
- end
-
def update!
return unless data_file.exist?
@@ -76,6 +61,12 @@ module Spandx
attr_reader :entries
+ def scan
+ data_file.open_file(mode: 'rb') do |io|
+ yield Relation.new(io, self)
+ end
+ end
+
def offset_for(row_number)
row_number * UINT_32_SIZE
end
@@ -101,6 +92,10 @@ module Spandx
lines.pop if lines.size > 1
lines
end
+
+ def mid_for(min, max)
+ (max - min) == 1 ? min : (((max - min) / 2) + min)
+ end
end
end
end