Crates.io | threshold-dict |
lib.rs | threshold-dict |
version | 0.7.0 |
source | src |
created_at | 2022-10-15 08:47:27.856875 |
updated_at | 2023-07-13 12:46:07.910992 |
description | A data structure to find smallest key that is larger than the query |
homepage | |
repository | https://github.com/lucidfrontier45/threshold_dict |
max_upload_size | |
id | 688842 |
size | 6,031 |
A data structure to find smallest key that is larger than the query.
Suppose we have a following weight dependent price table.
weight,price
100,10
200,15
500,30
The price is decided by the smallest entry whose weight
key is greater than or equal to the query.
examples
cargo add threshold_dict
A ThresholdDict
can be created by passing kv pairs. If query is greater than all of the keys, None is returned.
let kv_pairs = vec![(100, 10), (200, 15), (500, 30)];
let dict = ThresholdDict::from(kv_pairs);
assert_eq!(dict.query(&90), Some(&10));
assert_eq!(dict.query(600), None);