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

Move the search algorithm to search.h, search.cc.

This commit is contained in:
Bruno Haible
2002-11-26 12:48:39 +00:00
parent 122b13cc95
commit aca3f4abae
11 changed files with 747 additions and 864 deletions

76
src/search.h Normal file
View File

@@ -0,0 +1,76 @@
/* This may look like C code, but it is really -*- C++ -*- */
/* Search algorithm.
Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
This file is part of GNU GPERF.
GNU GPERF is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU GPERF is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef search_h
#define search_h 1
#include "keyword-list.h"
#include "vectors.h"
#include "bool-array.h"
class Search : public Vectors
{
public:
Search (KeywordExt_List *list);
~Search ();
void optimize ();
private:
void prepare ();
KeywordExt_List * merge (KeywordExt_List *list1, KeywordExt_List *list2);
KeywordExt_List * merge_sort (KeywordExt_List *head);
static int get_occurrence (KeywordExt *ptr);
static void set_determined (KeywordExt *ptr);
static bool already_determined (KeywordExt *ptr);
void reorder ();
int keyword_list_length ();
int max_key_length ();
int get_max_keysig_size ();
static int hash (KeywordExt *key_node);
static int compute_disjoint_union (const char *set_1, int size_1, const char *set_2, int size_2, char *set_3);
static void sort_set (char *union_set, int len);
bool affects_prev (char c, KeywordExt *curr);
void change (KeywordExt *prior, KeywordExt *curr);
void sort ();
public:
KeywordExt_List * _head; /* Points to the head of the linked list. */
int _total_keys; /* Total number of keys, counting duplicates. */
int _total_duplicates; /* Total number of duplicate hash values. */
int _max_key_len; /* Maximum length of the longest keyword. */
int _min_key_len; /* Minimum length of the shortest keyword. */
private:
int _list_len; /* Length of head's Key_List, not counting duplicates. */
bool _occurrence_sort; /* True if sorting by occurrence. */
bool _hash_sort; /* True if sorting by hash value. */
static bool _determined[MAX_ALPHA_SIZE]; /* Used in function reorder, below. */
int _num_done; /* Number of keywords processed without a collision. */
int _fewest_collisions; /* Records fewest # of collisions for asso value. */
int _max_hash_value; /* Maximum possible hash value. */
Bool_Array * _collision_detector;
int _size; /* Range of the hash table. */
void set_asso_max (int r) { _size = r; }
int get_asso_max () { return _size; }
};
#endif