-
Notifications
You must be signed in to change notification settings - Fork 0
ImmutableTree
The ImmutableTree
implementation aims to mimic the equivalent Go ImmutableTree
.
However, the design we implement ere is such that we have encapsulated the storage and access
to the nodes into the NodeStorageProtocol
. Therefore, any loading, saving, deleting, managing of
cache, memory and such is expected to be handled and delegated to the storage implementation itself.
We are providing this struct because as part of the design process, it was implemented before eventually
being carved out in favour of the NodeStorageProtocol
and the NodeProtocol
. As it may be
useful as part of the coming development of future CosmosSwift milestones, we keep it as suc for now, albeit
as part of the Legacy module.
This tree is not thread safe.
public struct ImmutableTree<Storage: NodeStorageProtocol>: CustomStringConvertible
CustomStringConvertible
public typealias Hash = Storage.Hasher.Hash
public typealias Node = Storage.Node
public typealias Key = Storage.Key
public typealias Value = Storage.Value
We implement here a simple initializer taking a storage instance. The specific strategies around caching, pruning, managing memory and speed of access are intended to be implemented by the type of storage provided dependin on the specific use case.
public init(_ storage: Storage) throws
var root: Node
var version: Int64
var size: Int64
var height: Int8
var hash: Hash
var description: String
public func next(key: Key) -> Key?
public func has(_ key: Key) -> Bool
public func get(_ key: Key) -> (index: Int64, value: Value?)
public func getByIndex(_ index: Int64) -> (key: Key, value: Value)?
public func iterate(_ calling: (Key, Value) -> Bool) -> Bool
public func iterateRange(_ start: Key, _ end: Key, _ ascending: Bool, _ calling: (Key, Value, Int64) -> Bool) -> Bool
public func nodeSize() -> Int
public func getRangeWithProof(_ start: Storage.Key?, _ end: Storage.Key?, _ limit: UInt) throws -> (keys: [Storage.Key], value: [Storage.Value], proof: RangeProof<Storage.Node>)
public func getWithProof(_ key: Storage.Key) throws -> (value: Storage.Value?, proof: RangeProof<Storage.Node>)
Generated at 2021-04-20T11:34:45+0000 using swift-doc 1.0.0-beta.5.