1 unstable release

0.1.0 Mar 2, 2024

#1082 in Data structures

Download history 131/week @ 2024-02-25 37/week @ 2024-03-03 4/week @ 2024-03-10 17/week @ 2024-03-31 1/week @ 2024-04-07 39/week @ 2024-04-14

57 downloads per month

CC0 license

11KB
192 lines

What

TreeMultiSet is an implementation of a multiset that allows duplicate elements. This data structure maintains a sorted state as elements are added, and supports iterators and range queries, offering more flexibility in operations.

Iterator

Iterator Support: Easily iterate through elements using the provided iterator.

Range Query Support: Utilize the range method to iterate over elements within a specific range, allowing extraction of elements within a defined range.

Example

ABC241 D - Sequence Query: https://atcoder.jp/contests/abc241/submissions/49645890

ABC212 D - Querying Multiset: https://atcoder.jp/contests/abc212/submissions/49645865


lib.rs:

This crate provides the TreeMultiSet data structure, which is an implementation of a multi-set using a BTree (BTreeMap) in Rust.

Examples

use tree_multi_set::TreeMultiSet;

let mut set = TreeMultiSet::new();

// Inserting elements
set.insert(1);
set.insert(2);
set.insert(2);

// Counting occurrences
assert_eq!(set.count(&1), 1);
assert_eq!(set.count(&2), 2);

// Removing elements
set.remove_one(&2);
assert_eq!(set.count(&2), 1);

// Iterating over elements
for elem in set.iter() {
    println!("{}", elem);
}

The TreeMultiSet allows for efficient insertion, removal, and counting of elements, making it suitable for scenarios where elements need to be stored along with their counts.

No runtime deps