On Mon, Nov 16, 2009 at 8:27 PM, Russ Cox <
r...@golang.org> wrote:
>>> No. It's a fine feature for some languages but at large scale it becomes
>>> very expensive so we decided to leave it out of Go. It's not too hard to
>>> write an O(1) multiplexer in Go; array select is O(N).
>>
>> With a tree of goroutines you could do array select in O(log(N)) even
>> without having it built in.
>
> No, you can do it in O(1), like the mail you quoted says.
I may be missing something here.
My reading of
http://golang.org/doc/go_spec.html#Select_statements
suggests that you can do a O(1) select of any number of channels, but
the specific channels you are selecting on has to be hard coded in
your program because you need explicit case statements in your code
for the list of possibilities.
To handle a list of channels whose size is dynamic at runtime takes
more work. The approach I thought of is to set up a tree of
goroutines that multiplex off of each other. You can then write a
function that takes in a slice of channels which sets up this tree and
returns a channel that returns pairs of (channel_index, value) each
time it is read.
Is there another possibility that I missed?
>> Of course the lack of generics means you'd have to reimplement this
>> for every kind of channel you wanted...
>
> Thanks for your input.
Thanks for your language! Trying to figure out how it does things and
how I could do things with it has been fun and educational. Hopefully
some day what I am learning will be useful for me.
Cheers,
Ben