Functional commit

This commit is contained in:
Ehmry - 2019-02-18 23:39:36 +01:00
parent a9959498c5
commit be57e23685
1 changed files with 7 additions and 7 deletions

View File

@ -219,6 +219,8 @@ func newBlobSet*(id: SetId): BlobSet =
## Create a new cold blob set.
BlobSet(kind: coldNode, setId: id)
func isHot*(bs: BlobSet): bool = bs.kind == hotNode
func sparseIndex(x: Key): int = int(x and keyChunkMask)
func compactIndex(t: BlobSet; x: Key): int =
@ -610,14 +612,12 @@ proc load*(store: BlobStore; id: SetId): BlobSet =
waitFor loadSet(store, id, 0)
proc commit*(store: BlobStore; bs: BlobSet): BlobSet =
assert(bs.kind == hotNode)
for e in bs.table.mitems:
case e.kind
of coldNode, leafNode: discard
of hotNode:
e = store.commit e
if bs.kind == coldNode: return bs
let tmp = BlobSet(kind: hotNode, bitmap: bs.bitmap, table: bs.table)
for e in tmp.table.mitems:
if e.isHot: e = store.commit e
let stream = store.openIngestStream(kind=metaBlob)
var buf = encode bs.toCbor
var buf = encode tmp.toCbor
waitFor stream.ingest(buf)
let (id, _) = waitFor finish(stream)
result = BlobSet(kind: coldNode, setId: id)