Sha256: 5cb74094cd54d5a8b58fc158404456c896cd9f68944a1da9dcc458e99916a476

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module MSSMT
  module Store
    # In-memory implementation of the tree store.
    class DefaultStore
      attr_accessor :branches, :leaves, :root

      def initialize
        @branches = {}
        @leaves = {}
        @root = nil
      end

      # Insert branch node.
      # @param [MSSMT::BranchNode] branch
      # @raise [ArgumentError]
      def insert_branch(branch)
        unless branch.is_a?(MSSMT::BranchNode)
          raise "branch must be MSSMT::BranchNode"
        end

        branches[branch.node_hash] = branch
      end

      # Insert leaf node.
      # @param [MSSMT::LeafNode] leaf
      # @raise [ArgumentError]
      def insert_leaf(leaf)
        raise "leaf must be MSSMT::LeafNode" unless leaf.is_a?(MSSMT::LeafNode)

        leaves[leaf.node_hash] = leaf
      end

      # Delete branch node.
      # @param [String] node_hash node hash of branch node.
      def delete_branch(node_hash)
        branches.delete(node_hash)
      end

      # Delete leaf node
      # @param [String] node_hash node hash of leaf node.
      def delete_leaf(node_hash)
        leaves.delete(node_hash)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mssmt-0.4.2 lib/mssmt/store/default_store.rb
mssmt-0.4.1 lib/mssmt/store/default_store.rb
mssmt-0.4.0 lib/mssmt/store/default_store.rb
mssmt-0.3.0 lib/mssmt/store/default_store.rb
mssmt-0.2.0 lib/mssmt/store/default_store.rb
mssmt-0.1.0 lib/mssmt/store/default_store.rb