libdatrie 0.2.13

Typedefs | Functions
alpha-map.h File Reference

AlphaMap data type and functions. More...

## Typedefs
typedef struct _AlphaMap | AlphaMap
| AlphaMap data type.

## Functions
AlphaMap * | alpha_map_new (void)
| Create new alphabet map. More...
AlphaMap * | alpha_map_clone (const AlphaMap *a_map)
| Create a clone of alphabet map. More...
void | alpha_map_free (AlphaMap *alpha_map)
| Free an alphabet map object. More...
int | alpha_map_add_range (AlphaMap *alpha_map, AlphaChar begin, AlphaChar end)
| Add a range to alphabet map. More...
int | alpha_char_strlen (const AlphaChar *str)
| Alphabet string length. More...
int | alpha_char_strcmp (const AlphaChar *str1, const AlphaChar *str2)
| Compare alphabet strings. More...

## Detailed Description

AlphaMap data type and functions.

AlphaMap is a mapping between AlphaChar and TrieChar. AlphaChar is the alphabet character used in words of a target language, while TrieChar is a small integer with packed range of values and is actually used in trie state transition calculations.

Since double-array trie relies on sparse state transition table, a small set of input characters can make the table small, i.e. with small number of columns. But in real life, alphabet characters can be of non-continuous range of values. The unused slots between them can waste the space in the table, and can increase the chance of unused array cells.

AlphaMap is thus defined for mapping between non-continuous ranges of values of AlphaChar and packed and continuous range of Triechar.

In this implementation, TrieChar is defined as a single-byte integer, which means the largest AlphaChar set that is supported is of 255 values, as the special value of 0 is reserved for null-termination code.

## Function Documentation

## ◆ alpha_char_strcmp()

int alpha_char_strcmp | ( | const AlphaChar * | str1,
|  | const AlphaChar * | str2
| ) |  |

Compare alphabet strings.

Parameters

  str1,str2 | : the arrays of null-terminated AlphaChar strings to compare

Returns
  negative if str1 < str2; 0 if str1 == str2; positive if str1 > str2

Available since: 0.2.7

## ◆ alpha_char_strlen()

int alpha_char_strlen | ( | const AlphaChar * | str | ) |

Alphabet string length.

Parameters

  str | : the array of null-terminated AlphaChar string to measure

Returns
  the total characters in str.

## ◆ alpha_map_add_range()

int alpha_map_add_range | ( | AlphaMap * | alpha_map,
|  | AlphaChar | begin,
|  | AlphaChar | end
| ) |  |

Add a range to alphabet map.

Parameters

  alpha_map | : the alphabet map object
  begin | : the first character of the range
  end | : the last character of the range

Returns
  0 on success, non-zero on failure

Add a range of character codes from begin to end to the alphabet set.

## ◆ alpha_map_clone()

AlphaMap * alpha_map_clone | ( | const AlphaMap * | a_map | ) |

Create a clone of alphabet map.

Parameters

  a_map | : the source alphabet map to clone

Returns
  a pointer to the alphabet map clone, NULL on failure

The created object must be freed with alpha_map_free().

## ◆ alpha_map_free()

void alpha_map_free | ( | AlphaMap * | alpha_map | ) |

Free an alphabet map object.

Parameters

  alpha_map | : the alphabet map object to free

Destruct the alpha_map and free its allocated memory.

## ◆ alpha_map_new()

AlphaMap * alpha_map_new | ( | void |  | ) |

Create new alphabet map.

Returns
  a pointer to the newly created alphabet map, NULL on failure

Create a new empty alphabet map. The map contents can then be added with alpha_map_add_range().

The created object must be freed with alpha_map_free().