Jump Table Switch Case question

前端 未结 6 594
孤街浪徒
孤街浪徒 2020-12-08 00:55

I am trying to understand some things about jump tables and its relationship between a switch case statement.

I was told that a jump table is a O(1) structure that t

6条回答
  •  攒了一身酷
    2020-12-08 01:34

    Compiling for a switch statement can take many forms, depending on the cases. If the cases are close together, it is a no brainer: use a jump table. If the cases are far apart, use if (case == value) or use a map. Or a compiler can use a combination: islands of jump tables determined by if checks of the jump table ranges.

提交回复
热议问题