-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add iterator for tokens sorted by probability #27
base: stable
Are you sure you want to change the base?
Conversation
pub trait Chainable: Eq + Hash + Clone + Debug {} | ||
impl<T> Chainable for T where T: Eq + Hash + Clone + Debug {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Debug statements in final PR
println!("Tokens {:?}", toks); | ||
println!("Map {:?}", self.map); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove prints or replace with logs in final PR
if !self.map.contains_key(&toks) { | ||
return Vec::new(); | ||
} | ||
println!("Tokens {:?}", toks); | ||
println!("Map {:?}", self.map); | ||
let result = self.map.get(&toks).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine contains_key
and unwrap
call in a match statement
src/lib.rs
Outdated
pub fn iter_rank<S: AsRef<[T]>>(&self, tokens: S) -> RankIterator<T> { | ||
RankIterator::new(self, tokens) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add feature to specify a token to be searched for and return its rank eg. iterate over all tokens of token a
as predecessor and search for token b
and return its rank
@@ -432,6 +460,44 @@ where | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
/// Iterator over tokens sorted by rank given a token (sorted by highest probability) | |||
pub struct RankIterator<'a, T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to something more specific? Maybe ProbabilityIterator
or SortedRankIterator
?
For a compression library we need an iterator over all tokens sorted by its probability. This PR adds this feature.