Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

alexandria_data_structures

Fully qualified path: alexandria_data_structures

Modules

array_ext
bit_array
byte_appender
byte_array_ext
byte_reader
queue
span_ext
stackStack implementation….
vec

Modules

Modules

array_ext
bit_array
byte_appender
byte_array_ext
byte_reader
queue
span_ext
stackStack implementation….
vec

array_ext

Fully qualified path: alexandria_data_structures::array_ext

Traits

Traits

Traits

ArrayTraitExt

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt

pub trait ArrayTraitExt<T, +Clone<T>, +Drop<T>>

Trait functions

append_all

Moves all the elements of other into self, leaving other empty.

Arguments

  • self - The array to append elements to
  • other - The array to move elements from

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::append_all

fn append_all(ref self: Array<T>, ref other: Array<T>)

extend_from_span

Clones and appends all the elements of other into self.

Arguments

  • self - The array to extend
  • other - The span containing elements to clone and append

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::extend_from_span

fn extend_from_span(ref self: Array<T>, other: Span<T>)

pop_front_n

Removes up to n elements from the front of self and returns them in a new array.

Arguments

  • self - The array to remove elements from
  • n - The maximum number of elements to remove

Returns

  • Array<T> - New array containing the removed elements

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::pop_front_n

fn pop_front_n(ref self: Array<T>, n: u32) -> Array<T>

remove_front_n

Removes up to n elements from the front of self.

Arguments

  • self - The array to remove elements from
  • n - The maximum number of elements to remove

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::remove_front_n

fn remove_front_n(ref self: Array<T>, n: u32)

concat

Clones and appends all the elements of self and then other in a single new array.

Arguments

  • self - The first array to concatenate
  • other - The second array to concatenate

Returns

  • Array<T> - New array containing elements from both arrays

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::concat

fn concat(self: @Array<T>, other: @Array<T>) -> Array<T>

reversed

Return a new array containing the elements of self in a reversed order.

Arguments

  • self - The array to reverse

Returns

  • Array<T> - New array with elements in reverse order

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::reversed

fn reversed(self: @Array<T>) -> Array<T>

contains

Returns true if the array contains an element with the given value.

Arguments

  • self - The array to search
  • item - The item to search for

Returns

  • bool - True if the item is found, false otherwise

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::contains

fn contains<+PartialEq<T>>(self: @Array<T>, item: @T) -> bool

position

Searches for an element in the array, returning its index.

Arguments

  • self - The array to search
  • item - The item to find the position of

Returns

  • Option<usize> - Some(index) if found, None otherwise

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::position

fn position<+PartialEq<T>>(self: @Array<T>, item: @T) -> Option<u32>

occurrences

Returns the number of elements in the array with the given value.

Arguments

  • self - The array to search
  • item - The item to count occurrences of

Returns

  • usize - The number of times the item appears

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::occurrences

fn occurrences<+PartialEq<T>>(self: @Array<T>, item: @T) -> u32

min

Returns the minimum element of an array.

Arguments

  • self - The array to find the minimum in

Returns

  • Option<T> - Some(min_element) if array is not empty, None otherwise

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::min

fn min<+PartialOrd<@T>>(self: @Array<T>) -> Option<T>

min_position

Returns the position of the minimum element of an array.

Arguments

  • self - The array to find the minimum position in

Returns

  • Option<usize> - Some(index) of minimum element, None if array is empty

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::min_position

fn min_position<+PartialOrd<@T>>(self: @Array<T>) -> Option<u32>

max

Returns the maximum element of an array.

Arguments

  • self - The array to find the maximum in

Returns

  • Option<T> - Some(max_element) if array is not empty, None otherwise

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::max

fn max<+PartialOrd<@T>>(self: @Array<T>) -> Option<T>

max_position

Returns the position of the maximum element of an array.

Arguments

  • self - The array to find the maximum position in

Returns

  • Option<usize> - Some(index) of maximum element, None if array is empty

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::max_position

fn max_position<+PartialOrd<@T>>(self: @Array<T>) -> Option<u32>

dedup

Returns a new array, cloned from self but removes consecutive repeated elements. If the array is sorted, this removes all duplicates.

Arguments

  • self - The array to deduplicate

Returns

  • Array<T> - New array with consecutive duplicates removed

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::dedup

fn dedup<+PartialEq<T>>(self: @Array<T>) -> Array<T>

unique

Returns a new array, cloned from self but without any duplicate.

Arguments

  • self - The array to remove duplicates from

Returns

  • Array<T> - New array with all duplicates removed

Fully qualified path: alexandria_data_structures::array_ext::ArrayTraitExt::unique

fn unique<+PartialEq<T>>(self: @Array<T>) -> Array<T>

bit_array

Fully qualified path: alexandria_data_structures::bit_array

Free functions

shift_bitReturns the bit value at the specified position (power of 2)…
one_shift_left_bytes_felt252Shifts 1 left by the specified number of bytes for felt252 values…
one_shift_left_bytes_u128Shifts 1 left by the specified number of bytes for u128 values…

Structs

Traits

Free functions

Free functions

shift_bitReturns the bit value at the specified position (power of 2)…
one_shift_left_bytes_felt252Shifts 1 left by the specified number of bytes for felt252 values…
one_shift_left_bytes_u128Shifts 1 left by the specified number of bytes for u128 values…

shift_bit

Returns the bit value at the specified position (power of 2)

Arguments

  • number - The bit position (0-7)

Returns

  • u8 - The bit value (1 shifted left by position)

Fully qualified path: alexandria_data_structures::bit_array::shift_bit

pub fn shift_bit(number: u32) -> u8

one_shift_left_bytes_felt252

Shifts 1 left by the specified number of bytes for felt252 values

Arguments

  • n_bytes - The number of bytes to shift left

Returns

  • felt252 - The result of 1 shifted left by n_bytes * 8 bits

Fully qualified path: alexandria_data_structures::bit_array::one_shift_left_bytes_felt252

pub fn one_shift_left_bytes_felt252(n_bytes: u32) -> felt252

one_shift_left_bytes_u128

Shifts 1 left by the specified number of bytes for u128 values

Arguments

  • n_bytes - The number of bytes to shift left

Returns

  • u128 - The result of 1 shifted left by n_bytes * 8 bits

Fully qualified path: alexandria_data_structures::bit_array::one_shift_left_bytes_u128

pub fn one_shift_left_bytes_u128(n_bytes: u32) -> u128

Structs

Structs

BitArray

Fully qualified path: alexandria_data_structures::bit_array::BitArray

[derive(Clone, Drop)]
pub struct BitArray { /* private fields */ }

Traits

Traits

BitArrayTrait

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait

pub trait BitArrayTrait

Trait functions

new

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::new

fn new(data: Array<bytes31>, current: felt252, read_pos: u32, write_pos: u32) -> BitArray

current

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::current

fn current(self: @BitArray) -> felt252

data

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::data

fn data(self: BitArray) -> Array<bytes31>

append_bit

Appends a single bit to the BitArray

Arguments

  • bit - either true or false, representing a single bit to be appended

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::append_bit

fn append_bit(ref self: BitArray, bit: bool)

at

Reads a single bit from the array

Arguments

  • index - the index into the array to read

Returns

  • Option<bool> - if the index is found, the stored bool is returned

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::at

fn at(self: @BitArray, index: u32) -> Option<bool>

len

The current length of the BitArray

Returns

  • usize - length in bits of the BitArray

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::len

fn len(self: @BitArray) -> u32

pop_front

Returns and removes the first element of the BitArray

Returns

  • Option<bool> - If the array is non-empty, a bool is removed from the front and returned

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::pop_front

fn pop_front(ref self: BitArray) -> Option<bool>

read_word_be

Reads a single word of the specified length up to 248 bits in big endian bit representation

Arguments

  • length - The bit length of the word to read, max 248

Returns

  • Option<felt252> - If there are length bits remaining, the word is returned as felt252

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::read_word_be

fn read_word_be(ref self: BitArray, length: u32) -> Option<felt252>

read_word_be_u256

Reads a single word of the specified length up to 256 bits in big endian representation. For words shorter than (or equal to) 248 bits use read_word_be(...) instead.

Arguments

  • length - The bit length of the word to read, max 256

Returns

  • Option<u256> - If there are length bits remaining, the word is returned as u256

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::read_word_be_u256

fn read_word_be_u256(ref self: BitArray, length: u32) -> Option<u256>

read_word_be_u512

Reads a single word of the specified length up to 512 bits in big endian representation. For words shorter than (or equal to) 256 bits consider the other read calls instead.

Arguments

  • length - The bit length of the word to read, max 512

Returns

  • Option<u512> - If there are length bits remaining, the word is returned as u512

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::read_word_be_u512

fn read_word_be_u512(ref self: BitArray, length: u32) -> Option<u512>

write_word_be

Writes the bits of the specified length from word onto the BitArray in big endian representation

Arguments

  • word - The value to store onto the bit array of type felt252
  • length - The length of the word in bits, maximum 248

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::write_word_be

fn write_word_be(ref self: BitArray, word: felt252, length: u32)

write_word_be_u256

Writes the bits of the specified length from word onto the BitArray in big endian representation

Arguments

  • word - The value to store onto the bit array of type u256
  • length - The length of the word in bits, maximum 256

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::write_word_be_u256

fn write_word_be_u256(ref self: BitArray, word: u256, length: u32)

write_word_be_u512

Writes the bits of the specified length from word onto the BitArray in big endian representation

Arguments

  • word - The value to store onto the bit array of type u512
  • length - The length of the word in bits, maximum 512

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::write_word_be_u512

fn write_word_be_u512(ref self: BitArray, word: u512, length: u32)

read_word_le

Reads a single word of the specified length up to 248 bits in little endian bit representation

Arguments

  • length - The bit length of the word to read, max 248

Returns

  • Option<felt252> - If there are length bits remaining, the word is returned as felt252

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::read_word_le

fn read_word_le(ref self: BitArray, length: u32) -> Option<felt252>

read_word_le_u256

Reads a single word of the specified length up to 256 bits in little endian representation. For words shorter than (or equal to) 248 bits use read_word_be(...) instead.

Arguments

  • length - The bit length of the word to read, max 256

Returns

  • Option<u256> - If there are length bits remaining, the word is returned as u256

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::read_word_le_u256

fn read_word_le_u256(ref self: BitArray, length: u32) -> Option<u256>

read_word_le_u512

Reads a single word of the specified length up to 512 bits in little endian representation. For words shorter than (or equal to) 256 bits consider the other read calls instead.

Arguments

  • length - The bit length of the word to read, max 512

Returns

  • Option<u512> - If there are length bits remaining, the word is returned as u512

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::read_word_le_u512

fn read_word_le_u512(ref self: BitArray, length: u32) -> Option<u512>

write_word_le

Writes the bits of the specified length from word onto the BitArray in little endian representation

Arguments

  • word - The value to store onto the bit array of type felt252
  • length - The length of the word in bits, maximum 248

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::write_word_le

fn write_word_le(ref self: BitArray, word: felt252, length: u32)

write_word_le_u256

Writes the bits of the specified length from word onto the BitArray in little endian representation

Arguments

  • word - The value to store onto the bit array of type u256
  • length - The length of the word in bits, maximum 256

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::write_word_le_u256

fn write_word_le_u256(ref self: BitArray, word: u256, length: u32)

write_word_le_u512

Writes the bits of the specified length from word onto the BitArray in little endian representation

Arguments

  • word - The value to store onto the bit array of type u512
  • length - The length of the word in bits, maximum 512

Fully qualified path: alexandria_data_structures::bit_array::BitArrayTrait::write_word_le_u512

fn write_word_le_u512(ref self: BitArray, word: u512, length: u32)

byte_appender

Fully qualified path: alexandria_data_structures::byte_appender

Free functions

reversingReverses the byte order of a value by repeatedly dividing and reconstructing. The step parameter MUST be a power of 2 (e.g., 2, 256, 65536)….
reversing_partial_resultReverses byte order with an existing partial result. The step parameter MUST be a power of 2 (e.g., 2, 256, 65536). Using a non-power-of-2 step will produce incorrect results and data corruption….

Traits

ByteAppenderSupportTraitGeneric support trait for appending signed and unsigned integers onto byte storage. There are two functions, one for each of big and little endian byte order due to…
ByteAppender

Free functions

Free functions

reversingReverses the byte order of a value by repeatedly dividing and reconstructing. The step parameter MUST be a power of 2 (e.g., 2, 256, 65536)….
reversing_partial_resultReverses byte order with an existing partial result. The step parameter MUST be a power of 2 (e.g., 2, 256, 65536). Using a non-power-of-2 step will produce incorrect results and data corruption….

reversing

Reverses the byte order of a value by repeatedly dividing and reconstructing.

The step parameter MUST be a power of 2 (e.g., 2, 256, 65536). Using a non-power-of-2 step will produce incorrect results and data corruption. Valid steps: 2 (bits), 256 (bytes), 65536 (u16 words), etc.

Arguments

  • word - The value to reverse
  • size - The number of steps to perform
  • step - The step size for division/reconstruction (MUST be a power of 2)

Returns

  • (T, T) - Tuple containing the reversed value and remaining value

Panics

  • If step is not a power of 2 (runtime check performed)

Fully qualified path: alexandria_data_structures::byte_appender::reversing

pub fn reversing<
    T,
    +Copy<T>,
    +Zero<T>,
    +TryInto<T, NonZero<T>>,
    +Into<T, u128>,
    +TryInto<u128, T>,
    +DivRem<T>,
    +Drop<T>,
    +MulAssign<T, T>,
    +Rem<T>,
    +AddAssign<T, T>,
>(
    word: T, size: u32, step: T,
) -> (T, T)

reversing_partial_result

Reverses byte order with an existing partial result.

The step parameter MUST be a power of 2 (e.g., 2, 256, 65536). Using a non-power-of-2 step will produce incorrect results and data corruption. Valid steps: 2 (bits), 256 (bytes), 65536 (u16 words), etc.

Arguments

  • word - The value to reverse
  • onto - The existing partial result to build upon
  • size - The number of steps to perform
  • step - The step size for division/reconstruction (MUST be a power of 2)

Returns

  • (T, T) - Tuple containing the final reversed value and remaining value

Panics

  • If step is not a power of 2 (runtime check performed)

Fully qualified path: alexandria_data_structures::byte_appender::reversing_partial_result

pub fn reversing_partial_result<
    T,
    +Copy<T>,
    +DivRem<T>,
    +TryInto<T, NonZero<T>>,
    +Into<T, u128>,
    +TryInto<u128, T>,
    +Drop<T>,
    +MulAssign<T, T>,
    +Rem<T>,
    +AddAssign<T, T>,
>(
    mut word: T, mut onto: T, size: u32, step: T,
) -> (T, T)

Traits

Traits

ByteAppenderSupportTraitGeneric support trait for appending signed and unsigned integers onto byte storage. There are two functions, one for each of big and little endian byte order due to…
ByteAppender

ByteAppenderSupportTrait

Generic support trait for appending signed and unsigned integers onto byte storage. There are two functions, one for each of big and little endian byte order due to performance considerations. The byte reversal could be used in the naïve case when only one implementation is worthwhile.

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppenderSupportTrait

pub trait ByteAppenderSupportTrait<T>

Trait functions

append_bytes_be

Appends bytes data of size count ordered in big endian

Arguments

  • bytes - big endian ordered bytes to append
  • count - number of bytes from input to append

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppenderSupportTrait::append_bytes_be

fn append_bytes_be(ref self: T, bytes: felt252, count: u32)

append_bytes_le

Appends bytes data of size count ordered in little endian

Arguments

  • bytes - little endian ordered bytes to append
  • count - number of bytes from input to append

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppenderSupportTrait::append_bytes_le

fn append_bytes_le(ref self: T, bytes: felt252, count: u32)

ByteAppender

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender

pub trait ByteAppender<T>

Trait functions

append_u16

Appends an unsigned 16 bit integer encoded in big endian

Arguments

  • word - a 16 bit unsigned integer typed as u16

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u16

fn append_u16(ref self: T, word: u16)

append_u16_le

Appends an unsigned 16 bit integer encoded in little endian

Arguments

  • word - a 16 bit unsigned integer typed as u16

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u16_le

fn append_u16_le(ref self: T, word: u16)

append_u32

Appends an unsigned 32 bit integer encoded in big endian

Arguments

  • word - a 32 bit unsigned integer typed as u32

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u32

fn append_u32(ref self: T, word: u32)

append_u32_le

Appends an unsigned 32 bit integer encoded in little endian

Arguments

  • word - a 32 bit unsigned integer typed as u32

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u32_le

fn append_u32_le(ref self: T, word: u32)

append_u64

Appends an unsigned 64 bit integer encoded in big endian

Arguments

  • word - a 64 bit unsigned integer typed as u64

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u64

fn append_u64(ref self: T, word: u64)

append_u64_le

Appends an unsigned 64 bit integer encoded in little endian

Arguments

  • word - a 64 bit unsigned integer typed as u64

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u64_le

fn append_u64_le(ref self: T, word: u64)

append_u128

Appends an unsigned 128 bit integer encoded in big endian

Arguments

  • word - a 128 bit unsigned integer typed as u128

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u128

fn append_u128(ref self: T, word: u128)

append_u128_le

Appends an unsigned 128 bit integer encoded in little endian

Arguments

  • word - a 128 bit unsigned integer typed as u128

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u128_le

fn append_u128_le(ref self: T, word: u128)

append_u256

Appends an unsigned 256 bit integer encoded in big endian

Arguments

  • word - a 256 bit unsigned integer typed as u256

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u256

fn append_u256(ref self: T, word: u256)

append_u256_le

Appends an unsigned 256 bit integer encoded in little endian

Arguments

  • word - a 256 bit unsigned integer typed as u256

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u256_le

fn append_u256_le(ref self: T, word: u256)

append_u512

Appends an unsigned 512 bit integer encoded in big endian

Arguments

  • word - a 512 bit unsigned integer typed as u32

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u512

fn append_u512(ref self: T, word: u512)

append_u512_le

Appends an unsigned 512 bit integer encoded in little endian

Arguments

  • word - a 512 bit unsigned integer typed as u32

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_u512_le

fn append_u512_le(ref self: T, word: u512)

append_i8

Appends a signed 8 bit integer

Arguments

  • word - an 8 bit signed integer typed as i8

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i8

fn append_i8(ref self: T, word: i8)

append_i16

Appends a signed 16 bit integer encoded in big endian

Arguments

  • word - a 16 bit signed integer typed as i16

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i16

fn append_i16(ref self: T, word: i16)

append_i16_le

Appends a signed 16 bit integer encoded in little endian

Arguments

  • word - a 16 bit signed integer typed as i16

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i16_le

fn append_i16_le(ref self: T, word: i16)

append_i32

Appends a signed 32 bit integer encoded in big endian

Arguments

  • word - a 32 bit signed integer typed as i32

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i32

fn append_i32(ref self: T, word: i32)

append_i32_le

Appends a signed 32 bit integer encoded in little endian

Arguments

  • word - a 32 bit signed integer typed as i32

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i32_le

fn append_i32_le(ref self: T, word: i32)

append_i64

Appends a signed 64 bit integer encoded in big endian

Arguments

  • word - a 64 bit signed integer typed as i64

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i64

fn append_i64(ref self: T, word: i64)

append_i64_le

Appends a signed 64 bit integer encoded in little endian

Arguments

  • word - a 64 bit signed integer typed as i64

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i64_le

fn append_i64_le(ref self: T, word: i64)

append_i128

Appends a signed 128 bit integer encoded in big endian

Arguments

  • word - a 128 bit signed integer typed as i128

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i128

fn append_i128(ref self: T, word: i128)

append_i128_le

Appends a signed 128 bit integer encoded in little endian

Arguments

  • word - a 128 bit signed integer typed as i128

Fully qualified path: alexandria_data_structures::byte_appender::ByteAppender::append_i128_le

fn append_i128_le(ref self: T, word: i128)

byte_array_ext

Fully qualified path: alexandria_data_structures::byte_array_ext

Impls

Impls

Impls

SpanU8IntoBytearray

Fully qualified path: alexandria_data_structures::byte_array_ext::SpanU8IntoBytearray

pub impl SpanU8IntoBytearray of Into<Span<u8>, ByteArray>;

Impl functions

into

Fully qualified path: alexandria_data_structures::byte_array_ext::SpanU8IntoBytearray::into

fn into(self: Span<u8>) -> ByteArray

ByteArrayIntoArrayU8

Fully qualified path: alexandria_data_structures::byte_array_ext::ByteArrayIntoArrayU8

pub impl ByteArrayIntoArrayU8 of Into<ByteArray, Array<u8>>;

Impl functions

into

Fully qualified path: alexandria_data_structures::byte_array_ext::ByteArrayIntoArrayU8::into

fn into(self: ByteArray) -> Array<u8>

byte_reader

Fully qualified path: alexandria_data_structures::byte_reader

Structs

Traits

Structs

Structs

ByteReaderState

Fully qualified path: alexandria_data_structures::byte_reader::ByteReaderState

[derive(Clone, Drop)]
pub struct ByteReaderState<T> {
    pub data: @T,
    /* private fields */
}

Members

data

Fully qualified path: alexandria_data_structures::byte_reader::ByteReaderState::data

pub data: @T

Traits

Traits

ByteReader

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader

pub trait ByteReader<T>

Trait functions

reader

Wraps the array of bytes in a ByteReader for sequential consumption of integers and/or bytes

Returns

  • ByteReader - The reader struct wrapping a read-only snapshot of this ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::reader

fn reader(self: @T) -> ByteReaderState<T>

remaining

Checks that there are enough remaining bytes available

Arguments

  • at - the start index position of the byte data
  • count - the number of bytes required

Returns

  • bool - true when there are count bytes remaining, false otherwise.

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::remaining

fn remaining(self: @T, at: u32, count: u32) -> bool

word_u16

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u16> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u16

fn word_u16(self: @T, offset: u32) -> Option<u16>

word_u16_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u16> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u16_le

fn word_u16_le(self: @T, offset: u32) -> Option<u16>

word_u32

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u32> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u32

fn word_u32(self: @T, offset: u32) -> Option<u32>

word_u32_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u32> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u32_le

fn word_u32_le(self: @T, offset: u32) -> Option<u32>

word_u64

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u64> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u64

fn word_u64(self: @T, offset: u32) -> Option<u64>

word_u64_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u64> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u64_le

fn word_u64_le(self: @T, offset: u32) -> Option<u64>

word_u128

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u128> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u128

fn word_u128(self: @T, offset: u32) -> Option<u128>

word_u128_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u128> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::word_u128_le

fn word_u128_le(self: @T, offset: u32) -> Option<u128>

read_u8

Reads a u8 unsigned integer

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u8

fn read_u8(ref self: ByteReaderState<T>) -> Option<u8>

read_u16

Reads a u16 unsigned integer in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u16

fn read_u16(ref self: ByteReaderState<T>) -> Option<u16>

read_u16_le

Reads a u16 unsigned integer in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u16_le

fn read_u16_le(ref self: ByteReaderState<T>) -> Option<u16>

read_u32

Reads a u32 unsigned integer in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u32

fn read_u32(ref self: ByteReaderState<T>) -> Option<u32>

read_u32_le

Reads a u32 unsigned integer in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u32_le

fn read_u32_le(ref self: ByteReaderState<T>) -> Option<u32>

read_u64

Reads a u64 unsigned integer in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u64

fn read_u64(ref self: ByteReaderState<T>) -> Option<u64>

read_u64_le

Reads a u64 unsigned integer in little endian byte order

Returns

Option<u64> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u64_le

fn read_u64_le(ref self: ByteReaderState<T>) -> Option<u64>

read_u128

Reads a u128 unsigned integer in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u128

fn read_u128(ref self: ByteReaderState<T>) -> Option<u128>

read_u128_le

Reads a u128 unsigned integer in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u128_le

fn read_u128_le(ref self: ByteReaderState<T>) -> Option<u128>

read_u256

Reads a u256 unsigned integer in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u256

fn read_u256(ref self: ByteReaderState<T>) -> Option<u256>

read_u256_le

Reads a u256 unsigned integer in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u256_le

fn read_u256_le(ref self: ByteReaderState<T>) -> Option<u256>

read_u512

Reads a u512 unsigned integer in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u512

fn read_u512(ref self: ByteReaderState<T>) -> Option<u512>

read_u512_le

Reads a u512 unsigned integer in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_u512_le

fn read_u512_le(ref self: ByteReaderState<T>) -> Option<u512>

read_i8

Reads an i8 signed integer in two’s complement encoding from the ByteArray

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i8

fn read_i8(ref self: ByteReaderState<T>) -> Option<i8>

read_i16

Reads an i16 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i16

fn read_i16(ref self: ByteReaderState<T>) -> Option<i16>

read_i16_le

Reads an i16 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i16_le

fn read_i16_le(ref self: ByteReaderState<T>) -> Option<i16>

read_i32

Reads an i32 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i32

fn read_i32(ref self: ByteReaderState<T>) -> Option<i32>

read_i32_le

Reads an i32 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i32_le

fn read_i32_le(ref self: ByteReaderState<T>) -> Option<i32>

read_i64

Reads an i64 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i64

fn read_i64(ref self: ByteReaderState<T>) -> Option<i64>

read_i64_le

Reads an i64 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i64_le

fn read_i64_le(ref self: ByteReaderState<T>) -> Option<i64>

read_i128

Reads an i128 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i128

fn read_i128(ref self: ByteReaderState<T>) -> Option<i128>

read_i128_le

Reads an i128 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

*Option` - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::read_i128_le

fn read_i128_le(ref self: ByteReaderState<T>) -> Option<i128>

len

Remaining length count relative to what has already been consume/read

Returns

*usize` - count number of bytes remaining

Fully qualified path: alexandria_data_structures::byte_reader::ByteReader::len

fn len(self: @ByteReaderState<T>) -> u32

queue

Fully qualified path: alexandria_data_structures::queue

Structs

Queue

Traits

Structs

Structs

Queue

Queue

Fully qualified path: alexandria_data_structures::queue::Queue

pub struct Queue<T> { /* private fields */ }

Traits

Traits

QueueTrait

Fully qualified path: alexandria_data_structures::queue::QueueTrait

pub trait QueueTrait<T>

Trait functions

new

Creates a new empty queue

Returns

  • Queue<T> - A new empty queue instance

Fully qualified path: alexandria_data_structures::queue::QueueTrait::new

fn new() -> Queue<T>

enqueue

Adds an element to the back of the queue

Arguments

  • self - The queue to add the element to
  • value - The element to add

Fully qualified path: alexandria_data_structures::queue::QueueTrait::enqueue

fn enqueue(ref self: Queue<T>, value: T)

dequeue

Removes and returns the front element from the queue

Arguments

  • self - The queue to remove the element from

Returns

  • Option<T> - Some(element) if queue is not empty, None otherwise

Fully qualified path: alexandria_data_structures::queue::QueueTrait::dequeue

fn dequeue(ref self: Queue<T>) -> Option<T>

peek_front

Returns a reference to the front element without removing it

Arguments

  • self - The queue to peek into

Returns

  • Option<Box<@T>> - Some(reference) to front element if queue is not empty, None otherwise

Fully qualified path: alexandria_data_structures::queue::QueueTrait::peek_front

fn peek_front(self: @Queue<T>) -> Option<Box<@T>>

len

Returns the number of elements in the queue

Arguments

  • self - The queue to get the length of

Returns

  • usize - The number of elements in the queue

Fully qualified path: alexandria_data_structures::queue::QueueTrait::len

fn len(self: @Queue<T>) -> u32

is_empty

Checks if the queue is empty

Arguments

  • self - The queue to check

Returns

  • bool - True if the queue contains no elements, false otherwise

Fully qualified path: alexandria_data_structures::queue::QueueTrait::is_empty

fn is_empty(self: @Queue<T>) -> bool

span_ext

Fully qualified path: alexandria_data_structures::span_ext

Traits

Traits

Traits

SpanTraitExt

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt

pub trait SpanTraitExt<T, +Clone<T>, +Drop<T>>

Trait functions

pop_front_n

Removes up to n elements from the front of self and returns them in a new span.

Arguments

  • self - The span to modify
  • n - The number of elements to remove from the front

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::pop_front_n

fn pop_front_n(ref self: Span<T>, n: u32) -> Span<T>

pop_back_n

Removes up to n elements from the back of self and returns them in a new span.

Arguments

  • self - The span to modify
  • n - The number of elements to remove from the back

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::pop_back_n

fn pop_back_n(ref self: Span<T>, n: u32) -> Span<T>

remove_front_n

Removes up to n elements from the front of self.

Arguments

  • self - The span to modify
  • n - The number of elements to remove from the front

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::remove_front_n

fn remove_front_n(ref self: Span<T>, n: u32)

remove_back_n

Removes up to n elements from the back of self.

Arguments

  • self - The span to modify
  • n - The number of elements to remove from the back

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::remove_back_n

fn remove_back_n(ref self: Span<T>, n: u32)

concat

Clones and appends all the elements of self and then other in a single new array.

Arguments

  • self - The first span to concatenate
  • other - The second span to concatenate

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::concat

fn concat(self: Span<T>, other: Span<T>) -> Array<T>

reversed

Return a new array containing the elements of self in a reversed order.

Arguments

  • self - The span to reverse

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::reversed

fn reversed(self: Span<T>) -> Array<T>

contains

Returns true if the span contains an element with the given value.

Arguments

  • self - The span to search
  • item - The value to search for

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::contains

fn contains<+PartialEq<T>>(self: Span<T>, item: @T) -> bool

position

Searches for an element the span, returning its index.

Arguments

  • self - The span to search
  • item - The value to search for

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::position

fn position<+PartialEq<T>>(self: Span<T>, item: @T) -> Option<u32>

occurrences

Returns the number of elements in the span with the given value.

Arguments

  • self - The span to search
  • item - The value to count

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::occurrences

fn occurrences<+PartialEq<T>>(self: Span<T>, item: @T) -> u32

min

Returns the minimum element of a span.

Arguments

  • self - The span to find the minimum value in

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::min

fn min<+PartialOrd<@T>>(self: Span<T>) -> Option<T>

min_position

Returns the position of the minimum element of a span.

Arguments

  • self - The span to find the minimum position in

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::min_position

fn min_position<+PartialOrd<@T>>(self: Span<T>) -> Option<u32>

max

Returns the maximum element of a span.

Arguments

  • self - The span to find the maximum value in

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::max

fn max<+PartialOrd<@T>>(self: Span<T>) -> Option<T>

max_position

Returns the position of the maximum element of a span.

Arguments

  • self - The span to find the maximum position in

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::max_position

fn max_position<+PartialOrd<@T>>(self: Span<T>) -> Option<u32>

dedup

Returns a new array, cloned from self but removes consecutive repeated elements. If the span is sorted, this removes all duplicates.

Arguments

  • self - The span to deduplicate

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::dedup

fn dedup<+PartialEq<T>>(self: Span<T>) -> Array<T>

unique

Returns a new array, cloned from self but without any duplicate.

Arguments

  • self - The span to get unique elements from

Fully qualified path: alexandria_data_structures::span_ext::SpanTraitExt::unique

fn unique<+PartialEq<T>>(self: Span<T>) -> Array<T>

stack

Stack implementation.

Example

use alexandria::data_structures::stack::StackTrait;

// Create a new stack instance.
let mut stack = StackTrait::new();
// Create an item and push it to the stack.
let mut item:u256 = 1.into();
stack.push(item);
Remove the item from the stack;
let item = stack.pop();

Fully qualified path: alexandria_data_structures::stack

Structs

Traits

Structs

Structs

Felt252Stack

Fully qualified path: alexandria_data_structures::stack::Felt252Stack

pub struct Felt252Stack<T> { /* private fields */ }

NullableStack

Fully qualified path: alexandria_data_structures::stack::NullableStack

pub struct NullableStack<T> { /* private fields */ }

Traits

Traits

StackTrait

Fully qualified path: alexandria_data_structures::stack::StackTrait

pub trait StackTrait<S, T>

Trait functions

new

Creates a new Stack instance.

Fully qualified path: alexandria_data_structures::stack::StackTrait::new

fn new() -> S

push

Pushes a new value onto the stack.

Arguments

  • self - The stack to push the value onto
  • value - The value to push onto the stack

Fully qualified path: alexandria_data_structures::stack::StackTrait::push

fn push(ref self: S, value: T)

pop

Removes the last item from the stack and returns it, or None if the stack is empty.

Arguments

  • self - The stack to pop the item from

Fully qualified path: alexandria_data_structures::stack::StackTrait::pop

fn pop(ref self: S) -> Option<T>

peek

Returns the last item from the stack without removing it, or None if the stack is empty.

Arguments

  • self - The stack to peek at

Fully qualified path: alexandria_data_structures::stack::StackTrait::peek

fn peek(ref self: S) -> Option<T>

len

Returns the number of items in the stack.

Arguments

  • self - The stack to get the length of

Fully qualified path: alexandria_data_structures::stack::StackTrait::len

fn len(self: @S) -> u32

is_empty

Returns true if the stack is empty.

Arguments

  • self - The stack to check if it is empty

Fully qualified path: alexandria_data_structures::stack::StackTrait::is_empty

fn is_empty(self: @S) -> bool

vec

Fully qualified path: alexandria_data_structures::vec

Structs

Traits

Structs

Structs

Felt252Vec

Fully qualified path: alexandria_data_structures::vec::Felt252Vec

pub struct Felt252Vec<T> { /* private fields */ }

NullableVec

Fully qualified path: alexandria_data_structures::vec::NullableVec

pub struct NullableVec<T> { /* private fields */ }

Traits

Traits

VecTrait

Fully qualified path: alexandria_data_structures::vec::VecTrait

pub trait VecTrait<V, T>

Trait functions

new

Creates a new V instance.

Returns

  • V The new vec instance.

Fully qualified path: alexandria_data_structures::vec::VecTrait::new

fn new() -> V

get

Returns the item at the given index, or None if the index is out of bounds.

Arguments

  • self The vec instance.
  • index The index of the item to get.

Returns

  • Option The item at the given index, or None if the index is out of bounds.

Fully qualified path: alexandria_data_structures::vec::VecTrait::get

fn get(ref self: V, index: u32) -> Option<T>

at

Returns the item at the given index, or panics if the index is out of bounds.

Arguments

  • self The vec instance.
  • index The index of the item to get.

Returns

  • T The item at the given index.

Fully qualified path: alexandria_data_structures::vec::VecTrait::at

fn at(ref self: V, index: u32) -> T

push

Pushes a new item to the vec.

Arguments

  • self The vec instance.
  • value The value to push onto the vec.

Fully qualified path: alexandria_data_structures::vec::VecTrait::push

fn push(ref self: V, value: T)

set

Sets the item at the given index to the given value. Panics if the index is out of bounds.

Arguments

  • self The vec instance.
  • index The index of the item to set.
  • value The value to set the item to.

Fully qualified path: alexandria_data_structures::vec::VecTrait::set

fn set(ref self: V, index: u32, value: T)

len

Returns the length of the vec.

Arguments

  • self The vec instance.

Returns

  • usize The length of the vec.

Fully qualified path: alexandria_data_structures::vec::VecTrait::len

fn len(self: @V) -> u32