Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForwardIterator.Prev() causes panic when it is at first element #1

Open
duncan-to-18m opened this issue Sep 30, 2022 · 0 comments
Open

Comments

@duncan-to-18m
Copy link

duncan-to-18m commented Sep 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant