#ring #buffer #queue

ring_buffer

RingBuffer is a queue with added random access

11 releases (6 stable)

2.0.2 Jul 2, 2021
2.0.0 Jul 1, 2021
1.0.2 Jul 1, 2021
1.0.0 Jun 1, 2021
0.1.1 Jul 13, 2019

#358 in Algorithms

Download history 719/week @ 2022-10-09 191/week @ 2022-10-16 597/week @ 2022-10-23 145/week @ 2022-10-30 131/week @ 2022-11-06 386/week @ 2022-11-13 202/week @ 2022-11-20 212/week @ 2022-11-27 267/week @ 2022-12-04 565/week @ 2022-12-11 497/week @ 2022-12-18 25/week @ 2022-12-25 158/week @ 2023-01-01 658/week @ 2023-01-08 272/week @ 2023-01-15 379/week @ 2023-01-22

1,468 downloads per month
Used in gpcas_simulator

MIT/Apache

49KB
831 lines

ring_buffer

pipeline status

RingBuffer is a mix of a vector and a queue. It allows for direct element access as well as pushing and popping elements like a queue.

Example

use ringbuffer::RingBuffer;

fn main() {
    let mut buffer = RingBuffer::new();
    
    let first_index = buffer.push(42);
    let second_index = buffer.push(9001);
    
    println!("{} == {}", buffer.get_relative(0),
        buffer.get_absolute(first_index));
    
    println!("{} == {}", buffer.get_relative(1),
        buffer.get_absolute(second_index));
}

Why use this?

The features of RingBuffer come in handy when processing a stream of elements while also needing to access elements at random.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps