Bug 439685 compiler warning in callgrind/main.c
[valgrind.git] / include / pub_tool_sparsewa.h
blobc5b336bdae604c4cf6602392d91d7fea03b60b11
2 /*--------------------------------------------------------------------*/
3 /*--- An sparse array (of words) implementation. ---*/
4 /*--- pub_tool_sparsewa.h ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2008-2017 OpenWorks Ltd
12 info@open-works.co.uk
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 #ifndef __PUB_TOOL_SPARSEWA_H
31 #define __PUB_TOOL_SPARSEWA_H
33 #include "pub_tool_basics.h" // UWord
35 //--------------------------------------------------------------------
36 // PURPOSE: (see coregrind/pub_core_sparsewa.h for details)
37 //--------------------------------------------------------------------
39 /////////////////////////////////////////////////////////
40 // //
41 // SparseWA: Interface //
42 // //
43 /////////////////////////////////////////////////////////
45 // This interface is a very cut-down version of WordFM.
46 // If you understand how to use WordFM then it should be
47 // trivial to use SparseWA.
49 typedef struct _SparseWA SparseWA; /* opaque */
51 // Create a new one, using the specified allocator/deallocator.
52 // Never returns NULL.
53 SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(const HChar* cc, SizeT),
54 const HChar* cc,
55 void(*dealloc)(void*) );
57 // Delete one, and free all associated storage
58 void VG_(deleteSWA) ( SparseWA* swa );
60 // Add the binding key -> val to this swa. Any existing binding is
61 // overwritten. Returned Bool is True iff a previous binding existed.
62 Bool VG_(addToSWA) ( SparseWA* swa, UWord key, UWord val );
64 // Delete key from swa, returning val if found.
65 // Returned Bool is True iff the key was actually bound in the mapping.
66 Bool VG_(delFromSWA) ( SparseWA* swa,
67 /*OUT*/UWord* oldV,
68 UWord key );
70 // Indexes swa at 'key' (or, if you like, looks up 'key' in the
71 // mapping), and returns the associated value, if any, in *valP.
72 // Returned Bool is True iff a binding for 'key' actually existed.
73 Bool VG_(lookupSWA) ( const SparseWA* swa,
74 /*OUT*/UWord* valP,
75 UWord key );
77 // Set up 'swa' for iteration.
78 void VG_(initIterSWA) ( SparseWA* swa );
80 // Get the next key/val pair. Behaviour undefined (highly likely
81 // to segfault) if 'swa' has been modified since initIterSWA was
82 // called. Returned Bool is False iff there are no more pairs
83 // that can be extracted.
84 Bool VG_(nextIterSWA)( SparseWA* swa,
85 /*OUT*/UWord* keyP, /*OUT*/UWord* valP );
87 // How many elements are there in 'swa'? NOTE: dangerous in the
88 // sense that this is not an O(1) operation but rather O(N),
89 // since it involves walking the whole tree.
90 UWord VG_(sizeSWA) ( const SparseWA* swa );
92 #endif // __PUB_TOOL_SPARSEWA_H
94 /*--------------------------------------------------------------------*/
95 /*--- end pub_tool_sparsewa.h ---*/
96 /*--------------------------------------------------------------------*/