summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-03-04 06:05:14 +0000
committerBruno Haible <bruno@clisp.org>2003-03-04 06:05:14 +0000
commit9492f0dad7d0546e8efa62ee72ba7ce5d5899e55 (patch)
treecaf6fe4d28f61f18f6e02c223417d3a273280fe1
parent9fa3ac42b377a7a8c519d64e25cbe83c7d3300a6 (diff)
downloadgperf-9492f0dad7d0546e8efa62ee72ba7ce5d5899e55.tar.gz
Improve debugging output.
-rw-r--r--ChangeLog13
-rw-r--r--src/hash-table.cc63
-rw-r--r--src/hash-table.h2
-rw-r--r--src/positions.h21
-rw-r--r--src/positions.icc17
-rw-r--r--src/search.cc63
6 files changed, 149 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 2ea96ea..3ad48f3 100644
--- a/ChangeLog
+++ b/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.
diff --git a/src/hash-table.cc b/src/hash-table.cc
index e00a456..615afd6 100644
--- a/src/hash-table.cc
+++ b/src/hash-table.cc
@@ -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. */
diff --git a/src/hash-table.h b/src/hash-table.h
index 22ad955..8b7f6a2 100644
--- a/src/hash-table.h
+++ b/src/hash-table.h
@@ -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. */
diff --git a/src/positions.h b/src/positions.h
index 88d9584..1c883a4 100644
--- a/src/positions.h
+++ b/src/positions.h
@@ -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>
diff --git a/src/positions.icc b/src/positions.icc
index 12e9938..9475f69 100644
--- a/src/positions.icc
+++ b/src/positions.icc
@@ -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);
+}
diff --git a/src/search.cc b/src/search.cc
index 5308690..a27b1fd 100644
--- a/src/search.cc
+++ b/src/search.cc
@@ -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