Skip to content

Commit

Permalink
HashBag: Rename get_all to get
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Aug 22, 2024
1 parent 55b4d30 commit f2f81b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
}

fn check_simple_word(&self, word: &str, hidden_homonym: HiddenHomonym) -> Option<&FlagSet> {
for (_stem, flags) in self.aff.words.get_all(word) {
for (_stem, flags) in self.aff.words.get(word) {
if has_flag!(flags, self.aff.options.need_affix_flag) {
continue;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem.as_ref()) {
for (stem, flags) in self.aff.words.get(stem.as_ref()) {
// Nuspell:
// if (!cross_valid_inner_outer(word_flags, e))
// continue;
Expand Down Expand Up @@ -454,7 +454,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem.as_ref()) {
for (stem, flags) in self.aff.words.get(stem.as_ref()) {
// Nuspell:
// if (!cross_valid_inner_outer(word_flags, e))
// continue;
Expand Down Expand Up @@ -583,7 +583,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem_without_suffix.as_ref()) {
for (stem, flags) in self.aff.words.get(stem_without_suffix.as_ref()) {
let valid_cross_prefix_outer = !has_needaffix_prefix
&& flags.contains(&suffix.flag)
&& (suffix.flags.contains(&prefix.flag) || flags.contains(&prefix.flag));
Expand Down Expand Up @@ -677,7 +677,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem2.as_ref()) {
for (stem, flags) in self.aff.words.get(stem2.as_ref()) {
if !flags.contains(&inner_suffix.flag) {
continue;
}
Expand Down Expand Up @@ -752,7 +752,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem2.as_ref()) {
for (stem, flags) in self.aff.words.get(stem2.as_ref()) {
if !flags.contains(&inner_prefix.flag) {
continue;
}
Expand Down Expand Up @@ -851,7 +851,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
}

// Check that the fully stripped word is a stem in the dictionary.
for (stem, flags) in self.aff.words.get_all(stem3.as_ref()) {
for (stem, flags) in self.aff.words.get(stem3.as_ref()) {
if !outer_suffix.flags.contains(&prefix.flag)
&& !flags.contains(&prefix.flag)
{
Expand Down Expand Up @@ -988,7 +988,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem3.as_ref()) {
for (stem, flags) in self.aff.words.get(stem3.as_ref()) {
if !inner_suffix.flags.contains(&prefix.flag)
&& !flags.contains(&prefix.flag)
{
Expand Down Expand Up @@ -1094,7 +1094,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
}

// Check that the fully stripped word is a stem in the dictionary.
for (stem, flags) in self.aff.words.get_all(stem3.as_ref()) {
for (stem, flags) in self.aff.words.get(stem3.as_ref()) {
if !outer_prefix.flags.contains(&suffix.flag)
&& !flags.contains(&suffix.flag)
{
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
continue;
}

for (stem, flags) in self.aff.words.get_all(stem3.as_ref()) {
for (stem, flags) in self.aff.words.get(stem3.as_ref()) {
if !inner_prefix.flags.contains(&suffix.flag)
&& !flags.contains(&suffix.flag)
{
Expand Down Expand Up @@ -1380,7 +1380,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
_ => None,
};

for (stem, flags) in self.aff.words.get_all(word) {
for (stem, flags) in self.aff.words.get(word) {
if has_flag!(flags, self.aff.options.need_affix_flag) {
continue;
}
Expand Down Expand Up @@ -1549,7 +1549,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
// It passes basically a `&mut String` with this function which is used with C++'s
// `basic_string::assign` to hold a substring and that is used to look up in the word
// list. We can avoid that by subslicing the `word: &str` with the same indices. See
// where we call `WordList::get_all` below.
// where we call `WordList::get` below.
//
// There's a `try_recursive` label that Nuspell jumps to in order to recurse or continue
// to the next iteration of the loop. We just do the recursion/continuing instead of
Expand Down Expand Up @@ -1581,7 +1581,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
let Some((part1_stem, part1_flags)) =
self.aff
.words
.get_all(&word[start_pos..i])
.get(&word[start_pos..i])
.find(|(_stem, flags)| {
!has_flag!(flags, self.aff.options.need_affix_flag)
&& self.aff.compound_rules.has_any_flags(flags)
Expand All @@ -1592,7 +1592,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
words_data.push(part1_flags);

let Some((_part2_stem, part2_flags)) =
self.aff.words.get_all(&word[i..]).find(|(_stem, flags)| {
self.aff.words.get(&word[i..]).find(|(_stem, flags)| {
!has_flag!(flags, self.aff.options.need_affix_flag)
&& self.aff.compound_rules.has_any_flags(flags)
})
Expand Down
12 changes: 6 additions & 6 deletions src/hash_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
self.table.len()
}

pub fn get_all<'map, 'key, Q>(&'map self, k: &'key Q) -> GetAllIter<'map, 'key, Q, K, V>
pub fn get<'map, 'key, Q>(&'map self, k: &'key Q) -> GetAllIter<'map, 'key, Q, K, V>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Expand Down Expand Up @@ -198,7 +198,7 @@ where
loop {
match self.inner.next() {
Some(bucket) => {
// SAFETY: the creator of the iterator (`get_all`) ensures that the reference
// SAFETY: the creator of the iterator (`get`) ensures that the reference
// to the value outlives the RawTable. It also prevents concurrent
// modifications to the table.
let element = unsafe { bucket.as_ref() };
Expand Down Expand Up @@ -228,10 +228,10 @@ mod test {
map.insert(1, 2);
assert!(map.len() == 3);

let mut vals: Vec<_> = map.get_all(&1).map(|kv| kv.1).copied().collect();
let mut vals: Vec<_> = map.get(&1).map(|kv| kv.1).copied().collect();
vals.sort_unstable();
assert_eq!(&[1, 2], vals.as_slice());
let vals = map.get_all(&5).map(|kv| kv.1).copied().collect::<Vec<_>>();
let vals = map.get(&5).map(|kv| kv.1).copied().collect::<Vec<_>>();
assert_eq!(&[5], vals.as_slice());
}

Expand All @@ -242,11 +242,11 @@ mod test {
map.insert("hello".to_string(), "world");
map.insert("bye".to_string(), "bob");

let mut hellos: Vec<_> = map.get_all("hello").map(|kv| kv.1).copied().collect();
let mut hellos: Vec<_> = map.get("hello").map(|kv| kv.1).copied().collect();
hellos.sort_unstable();
assert_eq!(&["bob", "world"], hellos.as_slice());

let vals: Vec<_> = map.get_all("bye").map(|kv| kv.1).copied().collect();
let vals: Vec<_> = map.get("bye").map(|kv| kv.1).copied().collect();
assert_eq!(&["bob"], vals.as_slice());
}

Expand Down

0 comments on commit f2f81b9

Please sign in to comment.