Skip to content

Commit

Permalink
Use <=> instead of comparison operators so it works on arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed Apr 18, 2024
1 parent b986f46 commit 5cf0264
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sorted_containers/sorted_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def each(&block)
# @param value [Object] The value to bisect with.
# @return [Integer] The index where the value should be inserted.
def bisect_left(array, value)
array.bsearch_index { |x| x >= value } || array.size
array.bsearch_index { |x| x <=> value } || array.size
end

# Performs a right bisect on the array.
Expand All @@ -181,7 +181,7 @@ def bisect_left(array, value)
# @param value [Object] The value to bisect with.
# @return [Integer] The index where the value should be inserted.
def bisect_right(array, value)
array.bsearch_index { |x| x > value } || array.size
array.bsearch_index { |x| (x <=> value) == 1 } || array.size
end

# Expands a sublist if it exceeds the load factor.
Expand Down

0 comments on commit 5cf0264

Please sign in to comment.