Struct nicompiler_backend::instruction::InstrBook
source · pub struct InstrBook {
pub start_pos: usize,
pub end_pos: usize,
pub keep_val: bool,
pub instr: Instruction,
}
Expand description
Manages an instruction along with its associated metadata during experiment editing.
The InstrBook
struct captures the following metadata:
- Defined interval using
start_pos
andend_pos
. - A flag,
keep_val
, to determine whether to retain the value after the defined interval.
For the instruction interval:
start_pos
is inclusive.end_pos
is exclusive.
InstrBook
implements ordering based on start_pos
to facilitate sorting.
editing phase: defined interval, and whether to keep value after defined interval.
For instruction interval, start_pos
is inclusive while end_pos
is exclusive.
We implemented ordering for InstrBook
to allow sorting based on start_pos
.
Fields§
§start_pos: usize
§end_pos: usize
§keep_val: bool
§instr: Instruction
Implementations§
source§impl InstrBook
impl InstrBook
sourcepub fn new(
start_pos: usize,
end_pos: usize,
keep_val: bool,
instr: Instruction
) -> Self
pub fn new( start_pos: usize, end_pos: usize, keep_val: bool, instr: Instruction ) -> Self
Constructs a new InstrBook
object.
Checks that end_pos
is strictly greater than start_pos
.
Arguments
start_pos
: Starting position (inclusive).end_pos
: Ending position (exclusive).keep_val
: Flag to determine if value should be retained after the interval.instr
: The associated instruction.
Examples
Constructing a valid InstrBook
:
let instruction = Instruction::new(InstrType::CONST, [("value".to_string(), 1.0)].iter().cloned().collect());
let book = InstrBook::new(0, 5, true, instruction);
Attempting to construct an InstrBook
with end_pos
not greater than start_pos
will panic:
let instruction = Instruction::new(InstrType::CONST, [("value".to_string(), 1.0)].iter().cloned().collect());
let book = InstrBook::new(5, 5, true, instruction);
The panic message will be:
Instruction { /* ... */ } end_pos 5 should be strictly greater than start_pos 5
.
Trait Implementations§
source§impl Ord for InstrBook
impl Ord for InstrBook
source§impl PartialEq<InstrBook> for InstrBook
impl PartialEq<InstrBook> for InstrBook
source§impl PartialOrd<InstrBook> for InstrBook
impl PartialOrd<InstrBook> for InstrBook
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more