Skip to content
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

Draft
wants to merge 5 commits into
base: stable
Choose a base branch
from

Conversation

ucyo
Copy link

@ucyo ucyo commented Oct 12, 2022

For a compression library we need an iterator over all tokens sorted by its probability. This PR adds this feature.

Comment on lines +60 to +61
pub trait Chainable: Eq + Hash + Clone + Debug {}
impl<T> Chainable for T where T: Eq + Hash + Clone + Debug {}
Copy link
Author

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

Comment on lines +121 to +122
println!("Tokens {:?}", toks);
println!("Map {:?}", self.map);
Copy link
Author

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

Comment on lines +118 to +123
if !self.map.contains_key(&toks) {
return Vec::new();
}
println!("Tokens {:?}", toks);
println!("Map {:?}", self.map);
let result = self.map.get(&toks).unwrap();
Copy link
Author

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
Comment on lines 133 to 135
pub fn iter_rank<S: AsRef<[T]>>(&self, tokens: S) -> RankIterator<T> {
RankIterator::new(self, tokens)
}
Copy link
Author

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>
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant