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