An alternative implementation of std::collections::LinkedList
featuring a prototype Cursor.
Documentation is available at https://contain-rs.github.io/linked-list/linked_list.
An alternative implementation of std::collections::LinkedList
Home Page: https://contain-rs.github.io/linked-list/linked_list/
License: Other
An alternative implementation of std::collections::LinkedList
featuring a prototype Cursor.
Documentation is available at https://contain-rs.github.io/linked-list/linked_list.
Set Travis's GH_TOKEN
environment variable after creating a new personal access token. You only need to give it the public_repo
permission.
Create an empty gh-pages
branch:
git checkout --orphan gh-pages
git rm -rf '*'
git commit --allow-empty -m 'create `gh-pages` branch'
git push origin gh-pages
Restart the first build.
It would be great to have a truly circular linked list, with no ghost. That way, you could iterate infinitely on the elements without worrying about the ghost, you could seek by n
without stepping one by one, checking for the ghost, etc.
Hi,
At the moment it seems that
Cursor::next()
Cursor::prev()
Cursor::peek_next()
Cursor::peek_prev()
all return Option<&mut T>
where the reference has the lifetime of the Cursor
instance, and not the underlying LinkedList
.
I believe it should be safe in those methods to update the signatures to .. -> Option<&'a mut T>
, and transmute the return value to have the appropriate lifetime. Does that sound correct?
Hi folks,
I've been poking around in data structures and I need to remove an element from this linked list (it stores a reference of a trait). My code is basically:
pub fn remove(&mut self, timer: &'a T) {
// other stuff.
let mut cursor = list.cursor();
loop {
let next = cursor.peek_next();
if next.is_some() {
if *(next.unwrap()) as *const T == timer as *const T {
cursor.remove();
break;
}
cursor.seek_forward(1);
} else {
break;
}
}
}
Now this doesn't work because remove
and/or seek_forward
borrow mut, but the peek_next
did already. I think in this case what I'd need would be a peek which doesn't return a mut, right? Can we put that in or is there an obvious solution that I don't know about?
@gankro wdyt?
When at the cursor is positioned at the first node, split_before
returns a new empty list which has its head pointer set to the original list's head which should not be the case. The same happens with split_after
when at the last node.
std
's LinkedList
has a split_off
method that panics if the given index is greater than the list's length, while this crate has a split_at
method that returns an empty list in that scenario.
error[E0080]: constant evaluation error: no item to reborrow for Unique from tag 106812 found in borrow stack
--> src/lib.rs:747:9
|
747 | ret
| ^^^ no item to reborrow for Unique from tag 106812 found in borrow stack
|
= note: inside call to `<LinkedList<i32> as std::iter::FromIterator<i32>>::from_iter::<std::iter::Map<std::slice::Iter<i32>, [closure@src/lib.rs:869:22: 869:38]>>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/iter/traits/iterator.rs:1465:9
note: inside call to `<std::iter::Map<std::slice::Iter<i32>, [closure@src/lib.rs:869:22: 869:38]> as std::iter::Iterator>::collect::<LinkedList<i32>>` at src/lib.rs:869:9
--> src/lib.rs:869:9
|
869 | v.iter().map(|x| (*x).clone()).collect()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `tests::list_from::<i32>` at src/lib.rs:1200:25
--> src/lib.rs:1200:25
|
1200| let mut list1 = list_from(&[0,1,2,3]);
| ^^^^^^^^^^^^^^^^^^^^^
note: inside call to `tests::test_append` at src/lib.rs:1199:5
--> src/lib.rs:1199:5
|
1199| / fn test_append() {
1200| | let mut list1 = list_from(&[0,1,2,3]);
1201| | let mut list2 = list_from(&[4,5,6,7]);
1202| |
... |
1222| | assert_eq!(list1.len(), 0);
1223| | }
| |_____^
= note: inside call to closure at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
= note: inside call to `<[closure@src/lib.rs:1199:5: 1223:6] as std::ops::FnOnce<()>>::call_once - shim` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
= note: inside call to `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:1522:5
= note: inside call to `tests::test::__rust_begin_short_backtrace::<fn()>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:1513:30
= note: inside call to closure at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
= note: inside call to `<[closure@DefId(9/1:109 ~ test[b0fc]::run_test[0]::{{closure}}[3]) 0:fn()] as std::ops::FnOnce<()>>::call_once - shim` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
= note: inside call to `<[closure@DefId(9/1:109 ~ test[b0fc]::run_test[0]::{{closure}}[3]) 0:fn()] as std::ops::FnOnce<()>>::call_once - shim(vtable)` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc/boxed.rs:704:9
= note: inside call to `<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send> as std::ops::FnOnce<()>>::call_once` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panic.rs:309:9
= note: inside call to `<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>> as std::ops::FnOnce<()>>::call_once` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panicking.rs:293:40
= note: inside call to `std::panicking::try::do_call::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>>, ()>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panicking.rs:289:5
= note: inside call to `std::panicking::try::<(), std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>>>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panic.rs:388:9
= note: inside call to `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::boxed::FnBox<(), Output = ()> + std::marker::Send>>, ()>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:1468:26
= note: inside call to closure at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:1490:13
= note: inside call to `tests::test::run_test::run_test_inner` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:1509:28
= note: inside call to `tests::test::run_test` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:1167:13
= note: inside call to `tests::test::run_tests::<[closure@DefId(9/1:80 ~ test[b0fc]::run_tests_console[0]::{{closure}}[2]) 0:&mut tests::test::ConsoleTestState, 1:&mut std::boxed::Box<dyn tests::test::formatters::OutputFormatter>]>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:972:5
= note: inside call to `tests::test::run_tests_console` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:293:15
= note: inside call to `tests::test::test_main` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libtest/lib.rs:327:5
= note: inside call to `tests::test::test_main_static`
= note: inside call to `main` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/rt.rs:64:34
= note: inside call to closure at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/rt.rs:52:53
= note: inside call to closure at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panicking.rs:293:40
= note: inside call to `std::panicking::try::do_call::<[closure@DefId(1/1:1835 ~ std[797b]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panicking.rs:289:5
= note: inside call to `std::panicking::try::<i32, [closure@DefId(1/1:1835 ~ std[797b]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/panic.rs:388:9
= note: inside call to `std::panic::catch_unwind::<[closure@DefId(1/1:1835 ~ std[797b]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/rt.rs:52:25
= note: inside call to `std::rt::lang_start_internal` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/rt.rs:64:5
= note: inside call to `std::rt::lang_start::<()>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.
test tests::test_append ...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.