mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 21:19:24 +00:00
Improve debugging output.
This commit is contained in:
13
ChangeLog
13
ChangeLog
@@ -1,5 +1,18 @@
|
|||||||
2002-12-04 Bruno Haible <bruno@clisp.org>
|
2002-12-04 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
|
Improve debugging output.
|
||||||
|
* src/hash-table.h (Hash_Table::dump): New method.
|
||||||
|
* src/hash-table.cc (Hash_Table::dump): New method, extracted from
|
||||||
|
destructor.
|
||||||
|
(Hash_Table::~Hash_Table): No longer print the contents.
|
||||||
|
* src/positions.h (PositionReverseIterator): New class.
|
||||||
|
* src/positions.icc (PositionReverseIterator::PositionReverseIterator,
|
||||||
|
PositionReverseIterator::next): New methods.
|
||||||
|
* src/search.cc (Search::find_positions): If debugging, print the
|
||||||
|
result.
|
||||||
|
(Search::find_alpha_inc): If debugging, print the result.
|
||||||
|
(Search::prepare): Explicitly dump the hash table's contents here.
|
||||||
|
|
||||||
Portability fixes.
|
Portability fixes.
|
||||||
* src/positions.h (Positions::LASTCHAR, Positions::MAX_KEY_POS,
|
* src/positions.h (Positions::LASTCHAR, Positions::MAX_KEY_POS,
|
||||||
PositionIterator::EOS): Define as compile-time constants using enum.
|
PositionIterator::EOS): Define as compile-time constants using enum.
|
||||||
|
|||||||
@@ -85,8 +85,13 @@ Hash_Table::Hash_Table (unsigned int size, bool ignore_length)
|
|||||||
/* Destructor. */
|
/* Destructor. */
|
||||||
Hash_Table::~Hash_Table ()
|
Hash_Table::~Hash_Table ()
|
||||||
{
|
{
|
||||||
if (option[DEBUG])
|
delete[] _table;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
/* Print the table's contents. */
|
||||||
|
void
|
||||||
|
Hash_Table::dump () const
|
||||||
|
{
|
||||||
int field_width;
|
int field_width;
|
||||||
|
|
||||||
field_width = 0;
|
field_width = 0;
|
||||||
@@ -117,8 +122,6 @@ Hash_Table::~Hash_Table ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "\nend dumping hash table\n\n");
|
fprintf (stderr, "\nend dumping hash table\n\n");
|
||||||
}
|
|
||||||
delete[] _table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compares two items. */
|
/* Compares two items. */
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public:
|
|||||||
/* Attempts to insert ITEM in the table. If there is already an equal
|
/* Attempts to insert ITEM in the table. If there is already an equal
|
||||||
entry in it, returns it. Otherwise inserts ITEM and returns NULL. */
|
entry in it, returns it. Otherwise inserts ITEM and returns NULL. */
|
||||||
KeywordExt * insert (KeywordExt *item);
|
KeywordExt * insert (KeywordExt *item);
|
||||||
|
/* Print the table's contents. */
|
||||||
|
void dump () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Vector of entries. */
|
/* Vector of entries. */
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
class Positions
|
class Positions
|
||||||
{
|
{
|
||||||
friend class PositionIterator;
|
friend class PositionIterator;
|
||||||
|
friend class PositionReverseIterator;
|
||||||
public:
|
public:
|
||||||
/* Denotes the last char of a keyword, depending on the keyword's length. */
|
/* Denotes the last char of a keyword, depending on the keyword's length. */
|
||||||
enum { LASTCHAR = 0 };
|
enum { LASTCHAR = 0 };
|
||||||
@@ -99,6 +100,26 @@ private:
|
|||||||
unsigned int _index;
|
unsigned int _index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* This class denotes an iterator in reverse direction through a set of
|
||||||
|
byte positions. */
|
||||||
|
|
||||||
|
class PositionReverseIterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/* Initializes an iterator through POSITIONS. */
|
||||||
|
PositionReverseIterator (Positions const& positions);
|
||||||
|
|
||||||
|
/* End of iteration marker. */
|
||||||
|
enum { EOS = -1 };
|
||||||
|
|
||||||
|
/* Retrieves the next position, or EOS past the end. */
|
||||||
|
int next ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Positions& _set;
|
||||||
|
unsigned int _index;
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __OPTIMIZE__
|
#ifdef __OPTIMIZE__
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -137,3 +137,20 @@ PositionIterator::next ()
|
|||||||
{
|
{
|
||||||
return (_index < _set._size ? _set._positions[_index++] : EOS);
|
return (_index < _set._size ? _set._positions[_index++] : EOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------- Class PositionReverseIterator --------------------- */
|
||||||
|
|
||||||
|
/* Initializes an iterator through POSITIONS. */
|
||||||
|
INLINE
|
||||||
|
PositionReverseIterator::PositionReverseIterator (Positions const& positions)
|
||||||
|
: _set (positions),
|
||||||
|
_index (_set._size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieves the next position, or EOS past the end. */
|
||||||
|
INLINE int
|
||||||
|
PositionReverseIterator::next ()
|
||||||
|
{
|
||||||
|
return (_index > 0 ? _set._positions[--_index] : EOS);
|
||||||
|
}
|
||||||
|
|||||||
@@ -329,6 +329,34 @@ Search::find_positions ()
|
|||||||
|
|
||||||
/* That's it. Hope it's good enough. */
|
/* That's it. Hope it's good enough. */
|
||||||
_key_positions = current;
|
_key_positions = current;
|
||||||
|
|
||||||
|
if (option[DEBUG])
|
||||||
|
{
|
||||||
|
/* Print the result. */
|
||||||
|
fprintf (stderr, "\nComputed positions: ");
|
||||||
|
PositionReverseIterator iter (_key_positions);
|
||||||
|
bool seen_lastchar = false;
|
||||||
|
bool first = true;
|
||||||
|
for (int i; (i = iter.next ()) != PositionReverseIterator::EOS; )
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
fprintf (stderr, ", ");
|
||||||
|
if (i == Positions::LASTCHAR)
|
||||||
|
seen_lastchar = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%d", i);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (seen_lastchar)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
fprintf (stderr, ", ");
|
||||||
|
fprintf (stderr, "$");
|
||||||
|
}
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===================== Finding good alpha increments ===================== */
|
/* ===================== Finding good alpha increments ===================== */
|
||||||
@@ -459,6 +487,39 @@ Search::find_alpha_inc ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (current_duplicates_count > duplicates_goal);
|
while (current_duplicates_count > duplicates_goal);
|
||||||
|
|
||||||
|
if (option[DEBUG])
|
||||||
|
{
|
||||||
|
/* Print the result. */
|
||||||
|
fprintf (stderr, "\nComputed alpha increments: ");
|
||||||
|
if (option[ALLCHARS])
|
||||||
|
{
|
||||||
|
bool first = true;
|
||||||
|
for (unsigned int j = 0; j < nindices; j++)
|
||||||
|
if (current[indices[j]] != 0)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
fprintf (stderr, ", ");
|
||||||
|
fprintf (stderr, "%u:+%u",
|
||||||
|
indices[j] + 1, current[indices[j]]);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool first = true;
|
||||||
|
for (unsigned int j = nindices; j-- > 0; )
|
||||||
|
if (current[indices[j]] != 0)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
fprintf (stderr, ", ");
|
||||||
|
fprintf (stderr, "%u:+%u",
|
||||||
|
indices[j] + 1, current[indices[j]]);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpha_inc = current;
|
_alpha_inc = current;
|
||||||
@@ -526,6 +587,8 @@ Search::prepare ()
|
|||||||
if (garbage)
|
if (garbage)
|
||||||
delete garbage;
|
delete garbage;
|
||||||
}
|
}
|
||||||
|
if (option[DEBUG])
|
||||||
|
representatives.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit program if duplicates exists and option[DUP] not set, since we
|
/* Exit program if duplicates exists and option[DUP] not set, since we
|
||||||
|
|||||||
Reference in New Issue
Block a user