Crates.io | cumulfreqtable |
lib.rs | cumulfreqtable |
version | 0.1.3 |
source | src |
created_at | 2023-04-04 00:02:28.436593 |
updated_at | 2023-04-06 01:16:07.590749 |
description | A Cumulative Frequency Table implemented with a Binary Indexed Tree |
homepage | |
repository | https://github.com/bombela/cumulfreqtable |
max_upload_size | |
id | 829607 |
size | 72,951 |
Store cumulative frequencies with a binary indexed tree in an array.
Just as an integer is the sum of appropriate powers of two, so can a cumulative frequency be represented as the appropriate sum of sets of cumulative sub-frequencies. from peter m. fenwick, "a new data structure for cumulative frequency tables." (1994)
A cumulative frequency table stores and/or compute the absolute frequency and the cumulative frequency for ever position in the table.
Formal definition from Wikipedia:
In statistics, the frequency (or absolute frequency) of an event i is the number nᵢ of times the observation has occurred/recorded in an experiment or study. The cumulative frequency is the total of the absolute frequencies of all events at or below a certain point in an ordered list of events.
use cumulfreqtable::CumulFreqTable; // Import the trait in scope.
let mut table = cumulfreqtable::BinaryIndexedTree::new(16);
table.inc(0);
table.inc(3);
table.add(5, 3);
assert_eq!(table.freq(0), 1);
assert_eq!(table.freq(3), 1);
assert_eq!(table.freq(5), 3);
assert_eq!(table.freq(6), 0);
assert_eq!(table.sum(0), 1);
assert_eq!(table.sum(3), 2);
assert_eq!(table.sum(5), 5);
assert_eq!(table.sum(6), 5);
assert_eq!(table.total(), 5);
This crate offers two implementations of the [CumulFreqTable] trait: