You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementing a double-linked structure is not straight-forward in Rust for several reasons. @segeljakt has a WIP (#24) with an implementation. His thoughts on design follows:
I think there should be one or more chunked array queue implementations floating around on https://crates.io/. The solution I had in mind before was to use:
a std::collections::LinkedList for connecting the chunks
a std::vec::Vec (or array [T;N]) for storing each chunk.
a std::collections::linked_list::CursorMut for traversing between chunks.
a higher-level Cursor, building on top of CursorMut for traversing between elements of chunks.
A cursor is like an iterator but does not consume the thing it is iterating over. With DoubleEndedIterator, it might be a problem because you cannot iterate over the same element twice:
let numbers = vec![1,2,3,4,5,6];letmut iter = numbers.iter();assert_eq!(Some(&1), iter.next());assert_eq!(Some(&6), iter.next_back());assert_eq!(Some(&5), iter.next_back());assert_eq!(Some(&2), iter.next());assert_eq!(Some(&3), iter.next());assert_eq!(Some(&4), iter.next());assert_eq!(None, iter.next());assert_eq!(None, iter.next_back());
If you need multiple cursors, you might have to create them using an unsafe pointer. I think it is not possible to use a std::cell::RefCell + std::rc::Rc because the cursors must mutably borrow the linked list which they are traversing for their whole lifetime. With RefCell, Rust would panic if two cursors exist simultaneously. There should hopefully be no problem as long as you ensure that the cursors do not point to something which is deallocated.
Implementing a double-linked structure is not straight-forward in Rust for several reasons. @segeljakt has a WIP (#24) with an implementation. His thoughts on design follows:
And,
The text was updated successfully, but these errors were encountered: