Main Page   Compound List   File List   Compound Members   File Members  

rr_libs/sih.c File Reference

Implementation of string-to-int32 hashing. More...

#include <stdio.h>
#include <sys/types.h>
#include "general.h"
#include "sih.h"
#include <stdlib.h>

Go to the source code of this file.

Defines

#define HASH_VERSION   940728
#define SIH_KEY(STRING, KEY)

Functions

int nearest_prime_up (int num)
sih_tsih_create (int initial_size, double max_occupancy, double growth_ratio, int warn_on_update)
void sih_add (sih_t *ht, char *string, int32 intval)
char sih_lookup (sih_t *ht, char *string, int32 *p_intval)
void * sih_val_write_to_file (sih_t *ht, FILE *fp, char *filename, int verbosity)
void * sih_val_read_from_file (sih_t *ht, FILE *fp, char *filename, int verbosity)


Detailed Description

Implementation of string-to-int32 hashing.

Definition in file sih.c.


Define Documentation

#define HASH_VERSION   940728
 

Definition at line 41 of file sih.c.

Referenced by sih_val_read_from_file(), and sih_val_write_to_file().

#define SIH_KEY STRING,
KEY   
 

Value:

{\
    int i = 0; \
    char *pstr = STRING; \
    KEY = 0; \
    do {KEY += *pstr++ << (0xF & --i);} while (*pstr);    \
}

Definition at line 42 of file sih.c.

Referenced by sih_add(), and sih_lookup().


Function Documentation

int nearest_prime_up int    num
 

return the nearest prime not smaller than 'num'

Definition at line 50 of file sih.c.

Referenced by sih_add(), and sih_create().

void sih_add sih_t   ht,
char *    string,
int32    intval
 

Add an entry to hash

Parameters:
ht  The hash table
string  Input: The string
intval  Output: The integer value

Definition at line 91 of file sih.c.

References fprintf(), free(), sih_t::growth_ratio, int32, intval, sih_slot_t::intval, sih_t::max_occupancy, nearest_prime_up(), sih_t::nentries, sih_t::nslots, quit(), rr_calloc(), SIH_KEY, sih_t::slots, sih_slot_t::string, and sih_t::warn_on_update.

Referenced by load_arpa_lm(), and read_wlist_into_siht().

sih_t* sih_create int    initial_size,
double    max_occupancy,
double    growth_ratio,
int    warn_on_update
 

Create a string to integer hash

Parameters:
initial_size  Initial size of the hash
warn_on_update  Whether warning is given in an update

Definition at line 69 of file sih.c.

References sih_t::growth_ratio, MAX, sih_t::max_occupancy, nearest_prime_up(), sih_t::nentries, sih_t::nslots, quit(), rr_calloc(), rr_malloc(), sih_t::slots, and sih_t::warn_on_update.

Referenced by load_arpa_lm(), and main().

char sih_lookup sih_t   ht,
char *    string,
int32   p_intval
 

Lookup the hash table

Parameters:
ht  The hash table
string  Input: the string
p_intval  Output: the pointer of an integer value

Definition at line 145 of file sih.c.

References int32, sih_slot_t::intval, sih_t::nslots, quit(), SIH_KEY, sih_t::slots, and sih_slot_t::string.

Referenced by compute_perplexity(), gen_fb_list(), load_arpa_lm(), main(), and validate().

void* sih_val_read_from_file sih_t   ht,
FILE *    fp,
char *    filename,
int    verbosity
 

Read the value from a file to a hash

Parameters:
ht  The hash table
fp  the file handle of the input
filename  the file name of the output
verbosity  verbosity of the this function

Definition at line 227 of file sih.c.

References fprintf(), sih_t::growth_ratio, HASH_VERSION, int32, sih_slot_t::intval, sih_t::max_occupancy, sih_t::nentries, sih_t::nslots, quit(), rr_calloc(), rr_fread(), rr_malloc(), sih_t::slots, sih_slot_t::string, verbosity, and sih_t::warn_on_update.

Referenced by load_lm(), and read_voc().

void* sih_val_write_to_file sih_t   ht,
FILE *    fp,
char *    filename,
int    verbosity
 

Read/Write from/to a file an (almost) ready-to-use hash table. The hash-table is a string->int mapping. All intvals are written out, whether or not they belong to active entries. All strings are writen out too, where an empty entry is represented in the file as a null string (null strings as entries are not allowed).

Parameters:
ht  The hash table
fp  the file handle of the output
filename  the file name of the output
verbosity  verbosity of the this function

Definition at line 181 of file sih.c.

References fprintf(), sih_t::growth_ratio, HASH_VERSION, int32, sih_slot_t::intval, sih_t::max_occupancy, sih_t::nentries, sih_t::nslots, quit(), rr_fwrite(), sih_t::slots, sih_slot_t::string, verbosity, and sih_t::warn_on_update.

Referenced by write_bin_lm().


Generated on Tue Dec 21 13:54:47 2004 by doxygen1.2.18