Crates.io | t-oc |
lib.rs | t-oc |
version | |
source | src |
created_at | 2024-11-14 23:13:25.508883 |
updated_at | 2024-12-08 19:22:53.172832 |
description | Trie Occurrence Counter is frequency dictionary for any type implementing `Iterator |
homepage | https://github.com/bravequickcleverfibreyarn/t-oc |
repository | https://github.com/bravequickcleverfibreyarn/t-oc |
max_upload_size | |
id | 1448423 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
trie occurrence counter is frequency dictionary that uses any impl Iterator<Item = char>
type as occurrent
since its flexibility it allows to count apples with pears without hassle
core::str::Chars
is impl Iterator<Item = char>
type usage with str
is oobuse t_oc::Toc;
use std::panic::catch_unwind;
let mut toc = Toc::new();
let occurrent = "true";
_ = toc.ins(occurrent.chars(), None);
_ = toc.ins(true.to_string().chars(), None);
assert_eq!(2, toc.acq(occurrent.chars()).uproot());
toc.put(occurrent.chars(), 15);
assert_eq!(15, toc.acq(occurrent.chars()).uproot());
let catch = catch_unwind(move|| _ = toc.ins("#&%".chars(), None));
assert!(catch.is_err());
Toc::new_with
new_with
use t_oc::Toc;
struct UsizeCharIterator {
s: String,
c: usize,
}
impl Iterator for UsizeCharIterator {
type Item = char;
fn next(&mut self) -> Option<char> {
let c = self.c;
let opt = self.s.chars().nth(c);
if opt.is_some() {
self.c = c + 1;
}
opt
}
}
impl UsizeCharIterator {
fn new(n: usize) -> Self {
Self { s: n.to_string(), c: 0 }
}
}
fn ix(c: char) -> usize {
c.to_digit(10).unwrap() as usize
}
#[test]
fn test() {
let nums = [0, 2, 2, 100, 100, 9999];
let mut toc = Toc::new_with(ix, 10);
for n in nums {
_ = toc.ins(UsizeCharIterator::new(n), None);
}
assert_eq!(1, toc.acq(UsizeCharIterator::new(0)).uproot());
assert_eq!(2, toc.acq(UsizeCharIterator::new(2)).uproot());
assert_eq!(2, toc.acq(UsizeCharIterator::new(100)).uproot());
assert_eq!(1, toc.acq(UsizeCharIterator::new(9999)).uproot());
}