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
Ctrie Iterator #89
Conversation
// computation is amortized across the update operations that occurred | ||
// since the last snapshot. | ||
size := uint(0) | ||
for _ = range c.Iterator() { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Think I found a decent compromise on the iterator nonsense @dustinhiatt-wf @alexandercampbell-wf. See last commit. |
lol. The rule of Go.... when all else fails just add another channel. +1 |
+1, but I can't say I like introducing another channel. |
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. |
The stateful iterator will be surprisingly nasty with this type of trie, at least if you want to do it in a "generator" style. |
Adds
Iterator
,Size
, andClear
operations to the Ctrie. Also adds aMap
function to the persistent list.@dustinhiatt-wf @alexandercampbell-wf @stevenosborne-wf @beaulyddon-wf @rosshendrickson-wf @tannermiller-wf