return ( n ? elem_of_node(n) : NULL );
}
+// Find the *element* in t matching k, or NULL if not found; use the given
+// 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 = t->cmp;
+ t->cmp = cmp;
+ e = VG_(OSet_Lookup)(t, k);
+ t->cmp = tmpcmp;
+ return e;
+}
+
// Is there an element matching k?
Bool VG_(OSet_Contains)(AvlTree* t, void* k)
{
// * 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, and
// they will return NULL if VG_(OSet_Next)() is called without an
// intervening call to VG_(OSet_ResetIter)().
-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 );
#endif // __PUB_TOOL_OSET_H
// Check we can find the remaining elements (with the right values).
for (i = 1; i < NN; i += 2) {
- assert( pv = VG_(OSet_Lookup)(oset1, vs[i]) );
+ assert( pv = VG_(OSet_LookupWithCmp)(oset1, vs[i], NULL) );
assert( pv == vs[i] );
}
a = vs[i]->first + 0; assert( vs[i] == VG_(OSet_Lookup)(oset2, &a) );
a = vs[i]->first + 1; assert( vs[i] == VG_(OSet_Lookup)(oset2, &a) );
a = vs[i]->first + 2; assert( vs[i] == VG_(OSet_Lookup)(oset2, &a) );
+ assert( vs[i] == VG_(OSet_LookupWithCmp)(oset2, &a, blockCmp) );
}
// Check that we can iterate over the OSet elements in sorted order, and