|
From: <sv...@va...> - 2005-08-18 19:12:28
|
Author: njn
Date: 2005-08-17 22:06:07 +0100 (Wed, 17 Aug 2005)
New Revision: 4444
Log:
Added VG_(OSet_LookupWithCmp)(), which can be useful.
Modified:
trunk/coregrind/m_oset.c
trunk/include/pub_tool_oset.h
trunk/memcheck/tests/oset_test.c
Modified: trunk/coregrind/m_oset.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_oset.c 2005-08-17 09:23:48 UTC (rev 4443)
+++ trunk/coregrind/m_oset.c 2005-08-17 21:06:07 UTC (rev 4444)
@@ -497,6 +497,21 @@
return ( n ? elem_of_node(n) : NULL );
}
=20
+// Find the *element* in t matching k, or NULL if not found; use the gi=
ven
+// comparison function rather than the standard one.
+void* VG_(OSet_LookupWithCmp)(AvlTree* t, void* k, OSetCmp_t cmp)
+{
+ // Save the normal one to the side, then restore once we're done.
+ void* e;
+ OSetCmp_t tmpcmp;
+ vg_assert(t);
+ tmpcmp =3D t->cmp;
+ t->cmp =3D cmp;
+ e =3D VG_(OSet_Lookup)(t, k);
+ t->cmp =3D tmpcmp;
+ return e;
+}
+
// Is there an element matching k?
Bool VG_(OSet_Contains)(AvlTree* t, void* k)
{
Modified: trunk/include/pub_tool_oset.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_oset.h 2005-08-17 09:23:48 UTC (rev 4443)
+++ trunk/include/pub_tool_oset.h 2005-08-17 21:06:07 UTC (rev 4444)
@@ -117,6 +117,9 @@
// * Lookup: Returns a pointer to the element matching the key, if there=
is
// one, otherwise returns NULL.
//
+// * LookupWithCmp: Like Lookup, but you specify the comparison function=
,
+// which overrides the OSet's normal one.
+//
// * Insert: Inserts a new element into the list. Note that 'elem' must
// have been allocated using VG_(OSet_AllocNode)(), otherwise you will=
get
// assertion failures about "bad magic". Duplicates are forbidden, an=
d
@@ -145,13 +148,14 @@
// they will return NULL if VG_(OSet_Next)() is called without an
// intervening call to VG_(OSet_ResetIter)().
=20
-extern Int VG_(OSet_Size) ( OSet* os );
-extern void VG_(OSet_Insert) ( OSet* os, void* elem );
-extern Bool VG_(OSet_Contains) ( OSet* os, void* key );
-extern void* VG_(OSet_Lookup) ( OSet* os, void* key );
-extern void* VG_(OSet_Remove) ( OSet* os, void* key );
-extern void VG_(OSet_ResetIter) ( OSet* os );
-extern void* VG_(OSet_Next) ( OSet* os );
+extern Int VG_(OSet_Size) ( OSet* os );
+extern void VG_(OSet_Insert) ( OSet* os, void* elem );
+extern Bool VG_(OSet_Contains) ( OSet* os, void* key );
+extern void* VG_(OSet_Lookup) ( OSet* os, void* key );
+extern void* VG_(OSet_LookupWithCmp)( OSet* os, void* key, OSetCmp_t cmp=
);
+extern void* VG_(OSet_Remove) ( OSet* os, void* key );
+extern void VG_(OSet_ResetIter) ( OSet* os );
+extern void* VG_(OSet_Next) ( OSet* os );
=20
#endif // __PUB_TOOL_OSET_H
=20
Modified: trunk/memcheck/tests/oset_test.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/memcheck/tests/oset_test.c 2005-08-17 09:23:48 UTC (rev 4443)
+++ trunk/memcheck/tests/oset_test.c 2005-08-17 21:06:07 UTC (rev 4444)
@@ -139,7 +139,7 @@
=20
// Check we can find the remaining elements (with the right values).
for (i =3D 1; i < NN; i +=3D 2) {
- assert( pv =3D VG_(OSet_Lookup)(oset1, vs[i]) );
+ assert( pv =3D VG_(OSet_LookupWithCmp)(oset1, vs[i], NULL) );
assert( pv =3D=3D vs[i] );
}
=20
@@ -286,6 +286,7 @@
a =3D vs[i]->first + 0; assert( vs[i] =3D=3D VG_(OSet_Lookup)(o=
set2, &a) );
a =3D vs[i]->first + 1; assert( vs[i] =3D=3D VG_(OSet_Lookup)(o=
set2, &a) );
a =3D vs[i]->first + 2; assert( vs[i] =3D=3D VG_(OSet_Lookup)(o=
set2, &a) );
+ assert( vs[i] =3D=3D VG_(OSet_LookupWithCmp)(oset2, &a, blockCmp) =
);
}
=20
// Check that we can iterate over the OSet elements in sorted order, =
and
|