#buffer #queue #bounded #bounds-preserving

bndpresbufq

Bounds-preserving, optionally limited, buffer queue

4 releases

0.1.4 Oct 5, 2024
0.1.3 Oct 5, 2024
0.1.2 Sep 12, 2024
0.1.1 Sep 12, 2024
0.1.0 Apr 9, 2024

#1748 in Data structures

Download history 2/week @ 2024-07-29 283/week @ 2024-09-09 24/week @ 2024-09-16 4/week @ 2024-09-23 308/week @ 2024-09-30 61/week @ 2024-10-07 27/week @ 2024-10-14

401 downloads per month
Used in bndpresbufch

0BSD license

12KB
231 lines

Bounds-preserving buffer queue

BndPresLimBufQ is a bounds-preserving, optionally limited, buffer queue.


lib.rs:

BndPresLimBufQ is a bounds-preserving, optionally limited, buffer queue.

Terminology

length is used to refer the number of elements in the queue. size is used to refer to the total amount of bytes in the queue.

Example

use bndpresbufq::BndPresLimBufQ;

// Construct a queue with a maximum 2 element length limit and 4 bytes size
// limit
let mut q = BndPresLimBufQ::new(Some(2), Some(4));

// Add elements to fill up to queue
q.try_push(vec![1, 2]).unwrap();
q.force_push(vec![3, 4]);

// Fail to add new node
assert_eq!(q.try_push(vec![5]), Err(vec![5]));

// Forcibly add node; expelling the oldest node
q.force_push([6].into());

assert_eq!(q.pop(), Some(vec![3, 4]));
assert_eq!(q.pop(), Some(vec![6]));
assert_eq!(q.pop(), None);

Dependencies

~11KB