pub fn single_wire_multiplex(
b: &CircuitBuilder,
inputs: &[Wire],
sel: Wire,
) -> WireExpand description
Creates a single-wire multiplexer circuit that selects an element from a vector based on a selector value.
This circuit validates that the output contains the element at position sel from the input
vector inputs. The selection is done using a binary tree of 2-to-1 select gates.
§Arguments
b- Circuit builderinputs- Input vector of N elements (N can be any positive number)sel- Selector value (only ceil(log2(N)) LSB bits are used)
§Returns
The output wire containing the selected element
§Implementation Details
- Builds a binary tree of 2-to-1 select gates, level by level
- Binary tree has ceil(log2(N)) levels for N inputs
- For non-power-of-two inputs, unpaired wires are carried forward to the next level
- Each level uses a different bit from the selector
- The final output is the single wire remaining after all levels
§Panics
- If inputs.len() is 0