|
From: <sv...@va...> - 2005-08-14 17:42:38
|
Author: njn
Date: 2005-08-14 18:42:35 +0100 (Sun, 14 Aug 2005)
New Revision: 4407
Log:
Added an iterator to VgHashTable.
Modified:
trunk/coregrind/m_hashtable.c
trunk/include/pub_tool_hashtable.h
Modified: trunk/coregrind/m_hashtable.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_hashtable.c 2005-08-14 17:36:07 UTC (rev 4406)
+++ trunk/coregrind/m_hashtable.c 2005-08-14 17:42:35 UTC (rev 4407)
@@ -41,7 +41,9 @@
=20
struct _VgHashTable {
UInt n_chains; // should be prime
- VgHashNode* chains[0];
+ VgHashNode* iterNode; // current iterator node
+ UInt iterChain; // next chain to be traversed by the itera=
tor
+ VgHashNode* chains[0]; // must be last field in the struct!
};
=20
/*--------------------------------------------------------------------*/
@@ -203,6 +205,33 @@
}
}
=20
+void VG_(HT_ResetIter)(VgHashTable table)
+{
+ vg_assert(table);
+ table->iterNode =3D NULL;
+ table->iterChain =3D 0;
+}
+
+void* VG_(HT_Next)(VgHashTable table)
+{
+ Int i;
+ vg_assert(table);
+ =20
+ if (table->iterNode && table->iterNode->next) {
+ table->iterNode =3D table->iterNode->next;
+ return table->iterNode;
+ }
+
+ for (i =3D table->iterChain; i < table->n_chains; i++) {
+ if (table->chains[i]) {
+ table->iterNode =3D table->chains[i];
+ table->iterChain =3D i + 1; // Next chain to be traversed
+ return table->iterNode;
+ }
+ }
+ return NULL;
+}
+
void VG_(HT_destruct)(VgHashTable table)
{
UInt i;
Modified: trunk/include/pub_tool_hashtable.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/pub_tool_hashtable.h 2005-08-14 17:36:07 UTC (rev 4406)
+++ trunk/include/pub_tool_hashtable.h 2005-08-14 17:42:35 UTC (rev 4407)
@@ -90,6 +90,14 @@
void (*f)(VgHashNode*, void*),
void* d );
=20
+/* Reset the table's iterator to point to the first element. */
+extern void VG_(HT_ResetIter) ( VgHashTable table );
+
+/* Return the element pointed to by the iterator and move on to the next
+ one. Returns NULL if the last one has been passed, or if HT_ResetIte=
r()
+ has not been called previously. */
+extern void* VG_(HT_Next) ( VgHashTable table );
+
/* Destroy a table. */
extern void VG_(HT_destruct) ( VgHashTable t );
=20
|