Skip to content

Commit

Permalink
add check
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasguo committed Jun 15, 2021
1 parent 3dc1512 commit 957958a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions ledger/onlineacct.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (h *onlineTopHeap) Push(x interface{}) {
// Pop implements heap.Interface
func (h *onlineTopHeap) Pop() interface{} {
res := h.accts[len(h.accts)-1]
h.accts[len(h.accts)-1] = nil
h.accts = h.accts[:len(h.accts)-1]
return res
}
9 changes: 5 additions & 4 deletions ledger/onlineacct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ func TestOnlineTopHeap_Pop(t *testing.T) {
},
}

acct0 := h.accts[0]
acct1 := h.accts[1]
originalAccounts := h.accts

h.Pop()

require.Equal(t, 2, h.Len())
require.Equal(t, acct0, h.accts[0])
require.Equal(t, acct1, h.accts[1])
require.Equal(t, 3, cap(h.accts))
require.Equal(t, originalAccounts[0], h.accts[0])
require.Equal(t, originalAccounts[1], h.accts[1])
require.Nil(t, originalAccounts[2])
}
2 changes: 1 addition & 1 deletion ledger/roundlru.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (hlc *heapLRUCache) inc() {
}
}
func (hlc *heapLRUCache) reIndex() {
if hlc.entries.heap == nil || len(hlc.entries.heap) == 0 {
if len(hlc.entries.heap) == 0 {
return
}
minprio := hlc.entries.heap[0].useIndex
Expand Down

0 comments on commit 957958a

Please sign in to comment.