Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orx-linked-list"
version = "3.10.0"
version = "4.0.0"
edition = "2024"
authors = ["orxfun <[email protected]>"]
description = "A linked list implementation with unique features and an extended list of constant time methods providing high performance traversals and mutations."
Expand All @@ -16,7 +16,7 @@ orx-pinned-vec = { version = "3.21.0", default-features = false }
orx-fixed-vec = { version = "3.22.0", default-features = false }
orx-split-vec = { version = "3.22.0", default-features = false }
orx-concurrent-iter = { version = "3.1.0", default-features = false }
orx-selfref-col = { version = "2.14.0", default-features = false }
orx-selfref-col = { git = "https://github.com/orxfun/orx-selfref-col.git", branch = "make-NodeIdx-Send", default-features = false }
orx-parallel = { version = "3.3.0", default-features = false, optional = true }

[dev-dependencies]
Expand Down
188 changes: 102 additions & 86 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions benches/doubly_shuffling_around.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ struct TourLinkedList {

impl TourLinkedList {
fn insert_after(&mut self, city: usize, city_to_succeed: usize) {
let a = &self.idx[city];
let b = &self.idx[city_to_succeed];
self.cities.move_next_to(&a, &b);
let a = self.idx[city];
let b = self.idx[city_to_succeed];
self.cities.move_next_to(a, b);
}

fn create_tour(num_cities: usize, moves: &[(usize, usize)]) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions examples/tour_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ impl Debug for TourLinkedList {

impl TourLinkedList {
fn insert_after(&mut self, city: usize, city_to_succeed: usize) {
let a = &self.idx[city];
let b = &self.idx[city_to_succeed];
self.cities.move_next_to(&a, &b);
let a = self.idx[city];
let b = self.idx[city_to_succeed];
self.cities.move_next_to(a, b);
}

fn create_tour(num_cities: usize, num_moves: usize) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions src/iter/doubly_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
fn next(&mut self) -> Option<Self::Item> {
self.0
.next()
.map(|p| unsafe { self.0.col.data_unchecked(&p) })
.map(|p| unsafe { self.0.col.data_unchecked(p) })
}
}

Expand All @@ -46,7 +46,7 @@ where
fn next_back(&mut self) -> Option<Self::Item> {
self.0
.next_back()
.map(|p| unsafe { self.0.col.data_unchecked(&p) })
.map(|p| unsafe { self.0.col.data_unchecked(p) })
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/iter/doubly_iter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ where
type Item = &'a mut T;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let ptr = p.ptr_mut();
let ptr = unsafe { p.ptr_mut() };
match self.current == self.current_back {
false => self.current = self.col.node(p).next().get().cloned(),
false => self.current = self.col.node(p).next().get(),
true => self.end(),
}

Expand All @@ -73,11 +73,12 @@ where
P: PinnedVec<Node<Doubly<T>>>,
{
fn next_back(&mut self) -> Option<Self::Item> {
match &self.current_back {
match self.current_back {
Some(p) => {
let ptr = p.ptr_mut();
// SAFETY: collection as alive as guaranteed by the `col` field.
let ptr = unsafe { p.ptr_mut() };
match self.current == self.current_back {
false => self.current_back = self.col.node(p).prev().get().cloned(),
false => self.current_back = self.col.node(p).prev().get(),
true => self.end(),
}
unsafe { &mut *ptr }.data_mut()
Expand Down
5 changes: 2 additions & 3 deletions src/iter/doubly_iter_mut_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
first: [Option<NodePtr<Doubly<T>>>; 2],
second: [Option<NodePtr<Doubly<T>>>; 2],
) -> Self {
let iter = DoublyIterMut::new(col, first[0].clone(), first[1].clone());
let iter = DoublyIterMut::new(col, first[0], first[1]);
let [second_front, second_back] = second;
Self {
iter,
Expand All @@ -50,8 +50,7 @@ where
true => None,
false => {
self.consumed_first = true;
self.iter
.restart_for(self.second_front.clone(), self.second_back.clone());
self.iter.restart_for(self.second_front, self.second_back);
self.iter.next()
}
},
Expand Down
17 changes: 9 additions & 8 deletions src/iter/doubly_iter_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ where
P: PinnedVec<Node<Doubly<T>>>,
{
pub(crate) fn new(col: CoreCol<Doubly<T>, P>) -> Self {
let current = col.ends().get(0).cloned();
let current_back = col.ends().get(1).cloned();
let current = col.ends().get(0);
let current_back = col.ends().get(1);
Self {
col,
current,
Expand All @@ -42,11 +42,11 @@ where
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let ptr = p.ptr_mut();
let ptr = unsafe { p.ptr_mut() };
match self.current == self.current_back {
false => self.current = self.col.node(p).next().get().cloned(),
false => self.current = self.col.node(p).next().get(),
true => self.end(),
}

Expand All @@ -62,11 +62,12 @@ where
P: PinnedVec<Node<Doubly<T>>>,
{
fn next_back(&mut self) -> Option<Self::Item> {
match &self.current_back {
match self.current_back {
Some(p) => {
let ptr = p.ptr_mut();
// SAFETY: collection as alive as guaranteed by the `col` field.
let ptr = unsafe { p.ptr_mut() };
match self.current == self.current_back {
false => self.current_back = self.col.node(p).prev().get().cloned(),
false => self.current_back = self.col.node(p).prev().get(),
true => self.end(),
}

Expand Down
16 changes: 8 additions & 8 deletions src/iter/doubly_iter_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ where
type Item = NodePtr<Doubly<T>>;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let ptr = Some(p.clone());
let ptr = Some(p);
match self.current == self.current_back {
false => self.current = self.col.node(p).next().get().cloned(),
false => self.current = self.col.node(p).next().get(),
true => self.end(),
}

Expand All @@ -64,12 +64,12 @@ where
P: PinnedVec<Node<Doubly<T>>>,
{
fn next_back(&mut self) -> Option<Self::Item> {
match &self.current_back {
match self.current_back {
Some(p) => {
let ptr = Some(p.clone());
let ptr = Some(p);

match self.current == self.current_back {
false => self.current_back = self.col.node(p).prev().get().cloned(),
false => self.current_back = self.col.node(p).prev().get(),
true => self.end(),
}

Expand All @@ -89,8 +89,8 @@ where
fn clone(&self) -> Self {
Self {
col: self.col,
current: self.current.clone(),
current_back: self.current_back.clone(),
current: self.current,
current_back: self.current_back,
}
}
}
4 changes: 2 additions & 2 deletions src/iter/doubly_link_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ where
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|p| {
(unsafe { self.0.col.data_unchecked(&p.0) }, unsafe {
self.0.col.data_unchecked(&p.1)
(unsafe { self.0.col.data_unchecked(p.0) }, unsafe {
self.0.col.data_unchecked(p.1)
})
})
}
Expand Down
13 changes: 6 additions & 7 deletions src/iter/doubly_link_iter_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ where
type Item = PairPtr<T>;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let (prev, curr) = p.clone();
let (prev, curr) = p;
match Some(&curr) == self.current_back.as_ref() {
false => {
//
let next = self.col.node(&curr).next().get().cloned();
let new_current = next.map(|next| (curr.clone(), next));
let next = self.col.node(curr).next().get();
let new_current = next.map(|next| (curr, next));
self.current = new_current;
}
true => self.end(),
Expand All @@ -75,8 +74,8 @@ where
fn clone(&self) -> Self {
Self {
col: self.col,
current: self.current.clone(),
current_back: self.current_back.clone(),
current: self.current,
current_back: self.current_back,
}
}
}
2 changes: 1 addition & 1 deletion src/iter/singly_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
fn next(&mut self) -> Option<Self::Item> {
self.0
.next()
.map(|p| unsafe { self.0.col.data_unchecked(&p) })
.map(|p| unsafe { self.0.col.data_unchecked(p) })
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/iter/singly_iter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
P: PinnedVec<Node<Singly<T>>>,
{
pub(crate) fn new_old(col: &'a mut CoreCol<Singly<T>, P>) -> Self {
let current = col.ends().get().cloned();
let current = col.ends().get();
Self { col, current }
}

Expand All @@ -38,10 +38,11 @@ where
type Item = &'a mut T;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let ptr = p.ptr_mut();
self.current = self.col.node(p).next().get().cloned();
// SAFETY: collection as alive as guaranteed by the `col` field.
let ptr = unsafe { p.ptr_mut() };
self.current = self.col.node(p).next().get();
unsafe { &mut *ptr }.data_mut()
}
None => None,
Expand Down
9 changes: 5 additions & 4 deletions src/iter/singly_iter_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
P: PinnedVec<Node<Singly<T>>>,
{
pub(crate) fn new(col: CoreCol<Singly<T>, P>) -> Self {
let current = col.ends().get().cloned();
let current = col.ends().get();
Self { col, current }
}
}
Expand All @@ -31,10 +31,11 @@ where
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let ptr = p.ptr_mut();
self.current = self.col.node(p).next().get().cloned();
// SAFETY: collection as alive as guaranteed by the `col` field.
let ptr = unsafe { p.ptr_mut() };
self.current = self.col.node(p).next().get();
unsafe { &mut *ptr }.take_data()
}
None => None,
Expand Down
8 changes: 4 additions & 4 deletions src/iter/singly_iter_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ where
type Item = NodePtr<Singly<T>>;

fn next(&mut self) -> Option<Self::Item> {
match &self.current {
match self.current {
Some(p) => {
let ptr = Some(p.clone());
self.current = self.col.node(p).next().get().cloned();
let ptr = Some(p);
self.current = self.col.node(p).next().get();
ptr
}
None => None,
Expand All @@ -50,7 +50,7 @@ where
fn clone(&self) -> Self {
Self {
col: self.col,
current: self.current.clone(),
current: self.current,
}
}
}
Loading