platform_trees/lists/absolute_linked_list.rs
1use crate::LinkedList;
2use platform_num::LinkReference;
3
4/// Linked list with direct (absolute) access to the first and last
5/// elements and a size counter.
6///
7/// This is typically used when a single list instance owns its own
8/// head/tail/size metadata. For multiple lists sharing the same
9/// storage, see [`RelativeLinkedList`](super::RelativeLinkedList).
10pub trait AbsoluteLinkedList<T: LinkReference>: LinkedList<T> {
11 /// Returns the first element (head) of the list, or `T::from_byte(0)` if empty.
12 fn get_first(&self) -> T;
13
14 /// Returns the last element (tail) of the list, or `T::from_byte(0)` if empty.
15 fn get_last(&self) -> T;
16
17 /// Returns the number of elements in the list.
18 fn get_size(&self) -> T;
19
20 /// Sets the first element (head) of the list.
21 fn set_first(&mut self, element: T);
22
23 /// Sets the last element (tail) of the list.
24 fn set_last(&mut self, element: T);
25
26 /// Sets the size of the list.
27 fn set_size(&mut self, size: T);
28
29 /// Increments the list size by one.
30 fn inc_size(&mut self) {
31 self.set_size(self.get_size() + T::from_byte(1));
32 }
33
34 /// Decrements the list size by one.
35 fn dec_size(&mut self) {
36 self.set_size(self.get_size() - T::from_byte(1));
37 }
38}