-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add a GetIterator method to treeMap etc #59
Comments
And a function |
Similiar API like https://github.com/google/btree would be great. |
There are two ways now of answering such questions with GoDS (efficient and inefficient way) after #189 using enumerable (creates a new list) or using the efficient iterator NextTo() function. Working example: package main
import (
"fmt"
"github.com/emirpasic/gods/lists/arraylist"
"math/rand"
)
// "search 20 items larger than 50"
func main() {
// Generate some random data
list := arraylist.New()
for i := 0; i < 1000; i++ {
list.Add(rand.Intn(100))
}
// Inefficient way of selecting all elements (enumerable select function)
newList := list.Select(func(index int, value interface{}) bool {
return value.(int) > 50
}).Values()[:20]
fmt.Println(len(newList), newList)
// Efficient iterator way
it := list.Iterator()
seek := func(index int, value interface{}) bool {
return value.(int) > 50
}
for count := 0; count < 20 && it.NextTo(seek); count = count + 1 {
fmt.Println(it.Value())
}
} Let me know if the above solves the needed cases, otherwise I'll reopen the issue |
I think sometimes we use treemap to search continusly data, e.g.:
"search 20 items large than 50",
I think some code like below can solve it:
The text was updated successfully, but these errors were encountered: