5 releases (breaking)

0.4.0 Mar 17, 2021
0.3.0 Mar 2, 2021
0.2.0 Mar 2, 2021
0.1.0 Feb 27, 2021
0.0.0 Feb 25, 2021

#1544 in Text processing

22 downloads per month

MIT license

10KB
180 lines

anagram

crates.io Build and Test

A collection of anagram utility functions

Installation

You can install this crate by adding it to your Cargo.toml file

anagram = "0.3.0"

Examples

use anagram::{count, get_next, is_anagram, occurences};

fn main() {
  // count how many anagrams can be formed from a given word
  let anagram_count = count("ordeals");
  assert_eq!(anagram_count, 5040);

  // count the number of occurences of an anagram in a given word
  let occur = occurences("helloworldhello", "ll");
  assert_eq!(occur, 2);

  // check if a word is an anagram of another word
  let ok = is_anagram("rustiscool", "oolcsistru");
  assert_eq!(ok, true);

  // get the next lexicographically greater anagram
  let next = get_next("abcdefg");
  assert_eq!(next, "abcdegf");

  // get all anagrams of a word
  let mut word: String = String::from("abc");
  for _ in 0..count(&word) {
    // get next anagram
    word = get_next(&word);
    println!("{}", word);
  }
}

Dependencies

~215KB