From 1e9c298454dbf64950e85551a0774102b94b811e Mon Sep 17 00:00:00 2001 From: Garrison Jensen Date: Tue, 23 Apr 2024 20:11:06 -0700 Subject: [PATCH] Update index to use calculated index --- lib/sorted_containers/sorted_array.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/sorted_containers/sorted_array.rb b/lib/sorted_containers/sorted_array.rb index 475054f..333aac6 100644 --- a/lib/sorted_containers/sorted_array.rb +++ b/lib/sorted_containers/sorted_array.rb @@ -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.