1
0
Fork 0
forked from External/ergo
Instead of building a new serialized message for each recipient,
try to cache them.
This commit is contained in:
Shivaram Lingamneni 2020-11-27 00:13:47 -05:00
parent f04648e081
commit ec15d367ba
6 changed files with 249 additions and 20 deletions

View file

@ -17,6 +17,14 @@ func BitsetGet(set []uint32, position uint) bool {
return (block & (1 << bit)) != 0
}
// BitsetGetLocal returns whether a given bit of the bitset is set,
// without synchronization.
func BitsetGetLocal(set []uint32, position uint) bool {
idx := position / 32
bit := position % 32
return (set[idx] & (1 << bit)) != 0
}
// BitsetSet sets a given bit of the bitset to 0 or 1, returning whether it changed.
func BitsetSet(set []uint32, position uint, on bool) (changed bool) {
idx := position / 32
@ -79,6 +87,15 @@ func BitsetCopy(set []uint32, other []uint32) {
}
}
// BitsetCopyLocal copies the contents of `other` over `set`,
// without synchronizing the writes to `set`.
func BitsetCopyLocal(set []uint32, other []uint32) {
for i := 0; i < len(set); i++ {
data := atomic.LoadUint32(&other[i])
set[i] = data
}
}
// BitsetSubtract modifies `set` to subtract the contents of `other`.
// Similar caveats about race conditions as with `BitsetUnion` apply.
func BitsetSubtract(set []uint32, other []uint32) {