orx_linked_list/
variant.rs

1use crate::memory::{DoublyReclaimer, SinglyReclaimer};
2use core::marker::PhantomData;
3use orx_selfref_col::{MemoryReclaimer, RefsArray, RefsNone, RefsSingle, Variant};
4
5pub trait ListVariant: Variant {
6    type Reclaimer: MemoryReclaimer<Self>;
7}
8
9/// A self referential collection variant representing a singly linked list
10/// where nodes hold a reference to the next element, but not to the previous.
11pub struct Singly<T> {
12    p: PhantomData<T>,
13}
14
15impl<T> Variant for Singly<T> {
16    type Item = T;
17
18    type Prev = RefsNone;
19
20    type Next = RefsSingle<Self>;
21
22    type Ends = RefsSingle<Self>;
23}
24
25impl<T> ListVariant for Singly<T> {
26    type Reclaimer = SinglyReclaimer;
27}
28
29/// A self referential collection variant representing a doubly linked list
30/// where nodes hold a reference to the next element, and a reference to the previous.
31pub struct Doubly<T> {
32    p: PhantomData<T>,
33}
34
35impl<T> Variant for Doubly<T> {
36    type Item = T;
37
38    type Prev = RefsSingle<Self>;
39
40    type Next = RefsSingle<Self>;
41
42    type Ends = RefsArray<2, Self>;
43}
44
45impl<T> ListVariant for Doubly<T> {
46    type Reclaimer = DoublyReclaimer;
47}