1
0
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:
Bruno Haible
2003-03-04 06:05:14 +00:00
parent 9fa3ac42b3
commit 9492f0dad7
6 changed files with 149 additions and 30 deletions

View File

@@ -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.

View File

@@ -85,7 +85,12 @@ 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;
@@ -118,8 +123,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. */
inline bool inline bool

View File

@@ -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. */

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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