capped_multiset

Crates.iocapped_multiset
lib.rscapped_multiset
version0.1.0
sourcesrc
created_at2017-03-06 11:52:30.243387
updated_at2017-03-06 11:52:30.243387
descriptionA Multiset that can return a capped value on the elements
homepagehttps://github.com/darnir/capped_multiset
repositoryhttps://github.com/darnir/capped_multiset
max_upload_size
id8851
size11,116
Darshit Shah (darnir)

documentation

https://docs.rs/capped_multiset

README

Build Status Crates.io Crates.io Docs.rs

CappedMultiset

A multiset is a datastructure which resembles a classic Set, except it allows duplicate elements for each key. For more information on Multisets, see:

This crate implements a CappedMultiset. A CappedMultiset is a datastructure similar to a multiset, except it can have a dynamically defined "cap" on the value of each key. When such a cap is defined, any operation to retrieve the value of an element of the set, the value returned will be no greater than the "cap" on the multiset. This cap can be changed at runtime and does not affect the actual data stored in the Multiset. As a result, setting cap = 1 or any other low value is not a lossy operation.

Installation

[dependencies]
capped_multiset = "0.1"

Example

extern crate capped_multiset;

use capped_multiset::CappedMultiset;

fn main() {
    let set = vec![1, 2, 3, 4, 5];
    let mut capped_set = CappedMultiset::new(set);
    assert_eq!(capped_set.sum(), 15);
    capped_set.set_cap(Some(1));
    assert_eq!(capped_set.sum(), 5);
    capped_set.set_cap(Some(2));
    assert_eq!(capped_set.sum(), 9);
}

License

MIT

Commit count: 20

cargo fmt