Crate anagram[][src]

A collection of anagram utility functions

Installation

Add anagram = 0.3.0 to your Cargo.toml

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);
  }
}

Functions

count

Count the number of anagrams that can be formed from a word

get_next

Get the next lexicographically greater permutation This function will return either the next greater permutation or the lexicographically smallest permutation if the given word is the lexicographically greatest permutation Examples: “abc” -> “acb” “cba” -> “abc”

is_anagram

Check if a word is an anagram of another word

occurences

Count the number of occurences of an anagram in a word