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

Ctrie Iterator #89

Merged
merged 7 commits into from May 18, 2015
Merged

Ctrie Iterator #89

merged 7 commits into from May 18, 2015

Conversation

tylertreat-wf
Copy link
Contributor

Adds Iterator, Size, and Clear operations to the Ctrie. Also adds a Map function to the persistent list.

@dustinhiatt-wf @alexandercampbell-wf @stevenosborne-wf @beaulyddon-wf @rosshendrickson-wf @tannermiller-wf

// computation is amortized across the update operations that occurred
// since the last snapshot.
size := uint(0)
for _ = range c.Iterator() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be for range c.Iterator()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that compatible with go 1.3? Are we still trying to ensure compatibility with 1.3?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point-- the new syntax was not adopted until 1.4

This allows a cancel channel to be passed in to the Ctrie Iterator. When
the channel is closed, the iterator channel will close, freeing up the
goroutine.
@tylertreat
Copy link
Contributor

Think I found a decent compromise on the iterator nonsense @dustinhiatt-wf @alexandercampbell-wf. See last commit.

@beaulyddon-wf
Copy link

lol. The rule of Go.... when all else fails just add another channel.

+1

@alexandercampbell-wk
Copy link
Contributor

+1, but I can't say I like introducing another channel.

@dustinhiatt-wf
Copy link
Contributor

I can merge this, but I have to agree with @alexandercampbell-wf, I'd much prefer to use a stateful iterator instead of leaving it up to the consumer to ensure memory isn't leaked. Especially for people coming from other languages, the duty of having to create a channel and then cancel is a burden people probably aren't used to for a simple iteration.

@tylertreat, I'll merge as is if you want, but I'm just worried people will just forget to cancel or pass in nil and this thing will leak memory. Up to you.

@tylertreat-wf
Copy link
Contributor Author

The stateful iterator will be surprisingly nasty with this type of trie, at least if you want to do it in a "generator" style.

dustinhiatt-wf added a commit that referenced this pull request May 18, 2015
@dustinhiatt-wf dustinhiatt-wf merged commit 9257431 into Workiva:master May 18, 2015
@tylertreat-wf tylertreat-wf deleted the iterator branch May 18, 2015 15:20
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

Successfully merging this pull request may close these issues.

None yet

5 participants