fn guarantee_maximum_prefix_length(
    list: &[String],
    maximum_shared_prefix_length: usize,
) -> Vec<String> {
    let mut prefix_hashmap: HashMap<String, String> = HashMap::new();
    for this_word in list {
        // If this word is too short just skip it.
        if this_word.chars().count() < maximum_shared_prefix_length {
            continue;
        }
        prefix_hashmap
            .entry(get_prefix(this_word, maximum_shared_prefix_length))
            .and_modify(|existing_word| {
                // Prefer shorter words, as a stand-in for simplicity (though that
                // is debatable...)
                if this_word.chars().count() < existing_word.chars().count() {
                    *existing_word = this_word.to_string()
                }
            })
            .or_insert_with(|| this_word.to_string());
    }
    let new_vec: Vec<(&String, &String)> = prefix_hashmap.iter().collect();
    let mut new_word_list = vec![];
    for t in new_vec {
        new_word_list.push(t.1.to_string());
    }
    new_word_list
}
/// This function removes words from the given word list
/// such that the resulting, outputted list has a guaranteed
/// maximum prefix length.  
///
/// As an example, if `maximum_shared_prefix_length == 4`, this
/// means that on the resulting list, knowing the first 4 characters
/// of any word on the generated list is sufficient to know which
/// word it is. In this case, we'd know that if a word starts with
/// "radi", we know it must be the word "radius" (if "radical" had been
/// on the list, this function would have removed it).
///
/// This is useful if you intend the list to be used by software that
/// uses auto-complete. In the case described above, a user will only have to type the
/// first 4 characters of any word before a program could successfully
/// auto-complete the entire word.
This function removes words from the given word list
such that the resulting, outputted list has a guaranteed
maximum prefix length.

As an example, if `maximum_shared_prefix_length == 4`, this
means that on the resulting list, knowing the first 4 characters
of any word on the generated list is sufficient to know which
word it is.

This is useful if you intend the list to be used by software that
uses auto-complete. In the case described above, a user will only have to type the
first 4 characters of any word before a program could successfully
auto-complete the entire word.
This function removes words from the given word list such that the resulting outputted list has a guaranteed maximum prefix length . As an example if ` maximum_shared_prefix_length == 4 ` this means that on the resulting list knowing the first 4 characters of any word on the generated list is sufficient to know which word it is . This is useful if you intend the list to be used by software that uses auto - complete . In the case described above a user will only have to type the first 4 characters of any word before a program could successfully auto - complete the entire word .
fn guarantee_maximum_prefix_length(
    list: &[String],
    maximum_shared_prefix_length: usize,
) -> Vec<String> {
    let mut prefix_hashmap: HashMap<String, String> = HashMap::new();
    for this_word in list {
        // If this word is too short just skip it.
        if this_word.chars().count() < maximum_shared_prefix_length {
            continue;
        }
        prefix_hashmap
            .entry(get_prefix(this_word, maximum_shared_prefix_length))
            .and_modify(|existing_word| {
                // Prefer shorter words, as a stand-in for simplicity (though that
                // is debatable...)
                if this_word.chars().count() < existing_word.chars().count() {
                    *existing_word = this_word.to_string()
                }
            })
            .or_insert_with(|| this_word.to_string());
    }
    let new_vec: Vec<(&String, &String)> = prefix_hashmap.iter().collect();
    let mut new_word_list = vec![];
    for t in new_vec {
        new_word_list.push(t.1.to_string());
    }
    new_word_list
}
fn guarantee_maximum_prefix_length ( list : & [ String ] , maximum_shared_prefix_length : usize , ) -> Vec < String > { let mut prefix_hashmap : HashMap < String , String > = HashMap :: new ( ) ; for this_word in list { // If this word is too short just skip it. if this_word . chars ( ) . count ( ) < maximum_shared_prefix_length { continue ; } prefix_hashmap . entry ( get_prefix ( this_word , maximum_shared_prefix_length ) ) . and_modify ( | existing_word | { // Prefer shorter words, as a stand-in for simplicity (though that // is debatable...) if this_word . chars ( ) . count ( ) < existing_word . chars ( ) . count ( ) { * existing_word = this_word . to_string ( ) } } ) . or_insert_with ( | | this_word . to_string ( ) ) ; } let new_vec : Vec < ( & String , & String ) > = prefix_hashmap . iter ( ) . collect ( ) ; let mut new_word_list = vec ! [ ] ; for t in new_vec { new_word_list . push ( t . 1 . to_string ( ) ) ; } new_word_list }
This function removes words from the given word list
such that the resulting, outputted list has a guaranteed
maximum prefix length.
This function removes words from the given word list such that the resulting outputted list has a guaranteed maximum prefix length .
list
&[String]
maximum_shared_prefix_length
usize
list
&[String]
maximum_shared_prefix_length
usize