Skip to content

Commit

Permalink
fix: Add support for draining random sequence ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Jul 26, 2022
1 parent 3cb7af8 commit 8e11a47
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions benchmarks/gluon_bench/benchmarks/parallel_seqset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,43 @@ func NewParallelSeqSetRandom(count uint32, numWorkers uint, generateIntervals, r
for i := uint(0); i < numWorkers; i++ {
list := make([]*imap.SeqSet, 0, count)

if generateIntervals && randomDrain {
panic("This is not yet supported")
}

if randomDrain {
available := make([]uint32, count)
for r := uint32(0); r < count; r++ {
available[r] = r + 1
}

for r := uint32(0); r < count; r++ {
index := rand.Uint32() % (count - r)
tmp := available[index]
available[index] = available[count-r-1]
seqSet := &imap.SeqSet{}
seqSet.AddNum(tmp)
list = append(list, seqSet)
if generateIntervals {
const maxIntervalRange = uint32(40)
for len(available) > 0 {
intervalRange := rand.Uint32() % maxIntervalRange
itemsLeft := uint32(len(available))
index := rand.Uint32() % itemsLeft

if index > intervalRange {
index -= intervalRange
} else {
index = 0
}

if index+intervalRange >= itemsLeft {
intervalRange = itemsLeft - index
}

seqSet := &imap.SeqSet{}
seqSet.AddRange(index, index+intervalRange)
list = append(list, seqSet)
available = append(available[:index], available[index+intervalRange:]...)
}
} else {
for r := uint32(0); r < count; r++ {
index := rand.Uint32() % (count - r)
tmp := available[index]
available[index] = available[count-r-1]
seqSet := &imap.SeqSet{}
seqSet.AddNum(tmp)
list = append(list, seqSet)
}
}
} else {
for r := uint32(0); r < count; r++ {
Expand Down

0 comments on commit 8e11a47

Please sign in to comment.