#linked-list #iterator #structure #node #deletion #memory

rblist

A block-based, non-circular double-linked list implementation for Rust

1 unstable release

0.1.0 Sep 10, 2024

#788 in Data structures

Download history 117/week @ 2024-09-06 46/week @ 2024-09-13 20/week @ 2024-09-20 14/week @ 2024-09-27 3/week @ 2024-10-04

98 downloads per month
Used in ztimer

Apache-2.0

90KB
2K SLoC

rblist

Crates.io Docs.rs

A block-based, non-circular double-linked list implementation for Rust.

Overview

rblist is a block-based, non-circular double-linked list that allows for efficient manipulation of data. It supports standard operations such as inserting, removing, and iterating over elements. The crate is optimized for use cases where you need a high-performance list structure for quick inserting and deletion, but with some flexibility in managing nodes and data directly.

Features

  • Block-based architecture for better memory efficiency.
  • Support for inserting and removing elements by node reference.
  • Iterator support for traversing elements.
  • Simple and clean API for list manipulation.
  • Not multi-thread safe by design (can be protected with a mutex).

Example

Here is a basic example of how to use rblist:

use rblist::{BList, Scale};

let mut list: BList<i32> = BList::new(Scale::default());
let node1 = list.push_back(1).unwrap();
let node3 = list.push_back(3).unwrap();
let node2 = list.insert_before(2, &node3).unwrap();

for x in list.iter() {
    println!("{}", *x.value().unwrap());
}

assert_eq!(list.len(), 3);
assert_eq!(*list.value(&node1).unwrap(), 1);

let v = list.remove(&node2).unwrap();
assert_eq!(v, 2);
assert_eq!(list.len(), 2);

let v = list.pop_front();
assert_eq!(v.unwrap(), 1);
assert_eq!(list.len(), 1);
assert_eq!(*list.front().unwrap(), 3);

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Installation

To use rblist in your project, add the following to your Cargo.toml:

[dependencies]
rblist = "0.1.x"

Dependencies

~0.5–1MB
~22K SLoC