mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
Remove the global vectors. Move them to the class Search.
This commit is contained in:
@@ -62,7 +62,7 @@ SHELL = /bin/sh
|
||||
VPATH = $(srcdir)
|
||||
|
||||
OBJECTS = options.o main.o \
|
||||
hash-table.o bool-array.o read-line.o vectors.o version.o \
|
||||
hash-table.o bool-array.o read-line.o version.o \
|
||||
keyword.o keyword-list.o output.o input.o search.o
|
||||
LIBS = ../lib/libgp.a @GPERF_LIBM@
|
||||
CPPFLAGS = -I. -I$(srcdir)/../lib
|
||||
@@ -86,7 +86,6 @@ $(TARGETPROG): $(OBJECTS)
|
||||
# Dependencies.
|
||||
CONFIG_H = config.h
|
||||
VERSION_H = version.h
|
||||
VECTORS_H = vectors.h
|
||||
READ_LINE_H = read-line.h read-line.icc
|
||||
OPTIONS_H = options.h options.icc
|
||||
HASH_TABLE_H = hash-table.h
|
||||
@@ -102,8 +101,6 @@ options.o : options.cc $(OPTIONS_H) $(VECTORS_H) $(VERSION_H)
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/options.cc
|
||||
read-line.o : read-line.cc $(READ_LINE_H) $(OPTIONS_H)
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/read-line.cc
|
||||
vectors.o : vectors.cc $(VECTORS_H)
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/vectors.cc
|
||||
version.o : version.cc $(VERSION_H)
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(srcdir)/version.cc
|
||||
keyword.o : keyword.cc keyword.h
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
#ifndef keyword_h
|
||||
#define keyword_h 1
|
||||
|
||||
#include "vectors.h"
|
||||
|
||||
/* An instance of this class is a keyword, as specified in the input file. */
|
||||
struct Keyword
|
||||
{
|
||||
@@ -37,7 +35,7 @@ struct Keyword
|
||||
/* Data members defined immediately by the input file. */
|
||||
/* The keyword as a string, possibly containing NUL bytes. */
|
||||
const char *const _allchars;
|
||||
const int _allchars_length;
|
||||
int const _allchars_length;
|
||||
/* Additional stuff seen on the same line of the input file. */
|
||||
const char *const _rest;
|
||||
};
|
||||
|
||||
@@ -51,7 +51,6 @@ main (int argc, char *argv[])
|
||||
/* Initialize the key word list. */
|
||||
KeywordExt_Factory factory;
|
||||
Input inputter (&factory);
|
||||
Vectors::ALPHA_SIZE = (option[SEVENBIT] ? 128 : 256);
|
||||
inputter.read_keys ();
|
||||
/* We can cast the keyword list to KeywordExt_List* because its list
|
||||
elements were created by KeywordExt_Factory. */
|
||||
@@ -72,7 +71,9 @@ main (int argc, char *argv[])
|
||||
searcher._total_duplicates,
|
||||
searcher._max_key_len,
|
||||
searcher._min_key_len,
|
||||
&searcher);
|
||||
searcher._alpha_size,
|
||||
searcher._occurrences,
|
||||
searcher._asso_values);
|
||||
outputter.output ();
|
||||
|
||||
/* Check for write error on stdout. */
|
||||
|
||||
@@ -70,12 +70,14 @@ Output::Output (KeywordExt_List *head, const char *array_type,
|
||||
const char *return_type, const char *struct_tag,
|
||||
bool additional_code, const char *include_src,
|
||||
int total_keys, int total_duplicates, int max_key_len,
|
||||
int min_key_len, Vectors *v)
|
||||
int min_key_len, int alpha_size, const int *occurrences,
|
||||
const int *asso_values)
|
||||
: _head (head), _array_type (array_type), _return_type (return_type),
|
||||
_struct_tag (struct_tag), _additional_code (additional_code),
|
||||
_include_src (include_src), _total_keys (total_keys),
|
||||
_total_duplicates (total_duplicates), _max_key_len (max_key_len),
|
||||
_min_key_len (min_key_len), _v (v)
|
||||
_min_key_len (min_key_len), _alpha_size (alpha_size),
|
||||
_occurrences (occurrences), _asso_values (asso_values)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -453,14 +455,14 @@ Output::output_hash_function ()
|
||||
const_readonly_array,
|
||||
smallest_integral_type (_max_hash_value + 1));
|
||||
|
||||
for (int count = 0; count < _v->ALPHA_SIZE; count++)
|
||||
for (int count = 0; count < _alpha_size; count++)
|
||||
{
|
||||
if (count > 0)
|
||||
printf (",");
|
||||
if (!(count % max_column))
|
||||
printf ("\n ");
|
||||
printf ("%*d", field_width,
|
||||
_v->_occurrences[count] ? _v->_asso_values[count] : _max_hash_value + 1);
|
||||
_occurrences[count] ? _asso_values[count] : _max_hash_value + 1);
|
||||
}
|
||||
|
||||
printf ("\n"
|
||||
|
||||
10
src/output.h
10
src/output.h
@@ -27,7 +27,6 @@
|
||||
#define output_h 1
|
||||
|
||||
#include "keyword-list.h"
|
||||
#include "vectors.h"
|
||||
|
||||
/* OSF/1 cxx needs these forward declarations. */
|
||||
struct Output_Constants;
|
||||
@@ -36,7 +35,7 @@ struct Output_Compare;
|
||||
class Output
|
||||
{
|
||||
public:
|
||||
Output (KeywordExt_List *head, const char *array_type, const char *return_type, const char *struct_tag, bool additional_code, const char *include_src, int total_keys, int total_duplicates, int max_key_len, int min_key_len, Vectors *v);
|
||||
Output (KeywordExt_List *head, const char *array_type, const char *return_type, const char *struct_tag, bool additional_code, const char *include_src, int total_keys, int total_duplicates, int max_key_len, int min_key_len, int alpha_size, const int *occurrences, const int *asso_values);
|
||||
void output ();
|
||||
private:
|
||||
void compute_min_max ();
|
||||
@@ -75,7 +74,12 @@ private:
|
||||
int _min_hash_value;
|
||||
/* Maximum hash value for all keywords. */
|
||||
int _max_hash_value;
|
||||
Vectors * _v;
|
||||
/* Size of alphabet. */
|
||||
int const _alpha_size;
|
||||
/* Counts occurrences of each key set character. */
|
||||
const int * const _occurrences;
|
||||
/* Value associated with each character. */
|
||||
const int * const _asso_values;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,12 +36,14 @@ static const int TABLE_MULTIPLE = 10;
|
||||
#define POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X)))
|
||||
|
||||
Search::Search (KeywordExt_List *list)
|
||||
: _head (list)
|
||||
: _head (list),
|
||||
_alpha_size (option[SEVENBIT] ? 128 : 256),
|
||||
_occurrences (new int[_alpha_size]),
|
||||
_asso_values (new int[_alpha_size]),
|
||||
_determined (new bool[_alpha_size])
|
||||
{
|
||||
}
|
||||
|
||||
bool Search::_determined[MAX_ALPHA_SIZE];
|
||||
|
||||
void
|
||||
Search::prepare ()
|
||||
{
|
||||
@@ -529,7 +531,7 @@ Search::optimize ()
|
||||
{
|
||||
srand (reinterpret_cast<long>(time (0)));
|
||||
|
||||
for (int i = 0; i < ALPHA_SIZE; i++)
|
||||
for (int i = 0; i < _alpha_size; i++)
|
||||
_asso_values[i] = (rand () & asso_value_max - 1);
|
||||
}
|
||||
else
|
||||
@@ -537,7 +539,7 @@ Search::optimize ()
|
||||
int asso_value = option.get_initial_asso_value ();
|
||||
|
||||
if (asso_value) /* Initialize array if user requests non-zero default. */
|
||||
for (int i = ALPHA_SIZE - 1; i >= 0; i--)
|
||||
for (int i = _alpha_size - 1; i >= 0; i--)
|
||||
_asso_values[i] = asso_value & get_asso_max () - 1;
|
||||
}
|
||||
_max_hash_value = max_key_length () + get_asso_max () * get_max_keysig_size ();
|
||||
@@ -603,7 +605,7 @@ Search::~Search ()
|
||||
{
|
||||
fprintf (stderr, "\ndumping occurrence and associated values tables\n");
|
||||
|
||||
for (int i = 0; i < ALPHA_SIZE; i++)
|
||||
for (int i = 0; i < _alpha_size; i++)
|
||||
if (_occurrences[i])
|
||||
fprintf (stderr, "asso_values[%c] = %6d, occurrences[%c] = %6d\n",
|
||||
i, _asso_values[i], i, _occurrences[i]);
|
||||
|
||||
21
src/search.h
21
src/search.h
@@ -27,10 +27,9 @@
|
||||
#define search_h 1
|
||||
|
||||
#include "keyword-list.h"
|
||||
#include "vectors.h"
|
||||
#include "bool-array.h"
|
||||
|
||||
class Search : public Vectors
|
||||
class Search
|
||||
{
|
||||
public:
|
||||
Search (KeywordExt_List *list);
|
||||
@@ -40,16 +39,16 @@ 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);
|
||||
int get_occurrence (KeywordExt *ptr);
|
||||
void set_determined (KeywordExt *ptr);
|
||||
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);
|
||||
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);
|
||||
void sort_set (char *union_set, int len);
|
||||
bool affects_prev (char c, KeywordExt *curr);
|
||||
void change (KeywordExt *prior, KeywordExt *curr);
|
||||
void sort ();
|
||||
@@ -59,11 +58,17 @@ public:
|
||||
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. */
|
||||
/* Size of alphabet. */
|
||||
int const _alpha_size;
|
||||
/* Counts occurrences of each key set character. */
|
||||
int * const _occurrences;
|
||||
/* Value associated with each character. */
|
||||
int * const _asso_values;
|
||||
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. */
|
||||
bool * const _determined; /* 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. */
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/* Static class data members that are shared between several classes.
|
||||
Copyright (C) 1989-1998, 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. */
|
||||
|
||||
#include "vectors.h"
|
||||
|
||||
int Vectors::ALPHA_SIZE;
|
||||
int Vectors::_occurrences[MAX_ALPHA_SIZE];
|
||||
int Vectors::_asso_values[MAX_ALPHA_SIZE];
|
||||
@@ -1,39 +0,0 @@
|
||||
/* This may look like C code, but it is really -*- C++ -*- */
|
||||
|
||||
/* Static class data members that are shared between several classes via
|
||||
inheritance.
|
||||
|
||||
Copyright (C) 1989-1998, 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 vectors_h
|
||||
#define vectors_h 1
|
||||
|
||||
static const int MAX_ALPHA_SIZE = 256;
|
||||
|
||||
struct Vectors
|
||||
{
|
||||
static int ALPHA_SIZE; /* Size of alphabet. */
|
||||
static int _occurrences[MAX_ALPHA_SIZE]; /* Counts occurrences of each key set character. */
|
||||
static int _asso_values[MAX_ALPHA_SIZE]; /* Value associated with each character. */
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user