Trait AtomTableOps

Source
pub trait AtomTableOps {
    // Required methods
    fn count(&self) -> usize;
    fn get_atom_string(
        &self,
        index: AtomIndex,
    ) -> Result<AtomRef<'_>, AtomError>;
    fn ensure_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>;
    fn find_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>;
    fn atom_equals(&self, atom_index: AtomIndex, data: &[u8]) -> bool;
    fn compare_atoms(&self, atom1: AtomIndex, atom2: AtomIndex) -> i32;
    fn ensure_atoms_bulk(
        &self,
        atoms_data: &[u8],
        count: usize,
        encoding: EnsureAtomsOpt,
    ) -> Result<Vec<AtomIndex>, AtomError>;

    // Provided methods
    fn ensure_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError> { ... }
    fn find_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError> { ... }
    fn atom_equals_str(&self, atom_index: AtomIndex, s: &str) -> bool { ... }
}
Expand description

Trait for atom table operations - the foundation of our generic design

Any implementation (real AtomVM, mock, in-memory, etc.) can provide these operations, making the entire system generic and testable.

Required Methods§

Source

fn count(&self) -> usize

Get the number of atoms currently in the table

Source

fn get_atom_string(&self, index: AtomIndex) -> Result<AtomRef<'_>, AtomError>

Get atom data by index

Source

fn ensure_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>

Ensure an atom exists in the table, creating it if necessary

Source

fn find_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>

Ensure an atom exists, but only if it already exists

Source

fn atom_equals(&self, atom_index: AtomIndex, data: &[u8]) -> bool

Check if an atom equals the given byte string

Source

fn compare_atoms(&self, atom1: AtomIndex, atom2: AtomIndex) -> i32

Compare two atoms lexicographically

Source

fn ensure_atoms_bulk( &self, atoms_data: &[u8], count: usize, encoding: EnsureAtomsOpt, ) -> Result<Vec<AtomIndex>, AtomError>

Bulk insert/lookup atoms from encoded atom data

Provided Methods§

Source

fn ensure_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError>

Ensure an atom exists using a string slice

Source

fn find_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError>

Find an atom using a string slice

Source

fn atom_equals_str(&self, atom_index: AtomIndex, s: &str) -> bool

Check if an atom equals the given string

Implementors§