2 releases

0.1.0-beta2 Oct 28, 2022
0.1.0-beta1 Sep 13, 2022

#1080 in Data structures

Download history 364/week @ 2023-12-31 40/week @ 2024-01-07 99/week @ 2024-01-14 62/week @ 2024-01-21 211/week @ 2024-01-28 8/week @ 2024-02-04 70/week @ 2024-02-11 61/week @ 2024-02-18 450/week @ 2024-02-25 361/week @ 2024-03-03 3110/week @ 2024-03-10 3433/week @ 2024-03-17 2113/week @ 2024-03-24 59/week @ 2024-03-31

8,721 downloads per month

Custom license

75KB
1.5K SLoC

fixed-slice-deque

MIT licensed GHA Build Status Docs Badge Crates.io

Add the library dependency

[dependencies]
fixed-slice-deque = "0.1.0-beta2"

Explanation:

A fixed size double-ended queue that Derefs into a slice. For keeping the fixed queue size items pushed out of bounds are pop and returned in inserting operations.

Example:

Initialize state, empty, with fixed size of 3

`X = None`
+---+---+---+
| X | X | X |
+---+---+---+

Pushing 1 to the back, since it is empty, 1 is the only item in the deque

=> push_back(1)

+---+---+---+
| 1 | X | X |
+---+---+---+

Push 2 to the front (left)

=> push_front(2)

+---+---+---+
| 2 | 1 | X |
+---+---+---+

Push again to the back, a single 3. The deque now is full

=> push_back(3)

+---+---+---+
| 2 | 1 | 3 |
+---+---+---+

We try to add a new item at the back, but we would have one extra, the first item (2) is pop to the left and returned. We keep the elements and the fixed size

=> push_back(4)

+---+---+---+
| 1 | 3 | 4 | => return Some(2)
+---+---+---+

The same happens when pushing to the front again, the back-most (right) item is pop and returned

=> push_front(5)

+---+---+---+
| 5 | 1 | 3 | => return Some(4)
+---+---+---+

It is implemented as a wrapper over SliceDeque slice-deque crate

Almost every orignal SliceDeque method is wrapped. Please refer to it's twin method documentation for internal functionality.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in SliceDeque by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~240–460KB