Skip to content

Commit 498236a

Browse files
committed
Clean code and fix issues reported by staticcheck
Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent 68e77ee commit 498236a

File tree

23 files changed

+40
-109
lines changed

23 files changed

+40
-109
lines changed

augmentedtree/atree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ func TestTraverse(t *testing.T) {
639639
found[id.ID()] = true
640640
})
641641
for i := 0; i <= top; i++ {
642-
if found, _ := found[uint64(i)]; !found {
642+
if found := found[uint64(i)]; !found {
643643
t.Errorf("could not find expected interval %d", i)
644644
}
645645
}

bitarray/bitarray.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,7 @@ func (ba *bitArray) Equals(other BitArray) bool {
282282
}
283283

284284
lastIndex, _ := getIndexAndRemainder(ba.highest)
285-
if lastIndex >= selfIndex {
286-
return false
287-
}
288-
289-
return true
285+
return lastIndex < selfIndex
290286
}
291287

292288
// Intersects returns a bool indicating if the supplied bitarray intersects
@@ -371,7 +367,7 @@ func newBitArray(size uint64, args ...bool) *bitArray {
371367
anyset: false,
372368
}
373369

374-
if len(args) > 0 && args[0] == true {
370+
if len(args) > 0 && args[0] {
375371
for i := uint64(0); i < uint64(len(ba.blocks)); i++ {
376372
ba.blocks[i] = maximumBlock
377373
}

bitarray/block_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestBlockToNums(t *testing.T) {
3030

3131
expected := []uint64{s - 6, s - 2}
3232

33-
result := make([]uint64, 0, 0)
33+
result := make([]uint64, 0)
3434
b.toNums(0, &result)
3535
assert.Equal(t, expected, result)
3636
}
@@ -41,7 +41,7 @@ func BenchmarkBlockToNums(b *testing.B) {
4141
block = block.insert(i)
4242
}
4343

44-
nums := make([]uint64, 0, 0)
44+
nums := make([]uint64, 0)
4545
b.ResetTimer()
4646

4747
for i := 0; i < b.N; i++ {

bitarray/encoding.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (ret *sparseBitArray) Deserialize(incoming []byte) error {
122122
var bytesRead int
123123
intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize])
124124
if bytesRead < 0 {
125-
return errors.New("Invalid data for BitArray")
125+
return errors.New("invalid data for BitArray")
126126
}
127127
curLoc += intsize
128128

@@ -131,15 +131,15 @@ func (ret *sparseBitArray) Deserialize(incoming []byte) error {
131131
for i := uint64(0); i < intsToRead; i++ {
132132
nextblock, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize])
133133
if bytesRead < 0 {
134-
return errors.New("Invalid data for BitArray")
134+
return errors.New("invalid data for BitArray")
135135
}
136136
ret.blocks[i] = block(nextblock)
137137
curLoc += intsize
138138
}
139139

140140
intsToRead, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize])
141141
if bytesRead < 0 {
142-
return errors.New("Invalid data for BitArray")
142+
return errors.New("invalid data for BitArray")
143143
}
144144
curLoc += intsize
145145

@@ -148,7 +148,7 @@ func (ret *sparseBitArray) Deserialize(incoming []byte) error {
148148
for i := uint64(0); i < intsToRead; i++ {
149149
nextuint, bytesRead = Uint64FromBytes(incoming[curLoc : curLoc+intsize])
150150
if bytesRead < 0 {
151-
return errors.New("Invalid data for BitArray")
151+
return errors.New("invalid data for BitArray")
152152
}
153153
ret.indices[i] = nextuint
154154
curLoc += intsize

bitarray/encoding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestUnmarshalErrors(t *testing.T) {
124124
}
125125
}
126126

127-
outputBytes, err := Marshal(input)
127+
outputBytes, _ := Marshal(input)
128128

129129
outputBytes[0] = 'C'
130130

btree/immutable/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (t *Tr) delete(keys Keys) error {
6363

6464
pb := path.peek()
6565
node := pb.n
66-
isRoot := bytes.Compare(node.ID, t.Root) == 0
66+
isRoot := bytes.Equal(node.ID, t.Root)
6767
if !t.context.nodeExists(node.ID) {
6868
cp := node.copy()
6969
t.context.addNode(cp)
@@ -103,7 +103,7 @@ func (t *Tr) delete(keys Keys) error {
103103
for pb.prev != nil {
104104
parentBundle := pb.prev
105105
parent := parentBundle.n
106-
isRoot := bytes.Compare(parent.ID, t.Root) == 0
106+
isRoot := bytes.Equal(parent.ID, t.Root)
107107
if !t.context.nodeExists(parent.ID) {
108108
cp := parent.copy()
109109
t.context.addNode(cp)

btree/immutable/item.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ type Item struct {
2222
}
2323

2424
type items []*Item
25-
26-
func (its items) split(numParts int) []items {
27-
parts := make([]items, numParts)
28-
for i := int64(0); i < int64(numParts); i++ {
29-
parts[i] = its[i*int64(len(its))/int64(numParts) : (i+1)*int64(len(its))/int64(numParts)]
30-
}
31-
return parts
32-
}

btree/immutable/rt_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func TestNodeSplit(t *testing.T) {
412412

413413
rt, err = mutable.Commit()
414414
require.NoError(t, err)
415-
rt, err = Load(cfg.Persister, rt.ID(), comparator)
415+
rt, _ = Load(cfg.Persister, rt.ID(), comparator)
416416

417417
result, err = mutable.(*Tr).toList(itemsToValues(items...)...)
418418
require.NoError(t, err)
@@ -504,7 +504,7 @@ func TestRandom(t *testing.T) {
504504

505505
require.NoError(t, err)
506506
expected := toOrdered(items).toItems()
507-
result, err := mutable.(*Tr).toList(itemsToValues(expected...)...)
507+
result, _ := mutable.(*Tr).toList(itemsToValues(expected...)...)
508508
if !assert.Equal(t, expected, result) {
509509
assert.Equal(t, len(expected), len(result))
510510
for i, c := range expected {
@@ -762,7 +762,7 @@ func TestSecondCommitMultipleSplits(t *testing.T) {
762762
mutable := rt.AsMutable()
763763
mutable.AddItems(items[:25]...)
764764
mutable.(*Tr).verify(mutable.(*Tr).Root, t)
765-
rt, err := mutable.Commit()
765+
rt, _ = mutable.Commit()
766766
rt.(*Tr).verify(rt.(*Tr).Root, t)
767767

768768
result, err := rt.(*Tr).toList(itemsToValues(items...)...)

btree/palm/action.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func (ga *getAction) keys() common.Comparators {
5252
}
5353

5454
func (ga *getAction) addNode(i int64, n *node) {
55-
return // not necessary for gets
5655
}
5756

5857
func (ga *getAction) nodes() []*node {

fibheap/fibheap.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ func (heap *FloatingFibonacciHeap) DequeueMin() (*Entry, error) {
251251
func (heap *FloatingFibonacciHeap) DecreaseKey(node *Entry, newPriority float64) (*Entry, error) {
252252

253253
if heap.IsEmpty() {
254-
return nil, EmptyHeapError("Cannot decrease key in an empty heap")
254+
return nil, EmptyHeapError("cannot decrease key in an empty heap")
255255
}
256256

257257
if node == nil {
258-
return nil, NilError("Cannot decrease key: given node is nil")
258+
return nil, NilError("cannot decrease key: given node is nil")
259259
}
260260

261261
if newPriority >= node.Priority {
262-
return nil, fmt.Errorf("The given new priority: %v, is larger than or equal to the old: %v",
262+
return nil, fmt.Errorf("the given new priority: %v, is larger than or equal to the old: %v",
263263
newPriority, node.Priority)
264264
}
265265

@@ -271,11 +271,11 @@ func (heap *FloatingFibonacciHeap) DecreaseKey(node *Entry, newPriority float64)
271271
func (heap *FloatingFibonacciHeap) Delete(node *Entry) error {
272272

273273
if heap.IsEmpty() {
274-
return EmptyHeapError("Cannot delete element from an empty heap")
274+
return EmptyHeapError("cannot delete element from an empty heap")
275275
}
276276

277277
if node == nil {
278-
return NilError("Cannot delete node: given node is nil")
278+
return NilError("cannot delete node: given node is nil")
279279
}
280280

281281
decreaseKeyUnchecked(heap, node, -math.MaxFloat64)
@@ -291,7 +291,7 @@ func (heap *FloatingFibonacciHeap) Delete(node *Entry) error {
291291
func (heap *FloatingFibonacciHeap) Merge(other *FloatingFibonacciHeap) (FloatingFibonacciHeap, error) {
292292

293293
if heap == nil || other == nil {
294-
return FloatingFibonacciHeap{}, NilError("One of the heaps to merge is nil. Cannot merge")
294+
return FloatingFibonacciHeap{}, NilError("one of the heaps to merge is nil. Cannot merge")
295295
}
296296

297297
resultSize := heap.size + other.size

0 commit comments

Comments
 (0)