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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orx-linked-list"
version = "3.7.0"
version = "3.8.0"
edition = "2024"
authors = ["orxfun <orx.ugur.arikan@gmail.com>"]
description = "A linked list implementation with unique features and an extended list of constant time methods providing high performance traversals and mutations."
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ pub mod pointers;
mod type_aliases;
mod variant;

pub use list::List;
pub use list::ends_traits::*;
pub use list::iter_traits::*;
pub use list::slice::{ListSlice, ListSliceMut};
pub use list::List;
pub use orx_selfref_col::{MemoryPolicy, NodeIdx, NodeIdxError};
pub use type_aliases::{
DoublyIdx, DoublyList, DoublyListLazy, DoublyListSlice, DoublyListSliceLazy,
Expand Down
4 changes: 2 additions & 2 deletions src/list/iter_traits/doubly_iterable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
Doubly, DoublyIdx,
iter::{DoublyIter, DoublyIterPtr, DoublyLinkIter},
list::helper_traits::HasDoublyEnds,
pointers::DoublyPtr,
type_aliases::{BACK_IDX, FRONT_IDX, OOB},
Doubly, DoublyIdx,
};
use core::iter::{Chain, Rev};
use orx_pinned_vec::PinnedVec;
Expand Down Expand Up @@ -283,7 +283,7 @@ where
M: 'a,
{
let b = self.col().try_get_ptr(idx).expect(OOB);
let a = self.ends().get(BACK_IDX).cloned();
let a = self.ends().get(FRONT_IDX).cloned();
DoublyIter::new(self.col(), a, Some(b)).rev()
}

Expand Down
155 changes: 97 additions & 58 deletions tests/iter_from.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
use orx_linked_list::*;

#[test]
fn iter_from_singly() {
let mut list = SinglyList::new();
let mut idx42 = None;
for i in 0..324 {
let idx = list.push_front(i.to_string());
if i == 42 {
idx42 = Some(idx)
}
}

let idx42 = idx42.unwrap();

let vec: Vec<_> = list.iter().cloned().collect();
let index_of_42 = vec
fn test_singly_iter_from(
list: &SinglyList<String>,
vec: &[String],
value: usize,
idx: NodeIdx<Singly<String>>,
) {
let position = vec
.iter()
.enumerate()
.find(|(_, x)| x == &&42.to_string())
.find(|(_, x)| x == &&value.to_string())
.unwrap()
.0;

let vec_slice = &vec[index_of_42..];
let mut list_slice = list.iter_from(&idx42);
let vec_slice = &vec[position..];
let mut list_slice = list.iter_from(&idx);
#[cfg(feature = "validation")]
list.validate();

Expand All @@ -34,37 +26,51 @@ fn iter_from_singly() {
assert!(list_slice.next().is_none());
}

#[test]
fn iter_from_doubly() {
let mut list = DoublyList::new();
let mut idx42 = None;
for i in 0..324 {
let idx = match i % 3 == 0 {
true => list.push_back(i.to_string()),
false => list.push_front(i.to_string()),
};
fn test_doubly_iter_from(
list: &DoublyList<String>,
vec: &[String],
value: usize,
idx: NodeIdx<Doubly<String>>,
) {
let position = vec
.iter()
.enumerate()
.find(|(_, x)| x == &&value.to_string())
.unwrap()
.0;

if i == 42 {
idx42 = Some(idx)
}
let vec_slice = &vec[position..];
let mut list_slice = list.iter_from(&idx);
#[cfg(feature = "validation")]
list.validate();

for x in vec_slice {
let value = list_slice.next().unwrap();
assert_eq!(x, value);
}

let idx42 = idx42.unwrap();
assert!(list_slice.next().is_none());
}

let vec: Vec<_> = list.iter().cloned().collect();
let index_of_42 = vec
fn test_doubly_iter_backward_from(
list: &DoublyList<String>,
vec: &[String],
value: usize,
idx: NodeIdx<Doubly<String>>,
) {
let position = vec
.iter()
.enumerate()
.find(|(_, x)| x == &&42.to_string())
.find(|(_, x)| x == &&value.to_string())
.unwrap()
.0;

let vec_slice = &vec[index_of_42..];
let mut list_slice = list.iter_from(&idx42);
let vec_slice = &vec[0..=position];
let mut list_slice = list.iter_backward_from(&idx);
#[cfg(feature = "validation")]
list.validate();

for x in vec_slice {
for x in vec_slice.iter().rev() {
let value = list_slice.next().unwrap();
assert_eq!(x, value);
}
Expand All @@ -73,39 +79,72 @@ fn iter_from_doubly() {
}

#[test]
fn iter_backward_from_doubly() {
fn iter_from_singly() {
let mut list = SinglyList::new();
let [mut idx_first, mut idx_last, mut idx42] = [None, None, None];
for i in 0..324 {
let idx = list.push_front(i.to_string());
match i {
0 => idx_first = Some(idx),
42 => idx42 = Some(idx),
323 => idx_last = Some(idx),
_ => {}
};
}

let vec: Vec<_> = list.iter().cloned().collect();

test_singly_iter_from(&list, &vec, 0, idx_first.unwrap());
test_singly_iter_from(&list, &vec, 323, idx_last.unwrap());
test_singly_iter_from(&list, &vec, 42, idx42.unwrap());
}

#[test]
fn iter_from_doubly() {
let mut list = DoublyList::new();
let mut idx42 = None;
let [mut idx_first, mut idx_last, mut idx42] = [None, None, None];
for i in 0..324 {
let idx = match i % 3 == 0 {
true => list.push_back(i.to_string()),
false => list.push_front(i.to_string()),
};

if i == 42 {
idx42 = Some(idx)
}
match i {
0 => idx_first = Some(idx),
42 => idx42 = Some(idx),
323 => idx_last = Some(idx),
_ => {}
};
}

let idx42 = idx42.unwrap();

let vec: Vec<_> = list.iter().cloned().collect();
let index_of_42 = vec
.iter()
.enumerate()
.find(|(_, x)| x == &&42.to_string())
.unwrap()
.0;

let vec_slice = &vec[0..=index_of_42];
let mut list_slice = list.iter_backward_from(&idx42);
#[cfg(feature = "validation")]
list.validate();
test_doubly_iter_from(&list, &vec, 0, idx_first.unwrap());
test_doubly_iter_from(&list, &vec, 323, idx_last.unwrap());
test_doubly_iter_from(&list, &vec, 42, idx42.unwrap());
}

for x in vec_slice.iter().rev() {
let value = list_slice.next().unwrap();
assert_eq!(x, value);
#[test]
fn iter_backward_from_doubly() {
let mut list = DoublyList::new();
let [mut idx_first, mut idx_last, mut idx42] = [None, None, None];
for i in 0..324 {
let idx = match i % 3 == 0 {
true => list.push_back(i.to_string()),
false => list.push_front(i.to_string()),
};

match i {
0 => idx_first = Some(idx),
42 => idx42 = Some(idx),
323 => idx_last = Some(idx),
_ => {}
};
}

assert!(list_slice.next().is_none());
let vec: Vec<_> = list.iter().cloned().collect();

test_doubly_iter_backward_from(&list, &vec, 0, idx_first.unwrap());
test_doubly_iter_backward_from(&list, &vec, 323, idx_last.unwrap());
test_doubly_iter_backward_from(&list, &vec, 42, idx42.unwrap());
}