def check
      branch_depth = nil

      traverse do |node, position, stack|
        if position == 0
          # Nodes should have between min_size() and
          # @tree.node_size children or values. Only the root node may have
          # less.
          if node.size > @tree.node_size
            node.error "BigArray node #{node._id} is too large. It has " +
              "#{node.size} nodes instead of max. #{@tree.node_size}."
            return false
          end
          if node.parent && node.size < min_size
            node.error "BigArray node #{node._id} is too small"
            return false
          end

          if node.is_leaf?
            # All leaf nodes must have same distance from root node.
            if branch_depth
              unless branch_depth == stack.size
                node.error "All leaf nodes must have same distance from root"
                return false
              end
            else
              branch_depth = stack.size
            end

            return false unless node.check_leaf_node_links

            if node.children
              node.error "children must be nil for a leaf node"
              return false
            end
          else
            unless node.children.size == node.offsets.size
              node.error "Offset count (#{node.offsets.size}) must be equal " +
                "to children count (#{node.children.size})"
                return false
            end

            if node.values
              node.error "values must be nil for a branch node"
              return false
            end

            unless @prev_sibling.nil? && @next_sibling.nil?
              node.error "prev_sibling and next_sibling must be nil for " +
                "branch nodes"
            end

            return false unless node.check_offsets

            return false unless node.check_child_nodes(stack)
          end
        elsif position <= node.size
          # These checks are done after we have completed the respective child
          # node with index 'position - 1'.
          index = position - 1
          if node.is_leaf?
            if block_given?
              # If a block was given, call this block with the key and value.
              return false unless yield(node.first_index + index,
                                        node.values[index])
            end
          end
        end
      end

      true
    end
def check
      branch_depth = nil

      traverse do |node, position, stack|
        if position == 0
          # Nodes should have between min_size() and
          # @tree.node_size children or values. Only the root node may have
          # less.
          if node.size > @tree.node_size
            node.error "BigArray node #{node._id} is too large. It has " +
              "#{node.size} nodes instead of max. #{@tree.node_size}."
            return false
          end
          if node.parent && node.size < min_size
            node.error "BigArray node #{node._id} is too small"
            return false
          end

          if node.is_leaf?
            # All leaf nodes must have same distance from root node.
            if branch_depth
              unless branch_depth == stack.size
                node.error "All leaf nodes must have same distance from root"
                return false
              end
            else
              branch_depth = stack.size
            end

            return false unless node.check_leaf_node_links

            if node.children
              node.error "children must be nil for a leaf node"
              return false
            end
          else
            unless node.children.size == node.offsets.size
              node.error "Offset count (#{node.offsets.size}) must be equal " +
                "to children count (#{node.children.size})"
                return false
            end

            if node.values
              node.error "values must be nil for a branch node"
              return false
            end

            unless @prev_sibling.nil? && @next_sibling.nil?
              node.error "prev_sibling and next_sibling must be nil for " +
                "branch nodes"
            end

            return false unless node.check_offsets

            return false unless node.check_child_nodes(stack)
          end
        elsif position <= node.size
          # These checks are done after we have completed the respective child
          # node with index 'position - 1'.
          index = position - 1
          if node.is_leaf?
            if block_given?
              # If a block was given, call this block with the key and value.
              return false unless yield(node.first_index + index,
                                        node.values[index])
            end
          end
        end
      end

      true
    end
Check consistency of the node and all subsequent nodes. In case an error
 is found, a message is logged and false is returned.
 @yield [key, value]
 @return [Boolean] true if tree has no errors