1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Completely new asso_values search algorithm.

This commit is contained in:
Bruno Haible
2003-03-18 10:22:37 +00:00
parent 40f37680ac
commit 6d268d095b
20 changed files with 1918 additions and 2117 deletions

View File

@@ -35,7 +35,7 @@ Keyword_List::Keyword_List (Keyword *car)
/* ------------------------- KeywordExt_List class ------------------------- */
/* Unused constructor. */
/* Constructor. */
KeywordExt_List::KeywordExt_List (KeywordExt *car)
: Keyword_List (car)
{

View File

@@ -48,7 +48,7 @@ protected:
class KeywordExt_List : public Keyword_List
{
public:
/* Unused constructor. */
/* Constructor. */
KeywordExt_List (KeywordExt *car);
/* Access to first element of list. */

View File

@@ -75,7 +75,6 @@ struct KeywordExt : public Keyword
void delete_selchars ();
/* Data members used by the algorithm. */
int _occurrence; /* Frequency of key set occurrences. */
int _hash_value; /* Hash value for the keyword. */
/* Data members used by the output routines. */

View File

@@ -195,13 +195,6 @@ Options::long_usage (FILE * stream) const
fprintf (stream,
" -D, --duplicates Handle keywords that hash to duplicate values. This\n"
" is useful for certain highly redundant keyword sets.\n");
fprintf (stream,
" -f, --fast=ITERATIONS Generate the gen-perf.hash function \"fast\". This\n"
" decreases gperf's running time at the cost of\n"
" minimizing generated table size. The numeric\n"
" argument represents the number of times to iterate\n"
" when resolving a collision. '0' means \"iterate by\n"
" the number of keywords\".\n");
fprintf (stream,
" -m, --multiple-iterations=ITERATIONS\n"
" Perform multiple choices of the -i and -j values,\n"
@@ -220,10 +213,6 @@ Options::long_usage (FILE * stream) const
fprintf (stream,
" -n, --no-strlen Do not include the length of the keyword when\n"
" computing the hash function.\n");
fprintf (stream,
" -o, --occurrence-sort Reorders input keys by frequency of occurrence of\n"
" the key sets. This should decrease the search time\n"
" dramatically.\n");
fprintf (stream,
" -r, --random Utilizes randomness to initialize the associated\n"
" values table.\n");
@@ -429,7 +418,6 @@ Options::Options ()
_input_file_name (NULL),
_output_file_name (NULL),
_language (NULL),
_iterations (0),
_jump (DEFAULT_JUMP_VALUE),
_initial_asso_value (0),
_asso_iterations (0),
@@ -454,14 +442,12 @@ Options::~Options ()
{
fprintf (stderr, "\ndumping Options:"
"\nDEBUG is.......: %s"
"\nORDER is.......: %s"
"\nTYPE is........: %s"
"\nRANDOM is......: %s"
"\nSWITCH is......: %s"
"\nNOLENGTH is....: %s"
"\nLENTABLE is....: %s"
"\nDUP is.........: %s"
"\nFAST is........: %s"
"\nCOMP is........: %s"
"\nNOTYPE is......: %s"
"\nGLOBAL is......: %s"
@@ -473,8 +459,6 @@ Options::~Options ()
"\nENUM is........: %s"
"\nINCLUDE is.....: %s"
"\nSEVENBIT is....: %s"
"\nOPT_CHOICE is..: %s"
"\niterations = %d"
"\nlookup function name = %s"
"\nhash function name = %s"
"\nword list name = %s"
@@ -487,14 +471,12 @@ Options::~Options ()
"\ndelimiters = %s"
"\nnumber of switch statements = %d\n",
_option_word & DEBUG ? "enabled" : "disabled",
_option_word & ORDER ? "enabled" : "disabled",
_option_word & TYPE ? "enabled" : "disabled",
_option_word & RANDOM ? "enabled" : "disabled",
_option_word & SWITCH ? "enabled" : "disabled",
_option_word & NOLENGTH ? "enabled" : "disabled",
_option_word & LENTABLE ? "enabled" : "disabled",
_option_word & DUP ? "enabled" : "disabled",
_option_word & FAST ? "enabled" : "disabled",
_option_word & COMP ? "enabled" : "disabled",
_option_word & NOTYPE ? "enabled" : "disabled",
_option_word & GLOBAL ? "enabled" : "disabled",
@@ -506,8 +488,6 @@ Options::~Options ()
_option_word & ENUM ? "enabled" : "disabled",
_option_word & INCLUDE ? "enabled" : "disabled",
_option_word & SEVENBIT ? "enabled" : "disabled",
_option_word & OPT_CHOICE ? "enabled" : "disabled",
_iterations,
_function_name, _hash_name, _wordlist_name, _slot_name,
_initializer_suffix, _asso_iterations, _jump, _size_multiple,
_initial_asso_value, _delimiters, _total_switches);
@@ -711,15 +691,7 @@ Options::parse_options (int argc, char *argv[])
break;
}
case 'f': /* Generate the hash table "fast". */
{
_option_word |= FAST;
if ((_iterations = atoi (/*getopt*/optarg)) < 0)
{
fprintf (stderr, "iterations value must not be negative, assuming 0\n");
_iterations = 0;
}
break;
}
break; /* Not needed any more. */
case 'F':
{
_initializer_suffix = /*getopt*/optarg;
@@ -861,15 +833,9 @@ Options::parse_options (int argc, char *argv[])
break;
}
case 'o': /* Order input by frequency of key set occurrence. */
{
_option_word |= ORDER;
break;
}
break; /* Not needed any more. */
case 'O': /* Optimized choice during collision resolution. */
{
_option_word |= OPT_CHOICE;
break;
}
break; /* Not needed any more. */
case 'p': /* Generated lookup function a pointer instead of int. */
break; /* This is now the default. */
case 'r': /* Utilize randomness to initialize the associated values table. */

View File

@@ -39,72 +39,63 @@ enum Option_Type
/* Enable debugging (prints diagnostics to stderr). */
DEBUG = 1 << 0,
/* Apply ordering heuristic to speed-up search time. */
ORDER = 1 << 1,
/* Use the given key positions. */
POSITIONS = 1 << 2,
POSITIONS = 1 << 1,
/* Use all characters in hash function. */
ALLCHARS = 1 << 3,
ALLCHARS = 1 << 2,
/* Handle user-defined type structured keyword input. */
TYPE = 1 << 4,
TYPE = 1 << 3,
/* Randomly initialize the associated values table. */
RANDOM = 1 << 5,
RANDOM = 1 << 4,
/* Generate switch output to save space. */
SWITCH = 1 << 6,
SWITCH = 1 << 5,
/* Don't include keyword length in hash computations. */
NOLENGTH = 1 << 7,
NOLENGTH = 1 << 6,
/* Generate a length table for string comparison. */
LENTABLE = 1 << 8,
LENTABLE = 1 << 7,
/* Handle duplicate hash values for keywords. */
DUP = 1 << 9,
/* Generate the hash function "fast". */
FAST = 1 << 10,
DUP = 1 << 8,
/* Don't include user-defined type definition in output -- it's already
defined elsewhere. */
NOTYPE = 1 << 11,
NOTYPE = 1 << 9,
/* Generate strncmp rather than strcmp. */
COMP = 1 << 12,
COMP = 1 << 10,
/* Make the keyword table a global variable. */
GLOBAL = 1 << 13,
GLOBAL = 1 << 11,
/* Make the generated tables readonly (const). */
CONST = 1 << 14,
CONST = 1 << 12,
/* Generate K&R C code: no prototypes, no const. */
KRC = 1 << 15,
KRC = 1 << 13,
/* Generate C code: no prototypes, but const (user can #define it away). */
C = 1 << 16,
C = 1 << 14,
/* Generate ISO/ANSI C code: prototypes and const, but no class. */
ANSIC = 1 << 17,
ANSIC = 1 << 15,
/* Generate C++ code: prototypes, const, class, inline, enum. */
CPLUSPLUS = 1 << 18,
CPLUSPLUS = 1 << 16,
/* Use enum for constants. */
ENUM = 1 << 19,
ENUM = 1 << 17,
/* Generate #include statements. */
INCLUDE = 1 << 20,
INCLUDE = 1 << 18,
/* Assume 7-bit, not 8-bit, characters. */
SEVENBIT = 1 << 21,
/* Apply optimized collision resolution to speed-up search time. */
OPT_CHOICE = 1 << 22
SEVENBIT = 1 << 19
};
/* Class manager for gperf program Options. */
@@ -140,9 +131,6 @@ public:
/* Sets the output language, if not already set. */
void set_language (const char *language);
/* Returns the iterations value. */
int get_iterations () const;
/* Returns the jump value. */
int get_jump () const;
@@ -222,9 +210,6 @@ private:
/* The output language. */
const char * _language;
/* Amount to iterate when a collision occurs. */
int _iterations;
/* Jump length when trying alternative values. */
int _jump;

View File

@@ -51,13 +51,6 @@ Options::get_output_file_name () const
return _output_file_name;
}
/* Returns the iterations value. */
INLINE int
Options::get_iterations () const
{
return _iterations;
}
/* Returns the jump value. */
INLINE int
Options::get_jump () const

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,8 @@
#include "positions.h"
#include "bool-array.h"
struct EquivalenceClass;
class Search
{
public:
@@ -62,16 +64,6 @@ private:
void prepare ();
/* Computes the sum of occurrences of the _selchars of a keyword. */
int compute_occurrence (KeywordExt *ptr) const;
/* Auxiliary functions used by Search::reorder(). */
void clear_determined ();
void set_determined (KeywordExt *keyword);
bool already_determined (KeywordExt *keyword) const;
/* Reorders the keyword list so as to minimize search times. */
void reorder ();
/* Returns the length of keyword list. */
int keyword_list_length () const;
@@ -83,30 +75,20 @@ private:
/* Initializes the asso_values[] related parameters. */
void prepare_asso_values ();
/* Puts a first guess into asso_values[]. */
void init_asso_values ();
EquivalenceClass * compute_partition (bool *undetermined) const;
unsigned int count_possible_collisions (EquivalenceClass *partition, unsigned int c) const;
bool unchanged_partition (EquivalenceClass *partition, unsigned int c) const;
/* Finds some _asso_values[] that fit. */
void find_asso_values ();
/* Computes a keyword's hash value, relative to the current _asso_values[],
and stores it in keyword->_hash_value. */
int compute_hash (KeywordExt *keyword) const;
/* Computes the frequency of occurrence of a character among the keywords
up to the given keyword. */
unsigned int compute_occurrence (unsigned int c, KeywordExt *curr) const;
/* Sorts the given set in increasing frequency of _occurrences[]. */
void sort_by_occurrence (unsigned int *set, unsigned int len) const;
/* Sorts the given set in increasing frequency of occurrences among the
keywords up to the given keyword. */
void sort_by_occurrence (unsigned int *set, unsigned int len, KeywordExt *curr) const;
bool has_collisions (KeywordExt *curr);
KeywordExt * collision_prior_to (KeywordExt *curr);
/* Finds some _asso_values[] that fit. */
void find_asso_values ();
/* Finds good _asso_values[]. */
void find_good_asso_values ();
@@ -152,9 +134,6 @@ private:
/* Length of _head list. Number of keywords, not counting duplicates. */
int _list_len;
/* Vector used during Search::reorder(). */
bool * _determined;
/* Exclusive upper bound for every _asso_values[c]. A power of 2. */
unsigned int _asso_value_max;