Skip to content

Commit b1bc306

Browse files
authored
Merge pull request #35 from orxfun/list-made-generic-over-pinned-vec-storage
List made generic over pinned vec storage
2 parents 9ed6c12 + 26cc009 commit b1bc306

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+919
-442
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "orx-linked-list"
3-
version = "3.0.1"
3+
version = "3.1.0"
44
edition = "2021"
55
authors = ["orxfun <[email protected]>"]
66
description = "A linked list implementation with unique features and an extended list of constant time methods providing high performance traversals and mutations."
@@ -13,7 +13,8 @@ categories = ["data-structures", "rust-patterns", "no-std"]
1313
orx-pseudo-default = { version = "1.4", default-features = false }
1414
orx-pinned-vec = "3.9"
1515
orx-split-vec = "3.9"
16-
orx-selfref-col = "2.0"
16+
orx-fixed-vec = "3.9"
17+
orx-selfref-col = "2.1"
1718

1819
[dev-dependencies]
1920
clap = { version = "4.5.17", features = ["derive"] }

examples/tour_mutations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn timed<R, F: FnOnce() -> R>(run: F) -> (R, u128) {
144144
(result, ms)
145145
}
146146

147-
/// Simple program to greet a person
147+
/// Program demonstrating different tour representations.
148148
#[derive(Parser, Debug)]
149149
#[command(version, about, long_about = None)]
150150
struct Args {

src/iter/doubly_iter.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
use super::doubly_iter_ptr::DoublyIterPtr;
2-
use crate::{type_aliases::PinVec, Doubly};
2+
use crate::Doubly;
33
use core::iter::FusedIterator;
4-
use orx_selfref_col::{CoreCol, NodePtr};
4+
use orx_pinned_vec::PinnedVec;
5+
use orx_selfref_col::{CoreCol, Node, NodePtr};
56

67
/// An ordered iterator over elements of the doubly linked list.
78
///
89
/// Can be created by calling the `iter` method.
9-
pub struct DoublyIter<'a, T>(DoublyIterPtr<'a, T>);
10+
pub struct DoublyIter<'a, T, P>(DoublyIterPtr<'a, T, P>)
11+
where
12+
P: PinnedVec<Node<Doubly<T>>>;
1013

11-
impl<'a, T> DoublyIter<'a, T> {
14+
impl<'a, T, P> DoublyIter<'a, T, P>
15+
where
16+
P: PinnedVec<Node<Doubly<T>>>,
17+
{
1218
pub(crate) fn new(
13-
col: &'a CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
19+
col: &'a CoreCol<Doubly<T>, P>,
1420
current: Option<NodePtr<Doubly<T>>>,
1521
current_back: Option<NodePtr<Doubly<T>>>,
1622
) -> Self {
1723
Self(DoublyIterPtr::new(col, current, current_back))
1824
}
1925
}
2026

21-
impl<'a, T> Iterator for DoublyIter<'a, T> {
27+
impl<'a, T, P> Iterator for DoublyIter<'a, T, P>
28+
where
29+
P: PinnedVec<Node<Doubly<T>>>,
30+
{
2231
type Item = &'a T;
2332

2433
#[inline(always)]
@@ -29,7 +38,10 @@ impl<'a, T> Iterator for DoublyIter<'a, T> {
2938
}
3039
}
3140

32-
impl<'a, T> DoubleEndedIterator for DoublyIter<'a, T> {
41+
impl<'a, T, P> DoubleEndedIterator for DoublyIter<'a, T, P>
42+
where
43+
P: PinnedVec<Node<Doubly<T>>>,
44+
{
3345
#[inline(always)]
3446
fn next_back(&mut self) -> Option<Self::Item> {
3547
self.0
@@ -38,9 +50,12 @@ impl<'a, T> DoubleEndedIterator for DoublyIter<'a, T> {
3850
}
3951
}
4052

41-
impl<'a, T> FusedIterator for DoublyIter<'a, T> {}
53+
impl<'a, T, P> FusedIterator for DoublyIter<'a, T, P> where P: PinnedVec<Node<Doubly<T>>> {}
4254

43-
impl<'a, T> Clone for DoublyIter<'a, T> {
55+
impl<'a, T, P> Clone for DoublyIter<'a, T, P>
56+
where
57+
P: PinnedVec<Node<Doubly<T>>>,
58+
{
4459
fn clone(&self) -> Self {
4560
Self(self.0.clone())
4661
}

src/iter/doubly_iter_mut.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
use crate::{type_aliases::PinVec, Doubly};
1+
use crate::Doubly;
22
use core::iter::FusedIterator;
3-
use orx_selfref_col::{CoreCol, NodePtr};
3+
use orx_pinned_vec::PinnedVec;
4+
use orx_selfref_col::{CoreCol, Node, NodePtr};
45

56
/// An ordered iterator mutable references to elements of the doubly linked list.
67
///
78
/// Can be created by calling the `iter_mut` method.
8-
pub struct DoublyIterMut<'a, T> {
9-
col: &'a mut CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
9+
pub struct DoublyIterMut<'a, T, P>
10+
where
11+
P: PinnedVec<Node<Doubly<T>>>,
12+
{
13+
col: &'a mut CoreCol<Doubly<T>, P>,
1014
current: Option<NodePtr<Doubly<T>>>,
1115
current_back: Option<NodePtr<Doubly<T>>>,
1216
}
1317

14-
impl<'a, T> DoublyIterMut<'a, T> {
18+
impl<'a, T, P> DoublyIterMut<'a, T, P>
19+
where
20+
P: PinnedVec<Node<Doubly<T>>>,
21+
{
1522
pub(crate) fn new(
16-
col: &'a mut CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
23+
col: &'a mut CoreCol<Doubly<T>, P>,
1724
current: Option<NodePtr<Doubly<T>>>,
1825
current_back: Option<NodePtr<Doubly<T>>>,
1926
) -> Self {
@@ -39,7 +46,10 @@ impl<'a, T> DoublyIterMut<'a, T> {
3946
}
4047
}
4148

42-
impl<'a, T> Iterator for DoublyIterMut<'a, T> {
49+
impl<'a, T, P> Iterator for DoublyIterMut<'a, T, P>
50+
where
51+
P: PinnedVec<Node<Doubly<T>>>,
52+
{
4353
type Item = &'a mut T;
4454

4555
fn next(&mut self) -> Option<Self::Item> {
@@ -58,7 +68,10 @@ impl<'a, T> Iterator for DoublyIterMut<'a, T> {
5868
}
5969
}
6070

61-
impl<'a, T> DoubleEndedIterator for DoublyIterMut<'a, T> {
71+
impl<'a, T, P> DoubleEndedIterator for DoublyIterMut<'a, T, P>
72+
where
73+
P: PinnedVec<Node<Doubly<T>>>,
74+
{
6275
fn next_back(&mut self) -> Option<Self::Item> {
6376
match &self.current_back {
6477
Some(p) => {
@@ -74,4 +87,4 @@ impl<'a, T> DoubleEndedIterator for DoublyIterMut<'a, T> {
7487
}
7588
}
7689

77-
impl<'a, T> FusedIterator for DoublyIterMut<'a, T> {}
90+
impl<'a, T, P> FusedIterator for DoublyIterMut<'a, T, P> where P: PinnedVec<Node<Doubly<T>>> {}

src/iter/doubly_iter_mut_chain.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
use crate::{type_aliases::PinVec, Doubly};
2-
use core::iter::FusedIterator;
3-
use orx_selfref_col::{CoreCol, NodePtr};
4-
51
use super::DoublyIterMut;
2+
use crate::Doubly;
3+
use core::iter::FusedIterator;
4+
use orx_pinned_vec::PinnedVec;
5+
use orx_selfref_col::{CoreCol, Node, NodePtr};
66

77
/// An ordered iterator mutable references to elements of the doubly linked list.
88
///
99
/// Can be created by calling the `iter_mut` method.
10-
pub struct DoublyIterMutChain<'a, T> {
11-
iter: DoublyIterMut<'a, T>,
10+
pub struct DoublyIterMutChain<'a, T, P>
11+
where
12+
P: PinnedVec<Node<Doubly<T>>>,
13+
{
14+
iter: DoublyIterMut<'a, T, P>,
1215
second_front: Option<NodePtr<Doubly<T>>>,
1316
second_back: Option<NodePtr<Doubly<T>>>,
1417
consumed_first: bool,
1518
}
1619

17-
impl<'a, T> DoublyIterMutChain<'a, T> {
20+
impl<'a, T, P> DoublyIterMutChain<'a, T, P>
21+
where
22+
P: PinnedVec<Node<Doubly<T>>>,
23+
{
1824
pub(crate) fn new(
19-
col: &'a mut CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
25+
col: &'a mut CoreCol<Doubly<T>, P>,
2026
first: [Option<NodePtr<Doubly<T>>>; 2],
2127
second: [Option<NodePtr<Doubly<T>>>; 2],
2228
) -> Self {
@@ -31,7 +37,10 @@ impl<'a, T> DoublyIterMutChain<'a, T> {
3137
}
3238
}
3339

34-
impl<'a, T> Iterator for DoublyIterMutChain<'a, T> {
40+
impl<'a, T, P> Iterator for DoublyIterMutChain<'a, T, P>
41+
where
42+
P: PinnedVec<Node<Doubly<T>>>,
43+
{
3544
type Item = &'a mut T;
3645

3746
fn next(&mut self) -> Option<Self::Item> {
@@ -50,4 +59,4 @@ impl<'a, T> Iterator for DoublyIterMutChain<'a, T> {
5059
}
5160
}
5261

53-
impl<'a, T> FusedIterator for DoublyIterMutChain<'a, T> {}
62+
impl<'a, T, P> FusedIterator for DoublyIterMutChain<'a, T, P> where P: PinnedVec<Node<Doubly<T>>> {}

src/iter/doubly_iter_owned.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
use crate::{type_aliases::PinVec, Doubly};
1+
use crate::Doubly;
22
use core::iter::FusedIterator;
3-
use orx_selfref_col::{CoreCol, NodePtr};
3+
use orx_pinned_vec::PinnedVec;
4+
use orx_selfref_col::{CoreCol, Node, NodePtr};
45

56
/// An ordered consuming iterator of the doubly linked list.
67
///
78
/// Can be created by calling the `into_iter` method.
8-
pub struct DoublyIterOwned<T> {
9-
col: CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
9+
pub struct DoublyIterOwned<T, P>
10+
where
11+
P: PinnedVec<Node<Doubly<T>>>,
12+
{
13+
col: CoreCol<Doubly<T>, P>,
1014
current: Option<NodePtr<Doubly<T>>>,
1115
current_back: Option<NodePtr<Doubly<T>>>,
1216
}
1317

14-
impl<T> DoublyIterOwned<T> {
15-
pub(crate) fn new(col: CoreCol<Doubly<T>, PinVec<Doubly<T>>>) -> Self {
18+
impl<T, P> DoublyIterOwned<T, P>
19+
where
20+
P: PinnedVec<Node<Doubly<T>>>,
21+
{
22+
pub(crate) fn new(col: CoreCol<Doubly<T>, P>) -> Self {
1623
let current = col.ends().get(0);
1724
let current_back = col.ends().get(1);
1825
Self {
@@ -28,7 +35,10 @@ impl<T> DoublyIterOwned<T> {
2835
}
2936
}
3037

31-
impl<T> Iterator for DoublyIterOwned<T> {
38+
impl<T, P> Iterator for DoublyIterOwned<T, P>
39+
where
40+
P: PinnedVec<Node<Doubly<T>>>,
41+
{
3242
type Item = T;
3343

3444
fn next(&mut self) -> Option<Self::Item> {
@@ -47,7 +57,10 @@ impl<T> Iterator for DoublyIterOwned<T> {
4757
}
4858
}
4959

50-
impl<T> DoubleEndedIterator for DoublyIterOwned<T> {
60+
impl<T, P> DoubleEndedIterator for DoublyIterOwned<T, P>
61+
where
62+
P: PinnedVec<Node<Doubly<T>>>,
63+
{
5164
fn next_back(&mut self) -> Option<Self::Item> {
5265
match &self.current_back {
5366
Some(p) => {
@@ -64,4 +77,4 @@ impl<T> DoubleEndedIterator for DoublyIterOwned<T> {
6477
}
6578
}
6679

67-
impl<T> FusedIterator for DoublyIterOwned<T> {}
80+
impl<T, P> FusedIterator for DoublyIterOwned<T, P> where P: PinnedVec<Node<Doubly<T>>> {}

src/iter/doubly_iter_ptr.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
use crate::{type_aliases::PinVec, Doubly};
1+
use crate::Doubly;
22
use core::iter::FusedIterator;
3-
use orx_selfref_col::{CoreCol, NodePtr};
3+
use orx_pinned_vec::PinnedVec;
4+
use orx_selfref_col::{CoreCol, Node, NodePtr};
45

56
/// An ordered iterator over pointers to the elements of the doubly linked list.
67
///
78
/// Can be created by calling the `iter_ptr` method.
8-
pub struct DoublyIterPtr<'a, T> {
9-
pub(crate) col: &'a CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
9+
pub struct DoublyIterPtr<'a, T, P>
10+
where
11+
P: PinnedVec<Node<Doubly<T>>>,
12+
{
13+
pub(crate) col: &'a CoreCol<Doubly<T>, P>,
1014
current: Option<NodePtr<Doubly<T>>>,
1115
current_back: Option<NodePtr<Doubly<T>>>,
1216
}
1317

14-
impl<'a, T> DoublyIterPtr<'a, T> {
18+
impl<'a, T, P> DoublyIterPtr<'a, T, P>
19+
where
20+
P: PinnedVec<Node<Doubly<T>>>,
21+
{
1522
pub(crate) fn new(
16-
col: &'a CoreCol<Doubly<T>, PinVec<Doubly<T>>>,
23+
col: &'a CoreCol<Doubly<T>, P>,
1724
current: Option<NodePtr<Doubly<T>>>,
1825
current_back: Option<NodePtr<Doubly<T>>>,
1926
) -> Self {
@@ -30,7 +37,10 @@ impl<'a, T> DoublyIterPtr<'a, T> {
3037
}
3138
}
3239

33-
impl<'a, T> Iterator for DoublyIterPtr<'a, T> {
40+
impl<'a, T, P> Iterator for DoublyIterPtr<'a, T, P>
41+
where
42+
P: PinnedVec<Node<Doubly<T>>>,
43+
{
3444
type Item = NodePtr<Doubly<T>>;
3545

3646
fn next(&mut self) -> Option<Self::Item> {
@@ -49,7 +59,10 @@ impl<'a, T> Iterator for DoublyIterPtr<'a, T> {
4959
}
5060
}
5161

52-
impl<'a, T> DoubleEndedIterator for DoublyIterPtr<'a, T> {
62+
impl<'a, T, P> DoubleEndedIterator for DoublyIterPtr<'a, T, P>
63+
where
64+
P: PinnedVec<Node<Doubly<T>>>,
65+
{
5366
fn next_back(&mut self) -> Option<Self::Item> {
5467
match &self.current_back {
5568
Some(p) => {
@@ -67,9 +80,12 @@ impl<'a, T> DoubleEndedIterator for DoublyIterPtr<'a, T> {
6780
}
6881
}
6982

70-
impl<'a, T> FusedIterator for DoublyIterPtr<'a, T> {}
83+
impl<'a, T, P> FusedIterator for DoublyIterPtr<'a, T, P> where P: PinnedVec<Node<Doubly<T>>> {}
7184

72-
impl<'a, T> Clone for DoublyIterPtr<'a, T> {
85+
impl<'a, T, P> Clone for DoublyIterPtr<'a, T, P>
86+
where
87+
P: PinnedVec<Node<Doubly<T>>>,
88+
{
7389
fn clone(&self) -> Self {
7490
Self {
7591
col: self.col,

0 commit comments

Comments
 (0)