Function lib_word_count::word_index::add_word [-] [+] [src]

pub fn add_word(word: String, index: &mut Vec<IndexedWord>)

Add a word to a given index.

This function prevents duplicates and increments the count of the word appearances automatically. The vector will be modified accordingly.

Arguments

Examples

use lib_word_count::word_index;

let mut index = Vec::new();

word_index::add_word("Hello".to_string(), &mut index);
word_index::add_word("hELLO".to_string(), &mut index);
word_index::add_word("World".to_string(), &mut index);
word_index::add_word("HELLO".to_string(), &mut index);
word_index::add_word("PFUDOR".to_string(), &mut index);

assert_eq!(index[0], word_index::IndexedWord{
    word: "hello".to_string(),
    appeared: 3
});
assert_eq!(index[1], word_index::IndexedWord{
    word: "world".to_string(),
    appeared: 1
});
assert_eq!(index[2], word_index::IndexedWord{
    word: "pfudor".to_string(),
    appeared: 1
});