Skip to content

IterRange can never include the last (Max) element #2

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

Open
peterbourgon opened this issue Apr 21, 2011 · 3 comments
Open

IterRange can never include the last (Max) element #2

peterbourgon opened this issue Apr 21, 2011 · 3 comments

Comments

@peterbourgon
Copy link

I want to iterate from a given key to the end of the tree inclusively. But there seems to be no way to get the last (tree.Max()) value as part of that iteration. I don't know what the most elegant solution would be...

  • a bool param to IterRange that would change < @upper to <= @upper?
  • a new IterRangeInclusive that goes @lower <= E <= @upper?
  • telling me I should simply tack on tree.Max() when my IterRange chan returns a nil and I expect another element?
@petar
Copy link
Owner

petar commented Apr 24, 2011

I'll look into this and update.

@petar
Copy link
Owner

petar commented Apr 25, 2011

I'm not yet entirely sure how to design the interface that controls inclusion/exclusion. One tempting possibility is to give a method to iterates from a given node (not item) to a given other node, inclusive. This is most general. To use it, you'd first "find" the nodes you need and then call the iterator. This will require some exposing the Node type, which is not terrible. I will think about this a bit. In the meantime, I've added IterRangeInclusive.

@peterbourgon
Copy link
Author

Now that I think on it a bit, this specific case devolves to a more general case: what I could really use is

func (t *Tree) IterAscendFrom(start Item) <-chan Item

and the complementary IterDescendFrom... working exactly like the existing IterAscend but allowing you to specify a start item which is included in the iteration. Looking forward, IterAscend would then become:

func (t *Tree) IterAscend() <-chan Item {
    return t.IterAscendFrom(t.Min())
}

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