mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 15:51:01 +00:00
only write changed values to op log
This commit is contained in:
parent
9b8a97ccb6
commit
c32c8cda84
1 changed files with 22 additions and 22 deletions
|
|
@ -182,25 +182,25 @@ func (b *Bitmap) AddN(a ...uint64) (changed int, err error) {
|
|||
if len(a) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if b.OpWriter != nil {
|
||||
op := &op{
|
||||
typ: opTypeAddBatch,
|
||||
values: a,
|
||||
}
|
||||
if err := b.writeOp(op); err != nil {
|
||||
return 0, errors.Wrap(err, "writing to op log")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO consider applying changes in-memory first and then only writing the
|
||||
// changed bits to op log?
|
||||
for _, v := range a {
|
||||
// Apply to the in-memory bitmap.
|
||||
if b.DirectAdd(v) {
|
||||
a[changed] = v
|
||||
changed++
|
||||
}
|
||||
}
|
||||
|
||||
if b.OpWriter != nil {
|
||||
op := &op{
|
||||
typ: opTypeAddBatch,
|
||||
values: a[:changed],
|
||||
}
|
||||
if err := b.writeOp(op); err != nil {
|
||||
return 0, errors.Wrap(err, "writing to op log")
|
||||
}
|
||||
}
|
||||
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
|
|
@ -243,25 +243,25 @@ func (b *Bitmap) RemoveN(a ...uint64) (changed int, err error) {
|
|||
if len(a) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if b.OpWriter != nil {
|
||||
op := &op{
|
||||
typ: opTypeRemoveBatch,
|
||||
values: a,
|
||||
}
|
||||
if err := b.writeOp(op); err != nil {
|
||||
return 0, errors.Wrap(err, "writing to op log")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO consider applying changes in-memory first and then only writing the
|
||||
// changed bits to op log?
|
||||
for _, v := range a {
|
||||
// Apply to the in-memory bitmap.
|
||||
if b.remove(v) {
|
||||
a[changed] = v
|
||||
changed++
|
||||
}
|
||||
}
|
||||
|
||||
if b.OpWriter != nil {
|
||||
op := &op{
|
||||
typ: opTypeRemoveBatch,
|
||||
values: a[:changed],
|
||||
}
|
||||
if err := b.writeOp(op); err != nil {
|
||||
return 0, errors.Wrap(err, "writing to op log")
|
||||
}
|
||||
}
|
||||
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue