lib/perobs/BigArray.rb in perobs-4.1.0 vs lib/perobs/BigArray.rb in perobs-4.2.0

- old
+ new

@@ -121,11 +121,15 @@ # Return the value stored at the given index. # @param index [Integer] Position in the array # @return [Integer or nil] found value or nil def [](index) - index = validate_index_range(index) + begin + index = validate_index_range(index) + rescue IndexError + return nil + end return nil if index >= @entry_counter @root.get(index) end @@ -186,9 +190,23 @@ alias size length # Return true if the BigArray has no stored entries. def empty? @entry_counter == 0 + end + + # Return the first entry of the Array. + def first + return nil unless @first_leaf + + @first_leaf.values.first + end + + # Return the last entry of the Array. + def last + return nil unless @last_leaf + + @last_leaf.values.last end # Iterate over all entries in the tree. Entries are always sorted by the # key. # @yield [key, value]