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

why LowerBound not reponse ReverseIterator? #37

Open
liyikun opened this issue Nov 21, 2022 · 3 comments
Open

why LowerBound not reponse ReverseIterator? #37

liyikun opened this issue Nov 21, 2022 · 3 comments

Comments

@liyikun
Copy link

liyikun commented Nov 21, 2022

how to get list for LowerBound and UpperBound ?

func Less(x, y treemap.Key) bool { return x.(uint32) < y.(uint32) }

func GetIterator(iterator treemap.ForwardIterator) (keys []uint32, values []uint32) {
	for it := iterator; it.Valid(); it.Next() {
		keys = append(keys, it.Key().(uint32))
		values = append(values, it.Value().(uint32))
	}
	return
}

func TestSortedMap(t *testing.T) {

	testmap := treemap.New(Less)

	for i, v := range []uint32{10, 20, 30, 20, 15, 5} {
		testmap.Set(uint32(i+1), v)
	}

	level := uint32(2)

	keys1, _ := GetIterator(testmap.LowerBound(level))

	keys2, _ := GetIterator(testmap.UpperBound(level))

	t.Log("success")
	t.Log(keys1, keys2)
}

keys1 return [2,3,4,5,6]
keys2 return [3,4,5,6]

i hope keys1 return [1] , i try use it.Prev in GetIterator, but it.Valid isn't work in this case.

how can i use?

@liyikun
Copy link
Author

liyikun commented Nov 21, 2022

i think the LowerBound api should response ReverseIterator

@liyikun
Copy link
Author

liyikun commented Nov 21, 2022

@ncw

@ncw
Copy link
Owner

ncw commented Nov 21, 2022

Maybe @igrmk can help?

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

2 participants