Skip to content

Commit

Permalink
Update index to use calculated index
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed Apr 24, 2024
1 parent 1149d93 commit 1e9c298
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/sorted_containers/sorted_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,11 @@ def internal_bisect_right(array, value)
#
# @param index [Integer] The index to get the value from.
def get_value_at_index(index)
raise "Index out of range" if index.abs >= @size

index += @size if index.negative?
@lists.each do |sublist|
return sublist[index] if index < sublist.size
return nil if index.abs >= @size

index -= sublist.size
end
# get index from pos
index, sublist_index = pos(index)
@lists[index][sublist_index]
end

# Gets values from a range.
Expand Down

0 comments on commit 1e9c298

Please sign in to comment.