1 unstable release
Uses old Rust 2015
0.1.0 | Sep 28, 2018 |
---|
#88 in #maps
47KB
750 lines
cuml_map
The goal of this library is to provide data structures that allow for efficient creation and querying of cumulative maps.
That is, for some mapping K -> V
, we want to make it quick and efficient for users to ask the following questions:
- What is the value associated with key
k
? - What is the sum of all values associated with keys
<= k
? - What is the first value
k
where the sum of all values with key<= k
is>=
some valuev
?
These queries are abstracted into the CumlMap
trait, which has the following definition:
pub trait CumlMap {
type Key;
type Value;
fn insert(&mut self, Self::Key, Self::Value);
fn get_cuml(&self, Self::Key) -> Self::Value; // Question 2
fn get_single(&self, Self::Key) -> Self::Value; // Question 1
fn get_quantile(&self, Self::Value) -> Option<Self::Key>; // Question 3
}
Additionally, three implementations of this trait are provided:
FenwickTree
implements a very efficient array-based mapping1 whereKey=usize
.ExtensibleFenwickTree
implements a wrapper around (1), which allows it to be dynamically resized, and take potentially negative keys.CumlTree
uses a red-black tree based structure to generalize to any ordered keys, and will be much more space-efficient than the other two for sparse keys.
1 Peter M. Fenwick (1994). "A new data structure for cumulative frequency tables" (PDF). Software: Practice and Experience. 24 (3): 327–336. CiteSeerX 10.1.1.14.8917 Freely accessible. doi:10.1002/spe.4380240306
Dependencies
~150KB