diff --git a/roaring/roaring.go b/roaring/roaring.go index 77483c84f..8c3cbc52e 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -478,25 +478,25 @@ func (b *Bitmap) Xor(other *Bitmap) *Bitmap { return output } -func (b *Bitmap) Shift() (*Bitmap) { +func (b *Bitmap) Shift() *Bitmap { output := NewBitmap() iiter, _ := b.Containers.Iterator(0) - last:=false - lastKey:= uint64(0) + last := false + lastKey := uint64(0) for iiter.Next() { ki, ci := iiter.Value() o, carry := shift(ci) if last { o.add(0) } - if o.n>0{ + if o.n > 0 { output.Containers.Put(ki, o) } last = carry - lastKey=ki + lastKey = ki } if last { //handle the overflow - extra:= NewContainer() + extra := NewContainer() extra.add(0) output.Containers.Put(lastKey+1, extra) } diff --git a/row.go b/row.go index fcf0b2438..6a5f541c4 100644 --- a/row.go +++ b/row.go @@ -153,10 +153,11 @@ func (r *Row) Difference(other *Row) *Row { return &Row{segments: segments} } + // Shift returns the bitwise shift of r by 1 bit. func (r *Row) Shift() *Row { var segments []rowSegment - for _,segment := range r.segments { + for _, segment := range r.segments { segments = append(segments, *segment.Shift()) } @@ -336,6 +337,7 @@ func (s *rowSegment) Xor(other *rowSegment) *rowSegment { n: data.Count(), } } + // Shift returns s shifted by 1 bit. func (s *rowSegment) Shift() *rowSegment { //TODO deal with overflow