Hello people,
I am trying to implement a doubly linked list by using arena allocation. So I want to save all the data in a Vec.
If I want to delete some Nodes, I want save their index in a another Vec, so I can fill the gap up by the next addition.
Currently I am stuck with the burrow checker during the implementation of the addNode() function.
here is the code:
struct DoublyLinkedList<T> {
Arena : Vec<ListE<T>>,
ArenaLastEntry : usize,
Gap : Vec<Option<usize>>,
GapLastEntry : usize,
Head : Option<usize>,
Tail : Option<usize>
}
enum ListE<T> {
Null,
Node{Value: T, Next : usize, Prev : usize}
}
impl<T> ListE<T> {
fn null() -> ListE<T> {
ListE::Null
}
fn node(value : T, next : usize, prev : usize) -> ListE<T> {
ListE::Node{
Value : value,
Next : next,
Prev : prev
}
}
}
impl<T> DoublyLinkedList<T> {
fn new() -> DoublyLinkedList<T> {
DoublyLinkedList{
Arena : Vec::new(),
ArenaLastEntry : 0,
Gap : Vec::new(),
GapLastEntry : 0,
Head : Option::None,
Tail : Option::None
}
}
fn addNode(&mut self, value : T) {
let mut a = 0;
if self.GapLastEntry < 0 {
match self.Arena[self.ArenaLastEntry] {
ListE::Node{Value,Next,Prev} => {
}
ListE::Null => {
a = 0;
}
}
}
}
}
fn main() {
let dblyLnkdLst : DoublyLinkedList<char> = DoublyLinkedList::new();
println!("Hello,a world!");
}
Compiler:
-- mode: cargo-process; default-directory: "~/Dropbox/programming/rust/bisschien/DoublyLinkedList/DoublyLinkedList/src/" --
Cargo-Process started at Sat Dec 31 22:11:21
cargo build
Compiling DoublyLinkedList v0.1.0 (file:///home/ahmed/Dropbox/programming/rust/bisschien/DoublyLinkedList/DoublyLinkedList)
error[E0308]: mismatched types
--> main.rs:55:17
|
55 | ListE::Node{Value,Next,Prev} => {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found enum ListE
|
= note: expected type &_
= note: found type ListE<_>
error[E0308]: mismatched types
--> main.rs:59:17
|
59 | ListE::Null => {
| ^^^^^^^^^^^ expected reference, found enum ListE
|
= note: expected type &_
= note: found type ListE<_>
error: aborting due to 2 previous errors
error: Could not compile DoublyLinkedList
.
To learn more, run the command again with --verbose.
Cargo-Process exited abnormally with code 101 at Sat Dec 31 22:11:22