-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
var unconfirmedMap *treemap.TreeMap[decimal.Decimal, *wm_model.Block] = treemap.NewWithKeyCompare[ decimal.Decimal, *wm_model.Block ] (BlockNumberCmp)
func BlockNumberCmp(left decimal.Decimal, right decimal.Decimal) bool {
return left.Cmp(right) < 0
}
func DoSomething(latestFastConfirmNum decimal.Decimal) []*wm_model.Block{
var movedBlockList []*wm_model.Block = make([]*wm_model.Block, 0)
it := unconfirmedMap.UpperBound(latestFastConfirmNum)
if it.Valid() {
for it.Prev(); it.Valid(); it.Prev() {
movedBlockList = append(movedBlockList, it.Value())
}
for _, item := range movedBlockList {
unconfirmedMap.Del(item.BlockNumber)
}
}
return movedBlockList
}
Panic at it.Prev()
Besides, I would suggest Valid() function would also check if it is before the first element
If the forward iterator just expect to work forward only, I would suggest a function to convert a forward iterator to a reverse iterator
Metadata
Metadata
Assignees
Labels
No labels