Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Jakub Sztandera committed Dec 7, 2019
1 parent 80dbc25 commit 71b973f
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 294 deletions.
7 changes: 5 additions & 2 deletions chain/types/bitfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ type BitField struct {
}

func NewBitField() BitField {
rle, _ := rlepluslazy.FromBuf([]byte{})
rle, err := rlepluslazy.FromBuf([]byte{})
if err != nil {
panic(err)
}
return BitField{
rle: rle,
bits: make(map[uint64]struct{}),
Expand Down Expand Up @@ -70,7 +73,7 @@ func (bf BitField) Count() (uint64, error) {
return rlepluslazy.Count(s)
}

// All returns all set bits, in random order
// All returns all set bits
func (bf BitField) All() ([]uint64, error) {

runs, err := bf.sum()
Expand Down
29 changes: 0 additions & 29 deletions docs/rewards.m

This file was deleted.

30 changes: 0 additions & 30 deletions docs/rewards.m~

This file was deleted.

Binary file removed docs/rewards1.jpg
Binary file not shown.
19 changes: 0 additions & 19 deletions docs/rewards2.m

This file was deleted.

63 changes: 0 additions & 63 deletions lib/rlepluslazy/bitvec.go.bak

This file was deleted.

147 changes: 0 additions & 147 deletions lib/rlepluslazy/rleplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,150 +45,3 @@ func (rle *RLE) Count() (uint64, error) {
}
return Count(it)
}

/*
type change struct {
set bool
reset bool
index uint64
}
func (c change) valid() bool {
return c.reset || c.set
}
func (rle *RLE) RunIterator() (RunIterator, error) {
if err != nil {
return nil, err
}
if len(rle.changes) == 0 {
return source, nil
}
ch := rle.changes
// using stable sort because we want to preserve change order
sort.SliceStable(ch, func(i int, j int) bool {
return ch[i].index < ch[j].index
})
for i := range ch {
if i+1 >= len(ch) {
break
}
if ch[i].index == ch[i+1].index {
ch[i].set = false
ch[i].reset = false
}
}
sets := make([]uint64, 0, len(ch)/2)
clears := make([]uint64, 0, len(ch)/2)
for _, c := range ch {
if c.set {
sets = append(sets, c.index)
} else if c.reset {
clears = append(clears, c.index)
}
}
setRuns, err := RunsFromSlice(sets)
if err != nil {
return nil, err
}
clearRuns, err := RunsFromSlice(clears)
if err != nil {
return nil, err
}
it := &chit{source: source, sets: setRuns, clears: clearRuns}
return nil, nil
}
type chit struct {
source RunIterator
sets RunIterator
clears RunIterator
next Run
nextSource Run
nextSet Run
nextClear Run
}
func (it *chit) prep() error {
var err error
if !it.nextSource.Valid() && it.source.HasNext() {
it.nextSource, err = it.source.NextRun()
if err != nil {
return err
}
}
if !it.nextSet.Valid() && it.sets.HasNext() {
it.nextSet, err = it.sets.NextRun()
if err != nil {
return err
}
}
if !it.nextClear.Valid() && it.clears.HasNext() {
it.nextClear, err = it.clears.NextRun()
if err != nil {
return err
}
}
for len(it.changes) != 0 && !it.changes[0].valid() {
it.changes = it.changes[1:]
}
var ch change
if len(it.changes) != 0 {
ch = it.changes[0]
}
if it.source.HasNext() {
var err error
it.nextRun, err = it.source.NextRun()
if err != nil {
return err
}
}
if ch.valid() && ch.index < it.runIndex+it.nextRun.Len {
if ch.set != it.nextRun.Val {
// split run
whole := it.nextRun
it.nextRun.Len = ch.index - it.runIndex
}
// if we are here then change was valid so len(it.changes) != 0
it.changes = it.changes[1:]
} else {
it.runIndex = it.runIndex + it.nextRun.Len
}
return nil
}
func (it *chit) HasNext() bool {
return it.nextRun.Valid()
}
func (it *chit) NextRun() (Run, error) {
return it.nextRun, it.prep()
}
func (rle *RLE) Set(index uint64) {
rle.changes = append(rle.changes, change{set: true, index: index})
}
func (rle *RLE) Clear(index uint64) {
rle.changes = append(rle.changes, change{reset: true, index: index})
}
func (rle *RLE) Merge(other *RLE) RunIterator {
return nil
}
*/
10 changes: 7 additions & 3 deletions lib/rlepluslazy/rleplus_reader.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package rlepluslazy

import (
"encoding/binary"

"github.com/multiformats/go-varint"
"golang.org/x/xerrors"
)

Expand Down Expand Up @@ -64,7 +63,12 @@ func (it *rleIterator) prep() error {
return xerrors.Errorf("run too long: %w", ErrDecode)
}
}
it.nextRun.Len, _ = binary.Uvarint(buf)
var err error
it.nextRun.Len, _, err = varint.FromUvarint(buf)
if err != nil {
return err
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rlepluslazy/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (it *addIt) prep() error {
return nil
}

if !it.arun.Val && !it.brun.Val {
if !(it.arun.Val || it.brun.Val) {
min := it.arun.Len
if it.brun.Len < min {
min = it.brun.Len
Expand Down

0 comments on commit 71b973f

Please sign in to comment.