mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +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>
|
||||
|
||||
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.
|
||||
* src/positions.h (Positions::LASTCHAR, Positions::MAX_KEY_POS,
|
||||
PositionIterator::EOS): Define as compile-time constants using enum.
|
||||
|
||||
@@ -85,40 +85,43 @@ Hash_Table::Hash_Table (unsigned int size, bool ignore_length)
|
||||
/* Destructor. */
|
||||
Hash_Table::~Hash_Table ()
|
||||
{
|
||||
if (option[DEBUG])
|
||||
{
|
||||
int field_width;
|
||||
delete[] _table;
|
||||
}
|
||||
|
||||
field_width = 0;
|
||||
/* Print the table's contents. */
|
||||
void
|
||||
Hash_Table::dump () const
|
||||
{
|
||||
int field_width;
|
||||
|
||||
field_width = 0;
|
||||
{
|
||||
for (int i = _size - 1; i >= 0; i--)
|
||||
if (_table[i])
|
||||
if (field_width < _table[i]->_selchars_length)
|
||||
field_width = _table[i]->_selchars_length;
|
||||
}
|
||||
|
||||
fprintf (stderr,
|
||||
"\ndumping the hash table\n"
|
||||
"total available table slots = %d, total bytes = %d, total collisions = %d\n"
|
||||
"location, %*s, keyword\n",
|
||||
_size, _size * static_cast<unsigned int>(sizeof (*_table)),
|
||||
_collisions, field_width, "keysig");
|
||||
|
||||
for (int i = _size - 1; i >= 0; i--)
|
||||
if (_table[i])
|
||||
{
|
||||
for (int i = _size - 1; i >= 0; i--)
|
||||
if (_table[i])
|
||||
if (field_width < _table[i]->_selchars_length)
|
||||
field_width = _table[i]->_selchars_length;
|
||||
fprintf (stderr, "%8d, ", i);
|
||||
if (field_width > _table[i]->_selchars_length)
|
||||
fprintf (stderr, "%*s", field_width - _table[i]->_selchars_length, "");
|
||||
for (int j = 0; j < _table[i]->_selchars_length; j++)
|
||||
putc (_table[i]->_selchars[j], stderr);
|
||||
fprintf (stderr, ", %.*s\n",
|
||||
_table[i]->_allchars_length, _table[i]->_allchars);
|
||||
}
|
||||
|
||||
fprintf (stderr,
|
||||
"\ndumping the hash table\n"
|
||||
"total available table slots = %d, total bytes = %d, total collisions = %d\n"
|
||||
"location, %*s, keyword\n",
|
||||
_size, _size * static_cast<unsigned int>(sizeof (*_table)),
|
||||
_collisions, field_width, "keysig");
|
||||
|
||||
for (int i = _size - 1; i >= 0; i--)
|
||||
if (_table[i])
|
||||
{
|
||||
fprintf (stderr, "%8d, ", i);
|
||||
if (field_width > _table[i]->_selchars_length)
|
||||
fprintf (stderr, "%*s", field_width - _table[i]->_selchars_length, "");
|
||||
for (int j = 0; j < _table[i]->_selchars_length; j++)
|
||||
putc (_table[i]->_selchars[j], stderr);
|
||||
fprintf (stderr, ", %.*s\n",
|
||||
_table[i]->_allchars_length, _table[i]->_allchars);
|
||||
}
|
||||
|
||||
fprintf (stderr, "\nend dumping hash table\n\n");
|
||||
}
|
||||
delete[] _table;
|
||||
fprintf (stderr, "\nend dumping hash table\n\n");
|
||||
}
|
||||
|
||||
/* Compares two items. */
|
||||
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
/* Attempts to insert ITEM in the table. If there is already an equal
|
||||
entry in it, returns it. Otherwise inserts ITEM and returns NULL. */
|
||||
KeywordExt * insert (KeywordExt *item);
|
||||
/* Print the table's contents. */
|
||||
void dump () const;
|
||||
|
||||
private:
|
||||
/* Vector of entries. */
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
class Positions
|
||||
{
|
||||
friend class PositionIterator;
|
||||
friend class PositionReverseIterator;
|
||||
public:
|
||||
/* Denotes the last char of a keyword, depending on the keyword's length. */
|
||||
enum { LASTCHAR = 0 };
|
||||
@@ -99,6 +100,26 @@ private:
|
||||
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__
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -137,3 +137,20 @@ PositionIterator::next ()
|
||||
{
|
||||
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. */
|
||||
_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 ===================== */
|
||||
@@ -459,6 +487,39 @@ Search::find_alpha_inc ()
|
||||
}
|
||||
}
|
||||
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;
|
||||
@@ -526,6 +587,8 @@ Search::prepare ()
|
||||
if (garbage)
|
||||
delete garbage;
|
||||
}
|
||||
if (option[DEBUG])
|
||||
representatives.dump();
|
||||
}
|
||||
|
||||
/* Exit program if duplicates exists and option[DUP] not set, since we
|
||||
|
||||
Reference in New Issue
Block a user