[][src]Trait alphabet::Alphabet

pub trait Alphabet<'a> {
    type IterWord: Iterator<Item = String>;
    type IterWordCounting: Iterator<Item = String>;
    fn iter_words(&'a self) -> Self::IterWord;
fn iter_words_counting(&'a self) -> Self::IterWordCounting; }

Represents an alphabet.

Associated Types

type IterWord: Iterator<Item = String>

The iterator type used by iter_words().

type IterWordCounting: Iterator<Item = String>

The iterator type used by iter_words_counting().

Loading content...

Required methods

fn iter_words(&'a self) -> Self::IterWord

Allows to iterate over words of this alphabet (i.e. Self* in the mathematical sense). This returns an infinite iterator in most cases.

The words returned by the iterator are sorted lexicographically if the alphabet imposes any particular order on its symbols.

All alphabets generated by the alphabet!() macro impose an order on their symbols, namely the order in which the symbols are listed. Vec<char> uses the order of its contents. For other implementors, refer to the respective documentation.

The iterator is not infinite for empty alphabets. In that case, the only word is the empty word.

Examples

Basic usage:

use alphabet::*;

alphabet!(SCREAM = "A");
let mut words = SCREAM.iter_words();
assert_eq!(words.next().unwrap(), "");
assert_eq!(words.next().unwrap(), "A");
assert_eq!(words.next().unwrap(), "AA");
assert_eq!(words.next().unwrap(), "AAA");

Note that this can not be used for 'counting':

use alphabet::*;

alphabet!(BINARY = "01");
let mut words = BINARY.iter_words();
assert_eq!(words.next().unwrap(), "");
assert_eq!(words.next().unwrap(), "0");
assert_eq!(words.next().unwrap(), "1");

// Note that this does not 'count' in binary, it operates on symbols:
assert_eq!(words.next().unwrap(), "00");
assert_eq!(words.next().unwrap(), "01");
assert_eq!(words.next().unwrap(), "10");
assert_eq!(words.next().unwrap(), "11");
assert_eq!(words.next().unwrap(), "000");

Special case for empty alphabets:

use alphabet::*;

alphabet!(SILENCE = "");
let mut words = SILENCE.iter_words();
assert_eq!(words.next().unwrap(), "");
assert!(words.next().is_none());

fn iter_words_counting(&'a self) -> Self::IterWordCounting

Allows to iterate over 'count words' of this alphabet. This returns an infinite iterator in most cases.

'Count words' are words that are not empty and that do not start in the first symbol of the alphabet, unless they have length 1. Note that this requires the alphabet imposing an order on its symbols.

Intuitively speaking, 'count words' are numbers using the alphabet as digits.

All alphabets generated by the alphabet!() macro impose an order on their symbols, namely the order in which the symbols are listed. Vec<char> uses the order of its contents. For other implementors, refer to the respective documentation.

The iterator is not infinite for empty alphabets and singleton alphabets. In both cases, there are no valid 'count words' and the iterator is empty.

Panics

When Self imposes no order on its symbols.

Examples

Basic usage:

use alphabet::*;

alphabet!(BINARY = "01");
let mut words = BINARY.iter_words_counting();
assert_eq!(words.next().unwrap(), "0");
assert_eq!(words.next().unwrap(), "1");
assert_eq!(words.next().unwrap(), "10");
assert_eq!(words.next().unwrap(), "11");
assert_eq!(words.next().unwrap(), "100");

Special case empty and singleton alphabets:

use alphabet::*;

alphabet!(SILENCE = "");
let mut words = SILENCE.iter_words_counting();
assert!(words.next().is_none());
use alphabet::*;

alphabet!(SCREAM = "A");
let mut words = SCREAM.iter_words_counting();
assert!(words.next().is_none());
Loading content...

Implementations on Foreign Types

impl<'a> Alphabet<'a> for [char][src]

type IterWord = WordIterator<'a>

type IterWordCounting = CountingIterator<'a>

impl<'a> Alphabet<'a> for Vec<char>[src]

type IterWord = WordIterator<'a>

type IterWordCounting = CountingIterator<'a>

Loading content...

Implementors

Loading content...