Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Jan 20, 2025
1 parent 7c8ab55 commit 395a23f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 3 additions & 2 deletions waku/waku_store_sync/storage/range_processing.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std/math, chronos
import chronos

import ../../waku_core/time, ../common

Expand Down Expand Up @@ -28,7 +28,8 @@ proc equalPartitioning*(slice: Slice[ID], count: int): seq[Slice[ID]] =
if totalLength < count:
return @[]

var (parts, rem) = divmod(totalLength, count)
let parts = totalLength div count
var rem = totalLength mod count

var bounds = newSeqOfCap[Slice[ID]](count)

Expand Down
14 changes: 10 additions & 4 deletions waku/waku_store_sync/storage/seq_storage.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import ../../waku_core/time, ../common, ./range_processing, ./storage
type SeqStorage* = ref object of SyncStorage
elements: seq[ID]

# Numer of parts a range will be splitted into.
partitionCount: int

# Number of element in a range for which item sets are used instead of fingerprints.
lengthThreshold: int

method length*(self: SeqStorage): int =
Expand Down Expand Up @@ -54,7 +57,9 @@ method prune*(self: SeqStorage, timestamp: Timestamp): int {.raises: [].} =

return idx

proc fingerprinting(self: SeqStorage, sliceOpt: Option[Slice[int]]): Fingerprint =
proc computefingerprintFromSlice(
self: SeqStorage, sliceOpt: Option[Slice[int]]
): Fingerprint =
## XOR all hashes of a slice of the storage.

var fingerprint = EmptyFingerprint
Expand Down Expand Up @@ -88,11 +93,11 @@ proc findIdxBounds(self: SeqStorage, slice: Slice[ID]): Option[Slice[int]] =

return some(lower ..< upper)

method fingerprinting*(
method computeFingerprint*(
self: SeqStorage, bounds: Slice[ID]
): Fingerprint {.raises: [].} =
let idxSliceOpt = self.findIdxBounds(bounds)
return self.fingerprinting(idxSliceOpt)
return self.computefingerprintFromSlice(idxSliceOpt)

proc processFingerprintRange*(
self: SeqStorage,
Expand Down Expand Up @@ -124,7 +129,8 @@ proc processFingerprintRange*(
output.itemSets.add(state)
return

for partitionBounds in equalPartitioning(inputBounds, self.partitionCount):
let partitions = equalPartitioning(inputBounds, self.partitionCount)
for partitionBounds in partitions:
let sliceOpt = self.findIdxBounds(partitionBounds)

let slice =
Expand Down
14 changes: 7 additions & 7 deletions waku/waku_store_sync/storage/storage.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ type SyncStorage* = ref object of RootObj
method insert*(
self: SyncStorage, element: ID
): Result[void, string] {.base, gcsafe, raises: [].} =
discard
return err("insert method not implemented for SyncStorage")

method batchInsert*(
self: SyncStorage, elements: seq[ID]
): Result[void, string] {.base, gcsafe, raises: [].} =
discard
return err("batchInsert method not implemented for SyncStorage")

method prune*(
self: SyncStorage, timestamp: Timestamp
): int {.base, gcsafe, raises: [].} =
discard
-1

method fingerprinting*(
method computeFingerprint*(
self: SyncStorage, bounds: Slice[ID]
): Fingerprint {.base, gcsafe, raises: [].} =
discard
return EmptyFingerprint

method processPayload*(
self: SyncStorage,
payload: SyncPayload,
hashToSend: var seq[Fingerprint],
hashToRecv: var seq[Fingerprint],
): SyncPayload {.base, gcsafe, raises: [].} =
discard
return SyncPayload()

method length*(self: SyncStorage): int {.base, gcsafe, raises: [].} =
discard
-1

0 comments on commit 395a23f

Please sign in to comment.