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

Can I set iterator index? #95

Closed
mcauto opened this issue Nov 6, 2018 · 4 comments
Closed

Can I set iterator index? #95

mcauto opened this issue Nov 6, 2018 · 4 comments
Labels

Comments

@mcauto
Copy link

mcauto commented Nov 6, 2018

var list *arraylist.List
list = {0,1,2,3,4,5}
it := list.Iterator()
it.SetIndex(3);
it.Next(); // 4
@emirpasic
Copy link
Owner

Not at the moment, but somebody proposed something interesting:

All three, including yourself, are asking for the same thing more or less, i.e. the ability to get the iterator from a specific location. For key-value structures that's the key, for others perhaps the index.

Not sure if I will call it list.IteratorAt(1) / tree.iteratorAt('someKey') or seek(), but this will definitively be implemented in future! Keeping this issue open until it's implemented on all structures that can be iterated.

@mcauto
Copy link
Author

mcauto commented Nov 10, 2018

I think making setter method in iterator is better than IteratorAt() or seek()
What do you think?

@emirpasic
Copy link
Owner

@mcauto I don't have a strong opinion on either.

so SetIndex() and SetKey() would move the iterator to the given index/key, right?

@emirpasic
Copy link
Owner

#189 Implements the NextTo iterator function.

@mcauto please let me know if the below implements the requested functionality so that I can reopen this issue:

	seek := func(index int, value interface{}) bool {
		return index == 3
	}
	for found := it.NextTo(seek); found; found = it.Next() {
		index, value := it.Index(), it.Value()
	}

PS. I hope that this NextTo function can support the requested functionality rather than adding more functions (SetIndex and SetKey). The reason is to keep GoDS as minimal as possible and yet flexible. But please let me know if it is not what you asked for and I'll reevaluate again, adding SetIndex and SetKey is simple

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

No branches or pull requests

2 participants