| Crates.io | bose_einstein |
| lib.rs | bose_einstein |
| version | 0.1.1 |
| created_at | 2025-03-14 19:59:01.221044+00 |
| updated_at | 2025-03-14 23:29:20.753653+00 |
| description | A data structure that efficiently partitions elements into two sets |
| homepage | |
| repository | https://github.com/milkey-mouse/bose_einstein |
| max_upload_size | |
| id | 1592719 |
| size | 284,462 |
A data structure that efficiently partitions elements into left and right sets.
Partition<T> is a data structure that maintains a collection of elements partitioned into two sets: left and right. Elements can be efficiently moved between the sets, and the relative order within each set is not guaranteed to be preserved.
use bose_einstein::Partition;
fn main() {
// Create a new partition
let mut p = Partition::new();
// Add elements to left and right partitions
p.push_left(1);
p.push_left(2);
p.push_right(3);
// Access the elements in each partition
assert_eq!(p.left().len(), 2);
assert_eq!(p.right().len(), 1);
// Move elements between partitions
let moved = p.move_to_right();
assert!(moved.is_some());
// Drain elements from a partition
let left_elements: Vec<_> = p.drain_left().collect();
// Check the state after operations
assert_eq!(p.left().len(), 0);
assert_eq!(p.right().len(), 2);
}
This project is licensed under CC0-1.0.