Skip to content

Branch Table

A constant-time multiway dispatch structure that maps a validated selector through a dense table of code addresses or branch instructions to one of several control-flow targets.

Version
v2 · 2026-09-19 · History
Domain-specific #
1409
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomain
Systems Programming → Computer Science & Software Engineering
Aliases
Jump table, Branch vector, Transfer vector

Core Idea

A Branch Table, commonly called a jump table, implements multiway control transfer by converting a selector into an index and using that index to obtain or reach a code target. Entries may be branch instructions placed at fixed spacing, absolute or relative code addresses, function pointers, or compiler-specific relocation records. After optional normalization and bounds checking, dispatch performs table lookup/address arithmetic followed by an indirect jump or call.

Compilers often generate branch tables for dense switch statements. If case values cover a compact integer range, direct indexing can select a target in essentially constant time, avoiding a linear chain or logarithmic comparison tree. Sparse keys can make a naive table wasteful because every missing value needs an entry or default mapping.

How would you explain it like I'm…

Jump Straight to the Door

Imagine a row of doors numbered 0, 1, 2, 3. Instead of asking 'Is it door 0? No. Is it door 1? No…', you just take the number you were given and walk straight to that door. A branch table lets a computer program do that: it uses a number to jump right to the right set of instructions, after first checking the number is one of the real doors.

Jump-to-the-Right-Code List

When a program has many choices — like 'if the button is 1 do this, if 2 do that, if 3 do something else' — it could check each option one by one. A branch table is a faster trick: the program keeps a list where each spot holds the location of the code for one choice. It turns the choice into a position number, first checking that the number isn't off the end of the list, and then jumps straight to the code stored there. This works best when the choices are numbers close together, like 1 through 10. If the numbers are scattered, the list would have lots of empty spots and waste space.

Indexed Indirect Dispatch Table

A branch table (jump table) implements a multiway choice by turning a selector value into an index and using it to find a code destination. Entries may be branch instructions at fixed spacing, code addresses (absolute or relative), function pointers, or compiler-specific relocation records. Dispatch usually normalizes the selector (for example, subtracting the lowest case value), checks that it is in range, looks up the entry, and then performs an indirect jump or call. Compilers generate these for dense switch statements, where direct indexing selects a case in essentially constant time rather than through a chain of comparisons or a comparison tree. Sparse case values waste space, since every missing value needs a slot, so compilers weigh density, table size, architecture and other costs. A table that just looks up a data value without transferring control is not a branch table.

 

A branch table, or jump table, realizes multiway control transfer: a selector is normalized to a bounded index, the index selects a table entry encoding a code destination, and the program transfers control indirectly to that destination. Entries can be fixed-stride branch instructions, absolute or relative code addresses, function pointers, or compiler-specific relocation records. Dispatch involves optional normalization and bounds checking, then table lookup or address arithmetic, then an indirect jump or call. Compilers commonly emit branch tables for dense switch statements, where a compact integer range allows target selection in essentially constant time instead of a linear chain of tests or a logarithmic comparison tree. Sparse keys make naive tables wasteful because every absent value needs an entry or default mapping, so compilers trade off range density, table size, relocation cost, target architecture, branch prediction, position-independent code and optimization goals. The defining feature is control transfer: a lookup table returning a data value, even one generated from the same switch source, is not a branch table.

Scope of Application

Branch tables occur in compiler lowering, assembly programming, interpreters, embedded firmware, operating-system syscall and interrupt dispatch, protocol parsers, finite-state machines, bytecode virtual machines, and performance-critical command handling. They are especially natural when selectors are small integers or can be cheaply normalized.

Two canonical implementations differ. An instruction table lays out equal-width unconditional branches and jumps into the chosen entry. An address table loads a pointer or relative displacement and performs one indirect transfer. Some architectures support PC-relative table branches or compact instructions designed for this purpose. Position-independent executables often prefer relative offsets to reduce relocations or writable absolute pointers.

Clarity

For cases {10,11,12,13}, normalization may compute i=x−10, verify 0≤i<4, then transfer through table[i]; an out-of-range selector goes to default. If the cases are {1,1000}, the same scheme would allocate about a thousand entries for two destinations. A comparison sequence or hybrid special-case-plus-small-table layout is usually smaller.

Manages Complexity

A chain of n tests embeds selection logic in n comparisons and branches. A branch table separates mapping from execution: data layout maps selectors to destinations, while one generic dispatch sequence performs the transfer. This makes adding a dense case an entry-level change and bounds dispatch work independently of the number of alternatives.

Abstract Reasoning

  1. If case keys form a contiguous range, direct indexing requires constant dispatch operations after one bounds check.
  2. If the key span is far larger than the case count, table space grows with span rather than populated cases.
  3. Subtracting the minimum key reduces table size without changing selection, provided underflow and bounds are handled safely.
  4. Relative offsets can improve position independence and shrink entries when all targets lie within representable range.

Knowledge Transfer

Exact transfer holds across architectures and languages when selector, bounded index, table target, and control transfer remain literal. Instruction tables, address tables, computed gotos, and compiler-generated switch tables are implementation variants.

Database indexes and organizational routing tables share selector-to-destination mapping but do not instantiate this node unless the destination is executable control flow. The portable parents are Indexed Lookup and Branching.

Relationships to Other Abstractions

Local relationship map for Branch TableParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Branch TableDOMAINPrime abstraction: Branching and Merging — includesBranchingand MergingPRIME

Current abstraction Branch Table Domain-specific

Parents (1) — outgoing typed relations

Hierarchy paths (2) — routes to 2 parentless roots

Neighborhood in Abstraction Space

Branch Table sits in a sparse region of the domain-specific corpus (92nd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Combinatorial Covering & Dispatch Structures (6 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-25