On 6/29/06, Nick Coghlan <[EMAIL PROTECTED]> wrote:
> You mean something like this?:
>
>    switch x in colours:
>      case RED:
>          # whatever
>      case GREEN:
>          # whatever
>      case BLUE:
>          # whatever
>
> I think Guido's right. It doesn't solve the underlying problem because the
> compiler still has to figure out how to build a dispatch table from the
> possible values in colours to the actual bytecode offsets of the cases.

To implement this, you actually need two lookup tables: one particular
to the switch that maps labels to bytecode offsets, and one in the
dispatch table to map values to labels.  The former is built when the
switch is compiled, and the latter is built wherever the dispatch
table is defined.  Each lookup is still O(1), so the whole operation
remains O(1).

It is O(n) or worse to check that all of the cases in the switch are
defined in the dispatch table, but that only has to be done once per
dispatch table/switch statement pair, and can then be stred in one or
the other (probably the dispatch table, as that will be a proper
object).

  -- Eric Sumner
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to