Iterator support seek ? #66

Closed
opened 2017-10-24 07:23:07 +00:00 by zhengxiaochuan-3 · 5 comments
zhengxiaochuan-3 commented 2017-10-24 07:23:07 +00:00 (Migrated from github.com)

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

	it := m.Iterator()
	prefix :="1234"
        it.Seek(prefix)
	for it.Next() {
		...
	}
Any follow up plan to add "seek" function for treemap ? like: ``` it := m.Iterator() prefix :="1234" it.Seek(prefix) for it.Next() { ... } ```
emirpasic commented 2017-11-22 21:43:18 +00:00 (Migrated from github.com)

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

@zhengxiaochuan-3 sure, let's keep this issue open and see if more people vote for it.
asdine commented 2019-02-15 22:51:52 +00:00 (Migrated from github.com)

Any plan for this feature?

Any plan for this feature?
emirpasic commented 2019-02-16 00:53:47 +00:00 (Migrated from github.com)

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

@asdine looks like it's on the road map given the number of up votes
emirpasic commented 2022-04-07 15:34:41 +00:00 (Migrated from github.com)

Related to #95

Related to #95
emirpasic commented 2022-04-11 23:34:13 +00:00 (Migrated from github.com)

#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.

#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: ```go // 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods#66
No description provided.