Skip to content

chapter2 : interface Type-switches have sorted  #37

@dreamerjackson

Description

@dreamerjackson
That this reordering is a net win for us in this particular case is nothing but mere luck, AFAICT. In fact, if you take the time to experiment a bit with type-switches, especially ones with more than two cases, you'll find that the compiler always shuffles the cases using some kind of deterministic heuristics.
What those heuristics are, I don't know (but as always, I'd love to if you do).

Type-switches have sorted and runtime use a Binary search to find the result , so the time complexity is log2(n).
if necessary, i am glad to pull request to this repo about how the golang compile do

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions