Blame utf8trans/mtable.h

Packit e4b6da
/* 
Packit e4b6da
 * mtable.h
Packit e4b6da
 * 
Packit e4b6da
 * This module implements a sparse multi-level array.
Packit e4b6da
 * The indices of the array range from 0 to (2^n)-1, inclusive,
Packit e4b6da
 * and the n bits used for the addressing can be split
Packit e4b6da
 * into arbitrary groups of consecutive bits, 
Packit e4b6da
 * one group representing each level of the table.
Packit e4b6da
 * 
Packit e4b6da
 * This module is used in utf8trans to store
Packit e4b6da
 * the Unicode translation table, where the index
Packit e4b6da
 * can get as high as (2^31)-1, but usually the table
Packit e4b6da
 * stores only a few thousand entries scattered in blocks
Packit e4b6da
 * in the bottom 64k addresses.
Packit e4b6da
 *
Packit e4b6da
 * Each entry in the multi-level array is assumed
Packit e4b6da
 * to be of type void*.  If unassigned, the entry
Packit e4b6da
 * is the null pointer.
Packit e4b6da
 */
Packit e4b6da
Packit e4b6da
#ifndef MTABLE_H
Packit e4b6da
#define MTABLE_H
Packit e4b6da
Packit e4b6da
typedef unsigned int mtable_key;
Packit e4b6da
struct mtable {
Packit e4b6da
    int *exponents;
Packit e4b6da
    void *slots[1];
Packit e4b6da
};
Packit e4b6da
typedef struct mtable *mtable_t;
Packit e4b6da
Packit e4b6da
/* 
Packit e4b6da
 * Makes a new sparse multi-level array.
Packit e4b6da
 * 
Packit e4b6da
 * exponents is a list of positive integers which
Packit e4b6da
 * are the number of bits of addressing for each 
Packit e4b6da
 * level of the table.  The list is terminated
Packit e4b6da
 * by a single zero entry.  
Packit e4b6da
 *
Packit e4b6da
 * For example, for a 2^4 * 2^8 table (total 2^(4+8) entries), 
Packit e4b6da
 *  set exponents = [ 4, 8, 0 ].
Packit e4b6da
 *
Packit e4b6da
 * The most significant bits are listed first.
Packit e4b6da
 *
Packit e4b6da
 * All entries are initially unassigned (that is, they are NULL).
Packit e4b6da
 */
Packit e4b6da
mtable_t mtable_new(int *exponents);
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Deallocates a multi-level array created by mtable_delete.
Packit e4b6da
 */
Packit e4b6da
void mtable_delete(mtable_t mtable);
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Extends the given multi-level array by adding
Packit e4b6da
 * more bits of addressing.  The existing
Packit e4b6da
 * entries in the array are given a prefix of zero
Packit e4b6da
 * in the expanded address space.
Packit e4b6da
 */
Packit e4b6da
mtable_t mtable_extend(mtable_t mtab, int *exponents);
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Changes the entry at the given index to the given data
Packit e4b6da
 * value.
Packit e4b6da
 */
Packit e4b6da
void mtable_set(mtable_t mtable, mtable_key key, void *data);
Packit e4b6da
Packit e4b6da
/*
Packit e4b6da
 * Returns the entry at the given index.
Packit e4b6da
 */
Packit e4b6da
void *mtable_get(mtable_t mtable, mtable_key key);
Packit e4b6da
Packit e4b6da
#endif  /* !defined MTABLE_H */
Packit e4b6da