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

Iterator support seek ? #66

Closed
zhengxiaochuan-3 opened this issue Oct 24, 2017 · 5 comments
Closed

Iterator support seek ? #66

zhengxiaochuan-3 opened this issue Oct 24, 2017 · 5 comments

Comments

@zhengxiaochuan-3
Copy link

zhengxiaochuan-3 commented Oct 24, 2017

Any follow up plan to add "seek" function for treemap ?
like:

	it := m.Iterator()
	prefix :="1234"
        it.Seek(prefix)
	for it.Next() {
		...
	}
@emirpasic
Copy link
Owner

@zhengxiaochuan-3 sure, let's keep this issue open and see if more people vote for it.

@asdine
Copy link

asdine commented Feb 15, 2019

Any plan for this feature?

@emirpasic
Copy link
Owner

@asdine looks like it's on the road map given the number of up votes

@emirpasic
Copy link
Owner

Related to #95

@emirpasic
Copy link
Owner

#189 brings in the two new functions that can help achieve the above, i.e. NextTo() and PrevTo()

Given the above comment on requested functionality, this can now be achieved with:

	// Seek key-value pair whose value starts with "1234"
	seek := func(key interface{}, value interface{}) bool {
		return strings.HasSuffix(value.(string), "1234")
	}

	for found := it.NextTo(seek); found; found = it.Next() {
		key, value := it.Key(), it.Value()
		...
	} 

For a working example refer to: https://github.com/emirpasic/gods/blob/master/examples/iteratorwithkey/iteratorwithkey.go#L71-L80

Please let me know if the above is not what was requested so I can reopen this issue.

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

No branches or pull requests

3 participants