libuproc  1.2.0
Data Structures | Enumerations | Functions
object uproc_ecurve

Evolutionary Curve. More...

Data Structures

struct  uproc_ecurve_suffixentry
 Pair of suffix and family. More...
 
struct  uproc_ecurve
 Evolutionary Curve. More...
 

Enumerations

enum  uproc_ecurve_format {
  UPROC_ECURVE_PLAIN,
  UPROC_ECURVE_BINARY
}
 Storage format. More...
 
enum  {
  UPROC_ECURVE_EXACT,
  UPROC_ECURVE_INEXACT,
  UPROC_ECURVE_OOB
}
 Lookup return codes. More...
 

Functions

uproc_ecurveuproc_ecurve_create (const char *alphabet, size_t suffix_count)
 Create ecurve object. More...
 
void uproc_ecurve_destroy (uproc_ecurve *ecurve)
 Destroy ecurve object. More...
 
int uproc_ecurve_add_prefix (uproc_ecurve *ecurve, uproc_prefix pfx, uproc_list *suffixes)
 Add a prefix entry. More...
 
int uproc_ecurve_finalize (uproc_ecurve *ecurve)
 Finalize ecurve. More...
 
int uproc_ecurve_lookup (const uproc_ecurve *ecurve, const struct uproc_word *word, struct uproc_word *lower_neighbour, uproc_family *lower_class, struct uproc_word *upper_neighbour, uproc_family *upper_class)
 Find the closest neighbours of a word in the ecurve. More...
 
uproc_alphabetuproc_ecurve_alphabet (const uproc_ecurve *ecurve)
 Return the internal alphabet. More...
 
uproc_ecurveuproc_ecurve_loads (enum uproc_ecurve_format format, uproc_io_stream *stream)
 Load ecurve from stream. More...
 
uproc_ecurveuproc_ecurve_load (enum uproc_ecurve_format format, enum uproc_io_type iotype, const char *pathfmt,...)
 Load ecurve from file. More...
 
uproc_ecurveuproc_ecurve_loadp (enum uproc_ecurve_format format, enum uproc_io_type iotype, void(*progress)(double), const char *pathfmt,...)
 Load ecurve from file. More...
 
uproc_ecurveuproc_ecurve_loadv (enum uproc_ecurve_format format, enum uproc_io_type iotype, const char *pathfmt, va_list ap)
 Load ecurve from file. More...
 
uproc_ecurveuproc_ecurve_loadpv (enum uproc_ecurve_format format, enum uproc_io_type iotype, void(*progress)(double), const char *pathfmt, va_list ap)
 Load ecurve from file. More...
 
int uproc_ecurve_stores (const uproc_ecurve *ecurve, enum uproc_ecurve_format format, uproc_io_stream *stream)
 Store ecurve to stream. More...
 
int uproc_ecurve_storeps (const uproc_ecurve *ecurve, enum uproc_ecurve_format format, void(*progress)(double), uproc_io_stream *stream)
 Store ecurve to stream. More...
 
int uproc_ecurve_store (const uproc_ecurve *ecurve, enum uproc_ecurve_format format, enum uproc_io_type iotype, const char *pathfmt,...)
 Store ecurve to file. More...
 
int uproc_ecurve_storep (const uproc_ecurve *ecurve, enum uproc_ecurve_format format, enum uproc_io_type iotype, void(*progress)(double), const char *pathfmt,...)
 Store ecurve to file. More...
 
int uproc_ecurve_storev (const uproc_ecurve *ecurve, enum uproc_ecurve_format format, enum uproc_io_type iotype, const char *pathfmt, va_list ap)
 Store ecurve to file. More...
 
int uproc_ecurve_storepv (const uproc_ecurve *ecurve, enum uproc_ecurve_format format, enum uproc_io_type iotype, void(*progress)(double), const char *pathfmt, va_list ap)
 Store ecurve to file. More...
 
uproc_ecurveuproc_ecurve_mmap (const char *pathfmt,...)
 Map a file to an ecurve. More...
 
uproc_ecurveuproc_ecurve_mmapv (const char *pathfmt, va_list ap)
 Store ecurve to file. More...
 
void uproc_ecurve_munmap (uproc_ecurve *ecurve)
 Release mapping and close the underlying file descriptor. More...
 
int uproc_ecurve_mmap_store (const uproc_ecurve *ecurve, const char *pathfmt,...)
 Store ecurve in a format suitable for uproc_ecurve_mmap() More...
 
int uproc_ecurve_mmap_storev (const uproc_ecurve *ecurve, const char *pathfmt, va_list ap)
 Store ecurve to mmap file. More...
 

Detailed Description

Evolutionary Curve.

Enumeration Type Documentation

Storage format.

Enumerator
UPROC_ECURVE_PLAIN 

Portable plain text file.

UPROC_ECURVE_BINARY 

Machine-dependent binary format.

anonymous enum

Lookup return codes.

Enumerator
UPROC_ECURVE_EXACT 

Exact match.

UPROC_ECURVE_INEXACT 

No exact match.

UPROC_ECURVE_OOB 

Out of bounds.

Function Documentation

uproc_ecurve* uproc_ecurve_create ( const char *  alphabet,
size_t  suffix_count 
)

Create ecurve object.

Parameters
alphabetstring to initialize the ecurve's alphabet (see uproc_alphabet_init())
suffix_countnumber of entries in the suffix table
void uproc_ecurve_destroy ( uproc_ecurve ecurve)

Destroy ecurve object.

int uproc_ecurve_add_prefix ( uproc_ecurve ecurve,
uproc_prefix  pfx,
uproc_list suffixes 
)

Add a prefix entry.

Adds the prefix pfx and the suffix/family pairs in the suffixes list to the ecurve.

The argument to ecurve must be an ecurve fulfilling the following conditions:

Because building is done incrementally, the pfx argument needs to be greater than it was in the previous call to this function.

The suffixes argument must be a List with at least one element of type uproc_ecurve_suffixentry.

Note
If this function is used on an ecurve that does not meet the conditions above, the result will be a broken ecurve.

Example

1 int add_entries(uproc_ecurve *ec, uproc_prefix p,
2  uproc_suffix *s, uproc_family *f, int n)
3 {
4  int i, res;
5  struct uproc_ecurve_suffixentry e;
6  uproc_list *list = uproc_list_create(sizeof e);
7  for (i = 0; i < n; i++) {
8  e.suffix = s[i];
9  e.family = f[i];
10  res = uproc_list_append(list, &e);
11  if (res) {
12  // handle error
13  }
14  }
15  res = uproc_ecurve_add_prefix(ec, p, list);
16  uproc_list_destroy(list);
17  return res;
18 }
int uproc_ecurve_finalize ( uproc_ecurve ecurve)

Finalize ecurve.

Finalizes an ecurve that was built using uproc_ecurve_add_prefix(). This function must be called on a newly-constructed ecurve before it can be used.

int uproc_ecurve_lookup ( const uproc_ecurve ecurve,
const struct uproc_word word,
struct uproc_word lower_neighbour,
uproc_family lower_class,
struct uproc_word upper_neighbour,
uproc_family upper_class 
)

Find the closest neighbours of a word in the ecurve.

NOTE: ecurve may not be empty.

If word was found exactly as it it in the ecurve, UPROC_ECURVE_EXACT will be returned; if word is "outside" of the ecurve (i.e. its prefix is less than than the smalles or greater than the largest stored non-empty prefix), UPROC_ECURVE_OOB will be returned. In both cases, the objects pointed to by upper_neighbour and upper_class will be set equal to their lower_... counterparts.

In case of an inexact match, UPROC_ECURVE_INEXACT will be returned, lower_... and their upper_... counterparts will differ.

Parameters
ecurveecurve object
wordword to search
lower_neighbourOUT: lower neighbour word
lower_classOUT: class of the lower neighbour
upper_neighbourOUT: upper neighbour word
upper_classOUT: class of the upper neighbour
Returns
UPROC_ECURVE_EXACT, UPROC_ECURVE_OOB or UPROC_ECURVE_INEXACT as described above.
uproc_alphabet* uproc_ecurve_alphabet ( const uproc_ecurve ecurve)

Return the internal alphabet.

uproc_ecurve* uproc_ecurve_loads ( enum uproc_ecurve_format  format,
uproc_io_stream stream 
)

Load ecurve from stream.

Similar to uproc_ecurve_load(), but reads the data from an already opened file stream.

uproc_ecurve* uproc_ecurve_load ( enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
const char *  pathfmt,
  ... 
)

Load ecurve from file.

Opens a file for reading, allocates a new uproc_ecurve object and parses the data in the file using the given format.

If libecurve is compiled on a system that supports mmap(), calling this function with UPROC_ECURVE_BINARY as the format argument is equivalent to using uproc_ecurve_mmap().

Parameters
formatformat to use, see uproc_ecurve_format
iotypeIO type, see uproc_io_type
pathfmtprintf format string for file path
...format string arguments
uproc_ecurve* uproc_ecurve_loadp ( enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
void(*)(double)  progress,
const char *  pathfmt,
  ... 
)

Load ecurve from file.

Like uproc_ecurve_load(), but periodically calls progress to report the current progress (in percent).

uproc_ecurve* uproc_ecurve_loadv ( enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
const char *  pathfmt,
va_list  ap 
)

Load ecurve from file.

Like uproc_ecurve_load(), but with a va_list instead of a variable number of arguments.

uproc_ecurve* uproc_ecurve_loadpv ( enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
void(*)(double)  progress,
const char *  pathfmt,
va_list  ap 
)

Load ecurve from file.

Like uproc_ecurve_loadp(), but with a va_list instead of a variable number of arguments.

int uproc_ecurve_stores ( const uproc_ecurve ecurve,
enum uproc_ecurve_format  format,
uproc_io_stream stream 
)

Store ecurve to stream.

Similar to uproc_ecurve_store(), but writes the data to an already opened file stream.

int uproc_ecurve_storeps ( const uproc_ecurve ecurve,
enum uproc_ecurve_format  format,
void(*)(double)  progress,
uproc_io_stream stream 
)

Store ecurve to stream.

Similar to uproc_ecurve_storep(), but writes the data to an already opened file stream.

int uproc_ecurve_store ( const uproc_ecurve ecurve,
enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
const char *  pathfmt,
  ... 
)

Store ecurve to file.

Stores a uproc_ecurve object to a file using the given format.

If libecurve is compiled on a system that supports mmap(), calling this function with UPROC_ECURVE_BINARY as the format argument is equivalent to using uproc_ecurve_mmap_store().

Parameters
ecurvepointer to ecurve to store
formatformat to use, see uproc_ecurve_format
iotypeIO type, see uproc_io_type
pathfmtprintf format string for file path
...format string arguments
int uproc_ecurve_storep ( const uproc_ecurve ecurve,
enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
void(*)(double)  progress,
const char *  pathfmt,
  ... 
)

Store ecurve to file.

Like uproc_ecurve_store(), but periodically calls progress to report the current progress (in percent).

int uproc_ecurve_storev ( const uproc_ecurve ecurve,
enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
const char *  pathfmt,
va_list  ap 
)

Store ecurve to file.

Like uproc_ecurve_store(), but with a va_list instead of a variable number of arguments.

int uproc_ecurve_storepv ( const uproc_ecurve ecurve,
enum uproc_ecurve_format  format,
enum uproc_io_type  iotype,
void(*)(double)  progress,
const char *  pathfmt,
va_list  ap 
)

Store ecurve to file.

Like uproc_ecurve_storep(), but with a va_list instead of a variable number of arguments.

uproc_ecurve* uproc_ecurve_mmap ( const char *  pathfmt,
  ... 
)

Map a file to an ecurve.

The file must have been created by uproc_ecurve_mmap_store(), preferably on the same machine.

Parameters
pathfmtprintf format string for file path
...format string arguments
uproc_ecurve* uproc_ecurve_mmapv ( const char *  pathfmt,
va_list  ap 
)

Store ecurve to file.

Like uproc_ecurve_store(), but with a va_list instead of a variable number of arguments.

void uproc_ecurve_munmap ( uproc_ecurve ecurve)

Release mapping and close the underlying file descriptor.

Parameters
ecurveecurve mapped with uproc_mmap_map()
int uproc_ecurve_mmap_store ( const uproc_ecurve ecurve,
const char *  pathfmt,
  ... 
)

Store ecurve in a format suitable for uproc_ecurve_mmap()

Identical to uproc_ecurve_store() with UPROC_ECURVE_BINARY

Parameters
ecurveecurve to store
pathfmtprintf format string for file path
...format string arguments
int uproc_ecurve_mmap_storev ( const uproc_ecurve ecurve,
const char *  pathfmt,
va_list  ap 
)

Store ecurve to mmap file.

Like uproc_ecurve_mmap_store(), but with a va_list instead of a variable number of arguments.