Module 0xc0ded0c0::iterable_table_custom
module helpers::iterable_table_custom
This module is a wrapper around aptos_std::iterable_table
. This allows a quick change in data structure that Tortuga uses, in case iterable_table
is deemed to be not suitable at some point.
Copy use 0x1::option;
use 0xc0ded0c0::iterable_table;
Struct IterableTableCustom
The iterable wrapper around value, points to previous and next key if any.
Copy struct IterableTableCustom<K: copy, drop, store, V: store> has store
FieldsFunction new
Create a new custom iterable table
Copy public fun new<K: copy, drop, store, V: store>(): iterable_table_custom::IterableTableCustom<K, V>
Implementation
Copy public fun new<K: copy + store + drop, V: store>(): IterableTableCustom<K, V> {
IterableTableCustom {
data: iterable_table::new<K, V>(),
}
}
Function destroy_empty
Destroy a table. The table must be empty to succeed.
Copy public fun destroy_empty<K: copy, drop, store, V: store>(table: iterable_table_custom::IterableTableCustom<K, V>)
Implementation
Copy public fun destroy_empty<K: copy + store + drop, V: store>(table: IterableTableCustom<K, V>) {
let IterableTableCustom { data: data} = table;
iterable_table::destroy_empty(data);
}
Function add
Add a new entry to the table. Aborts if an entry for this key already exists.
Copy public fun add<K: copy, drop, store, V: store>(table: &mut iterable_table_custom::IterableTableCustom<K, V>, key: K, val: V)
Implementation
Copy public fun add<K: copy + store + drop, V: store>(table: &mut IterableTableCustom<K, V>, key: K, val: V) {
iterable_table::add(&mut table.data, key, val);
}
Function remove
Remove from table
and return the value which key
maps to. Aborts if there is no entry for key
.
Copy public fun remove<K: copy, drop, store, V: store>(table: &mut iterable_table_custom::IterableTableCustom<K, V>, key: K): V
Implementation
Copy public fun remove<K: copy + store + drop, V: store>(table: &mut IterableTableCustom<K, V>, key: K): V {
iterable_table::remove(&mut table.data, key)
}
Function borrow
Acquire an immutable reference to the value which key
maps to. Aborts if there is no entry for key
.
Copy public fun borrow<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>, key: K): &V
Implementation
Copy public fun borrow<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>, key: K): &V {
iterable_table::borrow(&table.data, key)
}
Function borrow_mut
Acquire a mutable reference to the value which key
maps to. Aborts if there is no entry for key
.
Copy public fun borrow_mut<K: copy, drop, store, V: store>(table: &mut iterable_table_custom::IterableTableCustom<K, V>, key: K): &mut V
Implementation
Copy public fun borrow_mut<K: copy + store + drop, V: store>(table: &mut IterableTableCustom<K, V>, key: K): &mut V {
iterable_table::borrow_mut(&mut table.data, key)
}
Function length
Returns the length of the table, i.e. the number of entries.
Copy public fun length<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>): u64
Implementation
Copy public fun length<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>): u64 {
iterable_table::length(&table.data)
}
Function empty
Returns true if this table is empty.
Copy public fun empty<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>): bool
Implementation
Copy public fun empty<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>): bool {
iterable_table::empty(&table.data)
}
Function contains
Returns true iff table
contains an entry for key
.
Copy public fun contains<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>, key: K): bool
Implementation
Copy public fun contains<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>, key: K): bool {
iterable_table::contains(&table.data, key)
}
Function head_key
Iterable API. Returns the key of the head for iteration.
Copy public fun head_key<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>): option::Option<K>
Implementation
Copy public fun head_key<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>): Option<K> {
iterable_table::head_key(&table.data)
}
Function tail_key
Returns the key of the tail for iteration.
Copy public fun tail_key<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>): option::Option<K>
Implementation
Copy public fun tail_key<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>): Option<K> {
iterable_table::tail_key(&table.data)
}
Function borrow_iter
Acquire an immutable reference to the IterableValue which key
maps to. Aborts if there is no entry for key
.
Copy public fun borrow_iter<K: copy, drop, store, V: store>(table: &iterable_table_custom::IterableTableCustom<K, V>, key: K): (&V, option::Option<K>, option::Option<K>)
Implementation
Copy public fun borrow_iter<K: copy + store + drop, V: store>(table: &IterableTableCustom<K, V>, key: K): (&V, Option<K>, Option<K>) {
iterable_table::borrow_iter(&table.data, key)
}
Function borrow_iter_mut
Acquire a mutable reference to the value and previous/next key which key
maps to. Aborts if there is no entry for key
.
Copy public fun borrow_iter_mut<K: copy, drop, store, V: store>(table: &mut iterable_table_custom::IterableTableCustom<K, V>, key: K): (&mut V, option::Option<K>, option::Option<K>)
Implementation
Copy public fun borrow_iter_mut<K: copy + store + drop, V: store>(table: &mut IterableTableCustom<K, V>, key: K): (&mut V, Option<K>, Option<K>) {
iterable_table::borrow_iter_mut(&mut table.data, key)
}
Function remove_iter
Remove from table
and return the value and previous/next key which key
maps to. Aborts if there is no entry for key
.
Copy public fun remove_iter<K: copy, drop, store, V: store>(table: &mut iterable_table_custom::IterableTableCustom<K, V>, key: K): (V, option::Option<K>, option::Option<K>)
Implementation
Copy public fun remove_iter<K: copy + store + drop, V: store>(table: &mut IterableTableCustom<K, V>, key: K): (V, Option<K>, Option<K>) {
iterable_table::remove_iter(&mut table.data, key)
}
Function append
Remove all items from v2 and append to v1.
Copy public fun append<K: copy, drop, store, V: store>(v1: &mut iterable_table_custom::IterableTableCustom<K, V>, v2: &mut iterable_table_custom::IterableTableCustom<K, V>)
Implementation
Copy public fun append<K: copy + store + drop, V: store>(v1: &mut IterableTableCustom<K, V>, v2: &mut IterableTableCustom<K, V>) {
iterable_table::append(&mut v1.data, &mut v2.data);
}