}
static inline
-void* slow_key_of_node(AvlTree* t, AvlNode* n)
+void* slow_key_of_node(const AvlTree* t, const AvlNode* n)
{
return (void*)((Addr)elem_of_node(n) + t->keyOff);
}
static inline
-void* fast_key_of_node(AvlNode* n)
+void* fast_key_of_node(const AvlNode* n)
{
return elem_of_node(n);
}
return t;
}
-AvlTree* VG_(OSetGen_EmptyClone) (AvlTree* os)
+AvlTree* VG_(OSetGen_EmptyClone) (const AvlTree* os)
{
AvlTree* t;
}
// Allocate and initialise a new node.
-void* VG_(OSetGen_AllocNode)(AvlTree* t, SizeT elemSize)
+void* VG_(OSetGen_AllocNode)(const AvlTree* t, SizeT elemSize)
{
AvlNode* n;
Int nodeSize = sizeof(AvlNode) + elemSize;
return elem_of_node(n);
}
-void VG_(OSetGen_FreeNode)(AvlTree* t, void* e)
+void VG_(OSetGen_FreeNode)(const AvlTree* t, void* e)
{
if (t->node_pa)
VG_(freeEltPA) (t->node_pa, node_of_elem (e));
/*--- Insertion ---*/
/*--------------------------------------------------------------------*/
-static inline Word cmp_key_root(AvlTree* t, AvlNode* n)
+static inline Word cmp_key_root(const AvlTree* t, const AvlNode* n)
{
return t->cmp
? slow_cmp(t, slow_key_of_node(t, n), t->root)
return (NULL != VG_(OSetGen_Lookup)(t, k));
}
-Bool VG_(OSetWord_Contains)(AvlTree* t, UWord val)
+Bool VG_(OSetWord_Contains)(const AvlTree* t, UWord val)
{
return (NULL != VG_(OSetGen_Lookup)(t, &val));
}
// Remove an already-selected node n from the AVL tree t.
// Returns True if the depth of the tree has shrunk.
-static Bool avl_remove(AvlTree* t, AvlNode* n)
+static Bool avl_remove(AvlTree* t, const AvlNode* n)
{
Bool ch;
Word cmpres = cmp_key_root(t, n);
return t->nElems;
}
-Word VG_(OSetWord_Size)(AvlTree* t)
+Word VG_(OSetWord_Size)(const AvlTree* t)
{
return VG_(OSetGen_Size)(t);
}
-static void OSet_Print2( AvlTree* t, AvlNode* n,
- HChar*(*strElem)(void *), Int p )
+static void OSet_Print2( const AvlTree* t, const AvlNode* n,
+ const HChar*(*strElem)(const void *), Int p )
{
// This is a recursive in-order traversal.
Int q = p;
}
__attribute__((unused))
-static void OSet_Print( AvlTree* t, const HChar *where,
- HChar*(*strElem)(void *) )
+static void OSet_Print( const AvlTree* t, const HChar *where,
+ const HChar*(*strElem)(const void *) )
{
VG_(printf)("-- start %s ----------------\n", where);
OSet_Print2(t, t->root, strElem, 0);
//////// SWA helper functions (bitarray)
-static inline UWord swa_bitarray_read ( UChar* arr, UWord ix ) {
+static inline UWord swa_bitarray_read ( const UChar* arr, UWord ix ) {
UWord bix = ix >> 3;
UWord off = ix & 7;
return (arr[bix] >> off) & 1;
//////// SWA helper functions (allocation)
-static LevelN* swa_new_LevelN ( SparseWA* swa, Int level )
+static LevelN* swa_new_LevelN ( const SparseWA* swa, Int level )
{
LevelN* levelN = swa->alloc_nofail( swa->cc, sizeof(LevelN) );
VG_(memset)(levelN, 0, sizeof(*levelN));
return levelN;
}
-static Level0* swa_new_Level0 ( SparseWA* swa )
+static Level0* swa_new_Level0 ( const SparseWA* swa )
{
Level0* level0 = swa->alloc_nofail( swa->cc, sizeof(Level0) );
VG_(memset)(level0, 0, sizeof(*level0));
}
-Bool VG_(lookupSWA) ( SparseWA* swa,
+Bool VG_(lookupSWA) ( const SparseWA* swa,
/*OUT*/UWord* keyP, /*OUT*/UWord* valP,
UWord key )
{
}
-static UWord swa_sizeSWA_wrk ( void* nd )
+static UWord swa_sizeSWA_wrk ( const void* nd )
{
Int i;
- if (*(UWord*)nd == LevelN_MAGIC) {
+ if (*(const UWord*)nd == LevelN_MAGIC) {
UWord sum = 0;
- LevelN* levelN = (LevelN*)nd;
+ const LevelN* levelN = nd;
for (i = 0; i < 256; i++) {
if (levelN->child[i]) {
sum += swa_sizeSWA_wrk( levelN->child[i] );
}
return sum;
} else {
- Level0* level0;
- vg_assert(*(UWord*)nd == Level0_MAGIC);
- level0 = (Level0*)nd;
+ const Level0* level0;
+ vg_assert(*(const UWord*)nd == Level0_MAGIC);
+ level0 = nd;
return level0->nInUse;
}
}
-UWord VG_(sizeSWA) ( SparseWA* swa )
+UWord VG_(sizeSWA) ( const SparseWA* swa )
{
if (swa->root)
return swa_sizeSWA_wrk ( swa->root );
}
/* Find size of a non-NULL tree. */
-static UWord size_avl_nonNull ( AvlNode* nd )
+static UWord size_avl_nonNull ( const AvlNode* nd )
{
return 1 + (nd->child[0] ? size_avl_nonNull(nd->child[0]) : 0)
+ (nd->child[1] ? size_avl_nonNull(nd->child[1]) : 0);
}
static
-Bool avl_find_bounds ( AvlNode* t,
+Bool avl_find_bounds ( const AvlNode* t,
/*OUT*/UWord* kMinP, /*OUT*/UWord* vMinP,
/*OUT*/UWord* kMaxP, /*OUT*/UWord* vMaxP,
UWord minKey, UWord minVal,
}
static
-AvlNode* avl_dopy ( AvlNode* nd,
+AvlNode* avl_dopy ( const AvlNode* nd,
UWord(*dopyK)(UWord),
UWord(*dopyV)(UWord),
void*(alloc_nofail)(const HChar*,SizeT),
}
// Look up in fm, assigning found key & val at spec'd addresses
-Bool VG_(lookupFM) ( WordFM* fm,
+Bool VG_(lookupFM) ( const WordFM* fm,
/*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key )
{
AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
}
// See comment in pub_tool_wordfm.h for explanation
-Bool VG_(findBoundsFM)( WordFM* fm,
+Bool VG_(findBoundsFM)( const WordFM* fm,
/*OUT*/UWord* kMinP, /*OUT*/UWord* vMinP,
/*OUT*/UWord* kMaxP, /*OUT*/UWord* vMaxP,
UWord minKey, UWord minVal,
}
// See comment in pub_tool_wordfm.h for performance warning
-UWord VG_(sizeFM) ( WordFM* fm )
+UWord VG_(sizeFM) ( const WordFM* fm )
{
// Hmm, this is a bad way to do this
return fm->root ? size_avl_nonNull( fm->root ) : 0;
}
// NB UNTESTED! TEST BEFORE USE!
-//Bool VG_(isEmptyFM)( WordFM* fm )
+//Bool VG_(isEmptyFM)( const WordFM* fm )
//{
// return fm->root ? False : True;
//}
{
}
-WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
+WordFM* VG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord),
+ UWord(*dopyV)(UWord) )
{
WordFM* nyu;
}
}
-UWord VG_(elemBag) ( WordBag* bag, UWord w )
+UWord VG_(elemBag) ( const WordBag* bag, UWord w )
{
UWord key, count;
if (VG_(lookupFM)( bag->fm, &key, &count, w)) {
}
}
-UWord VG_(sizeUniqueBag) ( WordBag* bag )
+UWord VG_(sizeUniqueBag) ( const WordBag* bag )
{
return VG_(sizeFM)( bag->fm );
}
-static UWord sizeTotalBag_wrk ( AvlNode* nd )
+static UWord sizeTotalBag_wrk ( const AvlNode* nd )
{
/* unchecked pre: nd is non-NULL */
UWord w = nd->val;
w += sizeTotalBag_wrk(nd->child[1]);
return w;
}
-UWord VG_(sizeTotalBag)( WordBag* bag )
+UWord VG_(sizeTotalBag)( const WordBag* bag )
{
if (bag->fm->root)
return sizeTotalBag_wrk(bag->fm->root);
}
}
-Bool VG_(isEmptyBag)( WordBag* bag )
+Bool VG_(isEmptyBag)( const WordBag* bag )
{
return VG_(sizeFM)(bag->fm) == 0;
}
-Bool VG_(isSingletonTotalBag)( WordBag* bag )
+Bool VG_(isSingletonTotalBag)( const WordBag* bag )
{
AvlNode* nd;
if (VG_(sizeFM)(bag->fm) != 1)
return nd->val == 1;
}
-UWord VG_(anyElementOfBag)( WordBag* bag )
+UWord VG_(anyElementOfBag)( const WordBag* bag )
{
/* Return an arbitrarily chosen element in the bag. We might as
well return the one at the root of the underlying AVL tree. */
// they will return False if VG_(OSetWord_Next)() is called without an
// intervening call to VG_(OSetWord_ResetIter)().
-extern Word VG_(OSetWord_Size) ( OSet* os );
+extern Word VG_(OSetWord_Size) ( const OSet* os );
extern void VG_(OSetWord_Insert) ( OSet* os, UWord val );
-extern Bool VG_(OSetWord_Contains) ( OSet* os, UWord val );
+extern Bool VG_(OSetWord_Contains) ( const OSet* os, UWord val );
extern Bool VG_(OSetWord_Remove) ( OSet* os, UWord val );
extern void VG_(OSetWord_ResetIter) ( OSet* os );
extern Bool VG_(OSetWord_Next) ( OSet* os, /*OUT*/UWord* val );
// always <= than a (small) maximum value.
// In such a case, allocating the nodes in pools reduces significantly
// the memory overhead needed by each node.
-// When a node is freed (i.e. OsetGen_Freenode is called), the node is
+// When a node is freed (i.e. OSetGen_Freenode is called), the node is
// put back in the pool allocator free list (for sub-sequent re-use by
-// Osetgen_Allocnode). Note that the pool memory is only released when
+// OSetGen_AllocNode). Note that the pool memory is only released when
// the pool is destroyed : calls to VG_(OSetGen_Free) do not cause
-// any calls to OsetFree_t _free function.
+// any calls to OSetFree_t _free function.
// If there are several OSet managing similar such elements, it might be
// interesting to use a shared pool for these OSet.
// To have multiple OSets sharing a pool allocator, create the first OSet
// VG_(OSetGen_EmptyClone).
extern void VG_(OSetGen_Destroy) ( OSet* os );
-extern void* VG_(OSetGen_AllocNode) ( OSet* os, SizeT elemSize );
-extern void VG_(OSetGen_FreeNode) ( OSet* os, void* elem );
+extern void* VG_(OSetGen_AllocNode) ( const OSet* os, SizeT elemSize );
+extern void VG_(OSetGen_FreeNode) ( const OSet* os, void* elem );
-extern OSet* VG_(OSetGen_EmptyClone) (OSet* os);
+extern OSet* VG_(OSetGen_EmptyClone) (const OSet* os);
// Creates a new empty OSet.
// The new OSet will have the same characteristics as os.
// If os uses a pool allocator, this pool allocator will be shared with
// mapping), and returns the associated value, if any, in *valP. For
// compatibility with WordFM, 'key' is also returned in *keyP. Returned
// Bool is True iff a binding for 'key' actually existed.
-Bool VG_(lookupSWA) ( SparseWA* swa,
+Bool VG_(lookupSWA) ( const SparseWA* swa,
/*OUT*/UWord* keyP, /*OUT*/UWord* valP,
UWord key );
// How many elements are there in 'swa'? NOTE: dangerous in the
// sense that this is not an O(1) operation but rather O(N),
// since it involves walking the whole tree.
-UWord VG_(sizeSWA) ( SparseWA* swa );
+UWord VG_(sizeSWA) ( const SparseWA* swa );
#endif // __PUB_TOOL_SPARSEWA_H
/*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key );
// Look up in fm, assigning found key & val at spec'd addresses
-Bool VG_(lookupFM) ( WordFM* fm,
+Bool VG_(lookupFM) ( const WordFM* fm,
/*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key );
// Find the closest key values bracketing the given key, assuming the
// False is returned, and *kMinP, *vMinP, *kMaxP and *vMaxP are
// undefined. Any of kMinP, vMinP, kMaxP and vMaxP may be safely
// supplied as NULL.
-Bool VG_(findBoundsFM)( WordFM* fm,
+Bool VG_(findBoundsFM)( const WordFM* fm,
/*OUT*/UWord* kMinP, /*OUT*/UWord* vMinP,
/*OUT*/UWord* kMaxP, /*OUT*/UWord* vMaxP,
UWord minKey, UWord minVal,
// How many elements are there in fm? NOTE: dangerous in the
// sense that this is not an O(1) operation but rather O(N),
// since it involves walking the whole tree.
-UWord VG_(sizeFM) ( WordFM* fm );
+UWord VG_(sizeFM) ( const WordFM* fm );
// set up FM for iteration
void VG_(initIterFM) ( WordFM* fm );
void VG_(addToBag)( WordBag*, UWord );
/* Find out how many times the given word exists in the bag. */
-UWord VG_(elemBag) ( WordBag*, UWord );
+UWord VG_(elemBag) ( const WordBag*, UWord );
/* Delete a word from the bag. */
Bool VG_(delFromBag)( WordBag*, UWord );
/* Is the bag empty? */
-Bool VG_(isEmptyBag)( WordBag* );
+Bool VG_(isEmptyBag)( const WordBag* );
/* Does the bag have exactly one element? */
-Bool VG_(isSingletonTotalBag)( WordBag* );
+Bool VG_(isSingletonTotalBag)( const WordBag* );
/* Return an arbitrary element from the bag. */
-UWord VG_(anyElementOfBag)( WordBag* );
+UWord VG_(anyElementOfBag)( const WordBag* );
/* How many different / total elements are in the bag? */
-UWord VG_(sizeUniqueBag)( WordBag* ); /* fast */
-UWord VG_(sizeTotalBag)( WordBag* ); /* warning: slow */
+UWord VG_(sizeUniqueBag)( const WordBag* ); /* fast */
+UWord VG_(sizeTotalBag)( const WordBag* ); /* warning: slow */
/* Iterating over the elements of a bag. */
void VG_(initIterBag)( WordBag* );
// case a Word), in which case the element is also the key.
__attribute__((unused))
-static HChar *wordToStr(void *p)
+static const HChar *wordToStr(const void *p)
{
static HChar buf[32];
sprintf(buf, "%ld", *(Word*)p);