lib/perobs/BigTree.rb in perobs-4.5.0 vs lib/perobs/BigTree.rb in perobs-4.6.0

- old
+ new

@@ -1,6 +1,6 @@ -# encoding: UTF-8 +# frozen_string_literal: true # # = BigTree.rb -- Persistent Ruby Object Store # # Copyright (c) 2016, 2017 by Chris Schlaeger <chris@taskjuggler.org> # @@ -33,15 +33,12 @@ # The BigTree class implements a BTree as a PEROBS object. It allows to # manage huge amounts of data in a reasonably efficient way. The number of # entries is limited by the space on the backing store, not the main # memory. Entries are addressed by a Integer key. class BigTree < PEROBS::Object + Stats = Struct.new(:leaf_nodes, :branch_nodes, :min_depth, :max_depth) - class Stats < Struct.new(:leaf_nodes, :branch_nodes, :min_depth, - :max_depth) - end - attr_persist :node_size, :root, :first_leaf, :last_leaf, :entry_counter # Internal constructor. Use Store.new() instead. # @param p [Handle] # @param node_size [Integer] The size of the tree nodes. This determines @@ -116,33 +113,32 @@ # @yield [key, value] def delete_if old_root = @root clear old_root.each do |k, v| - if !yield(k, v) - insert(k, v) - end + insert(k, v) unless yield(k, v) end end # @return [Integer] The number of entries stored in the tree. def length @entry_counter end # Return true if the BigTree has no stored entries. def empty? - @entry_counter == 0 + @entry_counter.zero? end # Iterate over all entries in the tree. Entries are always sorted by the # key. # @yield [key, value] def each(&block) node = @first_leaf while node break if node.each_element(&block).nil? + node = node.next_sibling end end # Iterate over all entries in the tree in reverse order. Entries are @@ -154,11 +150,10 @@ node.reverse_each_element(&block) node = node.prev_sibling end end - # @return [String] Human reable form of the tree. def to_s @root.to_s end @@ -171,12 +166,12 @@ each do |k, v| i += 1 end unless @entry_counter == i - PEROBS.log.error "BigTree contains #{i} values but entry counter " + - "is #{@entry_counter}" + PEROBS.log.error "BigTree contains #{i} values but entry counter " \ + "is #{@entry_counter}" return false end true end @@ -186,12 +181,7 @@ def statistics stats = Stats.new(0, 0, nil, nil) @root.statistics(stats) stats end - - private - end - end -