mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-17 12:53:07 +00:00
Swaps in indexing strategy into erasure.
This commit is contained in:
parent
46612123d8
commit
2c2e42d363
@ -127,7 +127,12 @@ proc prepareEncodingData(
|
||||
##
|
||||
|
||||
let
|
||||
indicies = toSeq(countup(step, params.rounded - 1, params.steps))
|
||||
strategy = SteppedIndexingStrategy.new(
|
||||
firstIndex = 0,
|
||||
lastIndex = params.rounded - 1,
|
||||
numberOfIterations = params.steps
|
||||
)
|
||||
indicies = strategy.getIndicies(step)
|
||||
pendingBlocksIter = self.getPendingBlocks(manifest, indicies.filterIt(it < manifest.blocksCount))
|
||||
|
||||
var resolved = 0
|
||||
@ -171,7 +176,12 @@ proc prepareDecodingData(
|
||||
##
|
||||
|
||||
let
|
||||
indicies = toSeq(countup(step, encoded.blocksCount - 1, encoded.steps))
|
||||
strategy = SteppedIndexingStrategy.new(
|
||||
firstIndex = 0,
|
||||
lastIndex = encoded.blocksCount - 1,
|
||||
numberOfIterations = encoded.steps
|
||||
)
|
||||
indicies = strategy.getIndicies(step)
|
||||
pendingBlocksIter = self.getPendingBlocks(encoded, indicies)
|
||||
|
||||
var
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import ./manifest/coders
|
||||
import ./manifest/manifest
|
||||
import ./manifest/indexingstrategy
|
||||
|
||||
export manifest, coders
|
||||
export manifest, coders, indexingstrategy
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import std/sequtils
|
||||
import ../utils
|
||||
|
||||
type
|
||||
# Representing a strategy for grouping indices (of blocks usually)
|
||||
@ -8,6 +9,7 @@ type
|
||||
firstIndex: int # Lowest index that can be returned
|
||||
lastIndex: int # Highest index that can be returned
|
||||
numberOfIterations: int # getIndices(iteration) will run from 0 ..< numberOfIterations
|
||||
step: int
|
||||
|
||||
# Simplest approach:
|
||||
# 0 => 0, 1, 2
|
||||
@ -35,15 +37,16 @@ proc new*(T: type IndexingStrategy, firstIndex, lastIndex, numberOfIterations: i
|
||||
T(
|
||||
firstIndex: firstIndex,
|
||||
lastIndex: lastIndex,
|
||||
numberOfIterations: numberOfIterations
|
||||
numberOfIterations: numberOfIterations,
|
||||
step: divUp((lastIndex - firstIndex), numberOfIterations)
|
||||
)
|
||||
|
||||
method getIndicies*(self: LinearIndexingStrategy, iteration: int): seq[int] =
|
||||
self.assertIteration(iteration)
|
||||
|
||||
let
|
||||
first = self.firstIndex + iteration * self.numberOfIterations
|
||||
last = min(first + self.numberOfIterations, self.lastIndex)
|
||||
first = self.firstIndex + iteration * self.step
|
||||
last = min(first + self.step, self.lastIndex)
|
||||
toSeq(countup(first, last - 1, 1))
|
||||
|
||||
method getIndicies*(self: SteppedIndexingStrategy, iteration: int): seq[int] =
|
||||
@ -51,5 +54,5 @@ method getIndicies*(self: SteppedIndexingStrategy, iteration: int): seq[int] =
|
||||
|
||||
let
|
||||
first = self.firstIndex + iteration
|
||||
last = first + (self.numberOfIterations * self.numberOfIterations)
|
||||
last = first + (self.step * self.numberOfIterations)
|
||||
toSeq(countup(first, last - 1, self.numberOfIterations))
|
||||
|
||||
@ -10,28 +10,33 @@ for offset in @[0, 1, 100]:
|
||||
checksuite "Indexing strategies (Offset: " & $offset & ")":
|
||||
let
|
||||
firstIndex = 0 + offset
|
||||
lastIndex = 9 + offset
|
||||
lastIndex = 12 + offset
|
||||
nIters = 3
|
||||
linear = LinearIndexingStrategy.new(firstIndex, lastIndex, nIters)
|
||||
stepped = SteppedIndexingStrategy.new(firstIndex, lastIndex, nIters)
|
||||
|
||||
test "linear":
|
||||
check:
|
||||
linear.getIndicies(0) == @[0, 1, 2].mapIt(it + offset)
|
||||
linear.getIndicies(1) == @[3, 4, 5].mapIt(it + offset)
|
||||
linear.getIndicies(2) == @[6, 7, 8].mapIt(it + offset)
|
||||
|
||||
test "linear - oob":
|
||||
expect AssertionDefect:
|
||||
discard linear.getIndicies(3)
|
||||
linear.getIndicies(0) == @[0, 1, 2, 3].mapIt(it + offset)
|
||||
linear.getIndicies(1) == @[4, 5, 6, 7].mapIt(it + offset)
|
||||
linear.getIndicies(2) == @[8, 9, 10, 11].mapIt(it + offset)
|
||||
|
||||
test "stepped":
|
||||
check:
|
||||
stepped.getIndicies(0) == @[0, 3, 6].mapIt(it + offset)
|
||||
stepped.getIndicies(1) == @[1, 4, 7].mapIt(it + offset)
|
||||
stepped.getIndicies(2) == @[2, 5, 8].mapIt(it + offset)
|
||||
stepped.getIndicies(0) == @[0, 3, 6, 9].mapIt(it + offset)
|
||||
stepped.getIndicies(1) == @[1, 4, 7, 10].mapIt(it + offset)
|
||||
stepped.getIndicies(2) == @[2, 5, 8, 11].mapIt(it + offset)
|
||||
|
||||
test "stepped - oob":
|
||||
expect AssertionDefect:
|
||||
discard stepped.getIndicies(3)
|
||||
checksuite "Indexing strategies - oob":
|
||||
let
|
||||
linear = LinearIndexingStrategy.new(0, 10, 3)
|
||||
stepped = SteppedIndexingStrategy.new(0, 10, 3)
|
||||
|
||||
test "linear":
|
||||
expect AssertionDefect:
|
||||
discard linear.getIndicies(3)
|
||||
|
||||
test "stepped":
|
||||
expect AssertionDefect:
|
||||
discard stepped.getIndicies(3)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user