Skip to content

SQLiteNodeStorage

ratranqu edited this page Jun 2, 2020 · 1 revision

SQLiteNodeStorage

This implementation keeps one version in memory and stores committed version to disk in an SQLite database self.version contains the current version which still needs to be committed to the database

public final class SQLiteNodeStorage<Key: Comparable & Codable & DataProtocol & InitialisableProtocol, Value: Codable & DataProtocol & InitialisableProtocol, Hasher: HasherProtocol>: NodeStorageProtocol

Inheritance

NodeStorageProtocol

Nested Type Aliases

Key

public typealias Key = Key

Value

public typealias Value = Value

Hasher

public typealias Hasher = Hasher

Hash

public typealias Hash = Hasher.Hash

Node

public typealias Node = SQLiteNode<Key, Value, Hasher>

Initializers

init(_:)

Create a new SQLiteNodeStorage from a db file If the db is not provided, creates an in memory database

public init(_ path: String? = nil) throws

Properties

roots

var roots

orphans

var orphans: [Hash]

version

var version: Int64

versions

var versions: [Int64]

newNodes

Contains all new nodes created in memory not yet saved to the database. Flushed after calls to commit() or rollback()

var newNodes: [Node]

dbQueue

var dbQueue: DatabaseQueue

nodeCache

Contains all nodes which have been loaded from the database or created in memory

var nodeCache: [Hash: Node]

description

var description: String

Methods

root(at:)

public func root(at _: Int64) -> Node?

rollback()

public func rollback()

set(key:value:)

@discardableResult public func set(key: Key, value: Value) throws -> Bool

remove(key:)

@discardableResult public func remove(key: Key) -> (Value?, Bool)

commit()

public func commit() throws

makeEmpty()

public func makeEmpty() -> Node

makeLeaf(key:value:)

public func makeLeaf(key: Key, value: Value) -> Node

makeInner(key:left:right:)

public func makeInner(key: Key, left: Node, right: Node) -> Node

deleteLast()

public func deleteLast() throws

deleteAll(from:)

public func deleteAll(from _: Int64) throws

loadOrphans(from:)

private func loadOrphans(from: Int64) throws

loadRoot(from:)

private func loadRoot(from: Int64) throws

loadNode(from:lazy:)

Load the node with given hash from the database if lazy is set to true will only load a single node if lazyis set to false, will load the full tree below the node

fileprivate func loadNode(from hash: Hash, lazy _: Bool = true) throws -> Node?

loadNode(from:depth:)

Load the node with given hash from the database and all nodes below to a maximum depth of depth if depth == 0, only load the node

fileprivate func loadNode(from _: Hash, depth _: UInt8) -> Node?

save()

private func save() throws