|
Packit Service |
973b1a |
/* This may look like C code, but it is really -*- C++ -*- */
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Search algorithm.
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
Copyright (C) 1989-1998, 2000, 2002, 2009 Free Software Foundation, Inc.
|
|
Packit Service |
973b1a |
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
|
|
Packit Service |
973b1a |
and Bruno Haible <bruno@clisp.org>.
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
This file is part of GNU GPERF.
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
973b1a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
973b1a |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
973b1a |
(at your option) any later version.
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
973b1a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
973b1a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
973b1a |
GNU General Public License for more details.
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
973b1a |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
#ifndef search_h
|
|
Packit Service |
973b1a |
#define search_h 1
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
#include "keyword-list.h"
|
|
Packit Service |
973b1a |
#include "positions.h"
|
|
Packit Service |
973b1a |
#include "bool-array.h"
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
struct EquivalenceClass;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
class Search
|
|
Packit Service |
973b1a |
{
|
|
Packit Service |
973b1a |
public:
|
|
Packit Service |
973b1a |
Search (KeywordExt_List *list);
|
|
Packit Service |
973b1a |
~Search ();
|
|
Packit Service |
973b1a |
void optimize ();
|
|
Packit Service |
973b1a |
private:
|
|
Packit Service |
973b1a |
void prepare ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Computes the upper bound on the indices passed to asso_values[],
|
|
Packit Service |
973b1a |
assuming no alpha_increments. */
|
|
Packit Service |
973b1a |
unsigned int compute_alpha_size () const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Computes the unification rules between different asso_values[c],
|
|
Packit Service |
973b1a |
assuming no alpha_increments. */
|
|
Packit Service |
973b1a |
unsigned int * compute_alpha_unify () const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Initializes each keyword's _selchars array. */
|
|
Packit Service |
973b1a |
void init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify) const;
|
|
Packit Service |
973b1a |
/* Deletes each keyword's _selchars array. */
|
|
Packit Service |
973b1a |
void delete_selchars () const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Count the duplicate keywords that occur with a given set of positions. */
|
|
Packit Service |
973b1a |
unsigned int count_duplicates_tuple (const Positions& positions, const unsigned int *alpha_unify) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Find good key positions. */
|
|
Packit Service |
973b1a |
void find_positions ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Count the duplicate keywords that occur with the found set of positions. */
|
|
Packit Service |
973b1a |
unsigned int count_duplicates_tuple () const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Computes the upper bound on the indices passed to asso_values[]. */
|
|
Packit Service |
973b1a |
unsigned int compute_alpha_size (const unsigned int *alpha_inc) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Computes the unification rules between different asso_values[c]. */
|
|
Packit Service |
973b1a |
unsigned int * compute_alpha_unify (const Positions& positions, const unsigned int *alpha_inc) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Initializes each keyword's _selchars array. */
|
|
Packit Service |
973b1a |
void init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Count the duplicate keywords that occur with the given set of positions
|
|
Packit Service |
973b1a |
and a given alpha_inc[] array. */
|
|
Packit Service |
973b1a |
unsigned int count_duplicates_multiset (const unsigned int *alpha_inc) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Find good _alpha_inc[]. */
|
|
Packit Service |
973b1a |
void find_alpha_inc ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Initializes the asso_values[] related parameters. */
|
|
Packit Service |
973b1a |
void prepare_asso_values ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
EquivalenceClass * compute_partition (bool *undetermined) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
unsigned int count_possible_collisions (EquivalenceClass *partition, unsigned int c) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
bool unchanged_partition (EquivalenceClass *partition, unsigned int c) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Finds some _asso_values[] that fit. */
|
|
Packit Service |
973b1a |
void find_asso_values ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Computes a keyword's hash value, relative to the current _asso_values[],
|
|
Packit Service |
973b1a |
and stores it in keyword->_hash_value. */
|
|
Packit Service |
973b1a |
int compute_hash (KeywordExt *keyword) const;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Finds good _asso_values[]. */
|
|
Packit Service |
973b1a |
void find_good_asso_values ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Sorts the keyword list by hash value. */
|
|
Packit Service |
973b1a |
void sort ();
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
public:
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Linked list of keywords. */
|
|
Packit Service |
973b1a |
KeywordExt_List * _head;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Total number of keywords, counting duplicates. */
|
|
Packit Service |
973b1a |
int _total_keys;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Maximum length of the longest keyword. */
|
|
Packit Service |
973b1a |
int _max_key_len;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Minimum length of the shortest keyword. */
|
|
Packit Service |
973b1a |
int _min_key_len;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Whether the hash function includes the length. */
|
|
Packit Service |
973b1a |
bool _hash_includes_len;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* User-specified or computed key positions. */
|
|
Packit Service |
973b1a |
Positions _key_positions;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Adjustments to add to bytes add specific key positions. */
|
|
Packit Service |
973b1a |
unsigned int * _alpha_inc;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Size of alphabet. */
|
|
Packit Service |
973b1a |
unsigned int _alpha_size;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Alphabet character unification, either the identity or a mapping from
|
|
Packit Service |
973b1a |
upper case characters to lower case characters (and maybe more). */
|
|
Packit Service |
973b1a |
unsigned int * _alpha_unify;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Maximum _selchars_length over all keywords. */
|
|
Packit Service |
973b1a |
unsigned int _max_selchars_length;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Total number of duplicates that have been moved to _duplicate_link lists
|
|
Packit Service |
973b1a |
(not counting their representatives which stay on the main list). */
|
|
Packit Service |
973b1a |
int _total_duplicates;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Counts occurrences of each key set character.
|
|
Packit Service |
973b1a |
_occurrences[c] is the number of times that c occurs among the _selchars
|
|
Packit Service |
973b1a |
of a keyword. */
|
|
Packit Service |
973b1a |
int * _occurrences;
|
|
Packit Service |
973b1a |
/* Value associated with each character. */
|
|
Packit Service |
973b1a |
int * _asso_values;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
private:
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Length of _head list. Number of keywords, not counting duplicates. */
|
|
Packit Service |
973b1a |
int _list_len;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Exclusive upper bound for every _asso_values[c]. A power of 2. */
|
|
Packit Service |
973b1a |
unsigned int _asso_value_max;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Initial value for asso_values table. -1 means random. */
|
|
Packit Service |
973b1a |
int _initial_asso_value;
|
|
Packit Service |
973b1a |
/* Jump length when trying alternative values. 0 means random. */
|
|
Packit Service |
973b1a |
int _jump;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Maximal possible hash value. */
|
|
Packit Service |
973b1a |
int _max_hash_value;
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
/* Sparse bit vector for collision detection. */
|
|
Packit Service |
973b1a |
Bool_Array * _collision_detector;
|
|
Packit Service |
973b1a |
};
|
|
Packit Service |
973b1a |
|
|
Packit Service |
973b1a |
#endif
|