#queue #buffer #bounded #max #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

#1795 in Data structures


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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy