only write changed values to op log

This commit is contained in:
Matt Jaffee 2019-02-28 14:16:56 -06:00
parent 9b8a97ccb6
commit c32c8cda84
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -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
}