blob: 5336fee9c17d71d7ed94bb5ce1649e0427621415 [file] [log] [blame]
sewardj78b7ecf2008-12-06 22:07:35 +00001
2/*--------------------------------------------------------------------*/
3/*--- An sparse array (of words) implementation. ---*/
4/*--- pub_tool_sparsewa.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
10
sewardj03f8d3f2012-08-05 15:46:46 +000011 Copyright (C) 2008-2012 OpenWorks Ltd
sewardj78b7ecf2008-12-06 22:07:35 +000012 info@open-works.co.uk
13
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.
18
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.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
32#ifndef __PUB_TOOL_SPARSEWA_H
33#define __PUB_TOOL_SPARSEWA_H
34
35//--------------------------------------------------------------------
36// PURPOSE: (see coregrind/pub_core_sparsewa.h for details)
37//--------------------------------------------------------------------
38
39/////////////////////////////////////////////////////////
40// //
41// SparseWA: Interface //
42// //
43/////////////////////////////////////////////////////////
44
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.
48
49typedef struct _SparseWA SparseWA; /* opaque */
50
51// Create a new one, using the specified allocator/deallocator
florian54fe2022012-10-27 23:07:42 +000052SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(const HChar* cc, SizeT),
53 const HChar* cc,
sewardj78b7ecf2008-12-06 22:07:35 +000054 void(*dealloc)(void*) );
55
56// Delete one, and free all associated storage
57void VG_(deleteSWA) ( SparseWA* swa );
58
59// Add the binding key -> val to this swa. Any existing binding is
60// overwritten. Returned Bool is True iff a previous binding existed.
61Bool VG_(addToSWA) ( SparseWA* swa, UWord key, UWord val );
62
63// Delete key from swa, returning associated key and val if found.
64// Note: returning associated key is stupid (it can only be the
65// key you just specified). This behaviour is retained to make it
66// easier to migrate from WordFM. Returned Bool is True iff
67// the key was actually bound in the mapping.
68Bool VG_(delFromSWA) ( SparseWA* swa,
69 /*OUT*/UWord* oldK, /*OUT*/UWord* oldV,
70 UWord key );
71
72// Indexes swa at 'key' (or, if you like, looks up 'key' in the
73// mapping), and returns the associated value, if any, in *valP. For
74// compatibility with WordFM, 'key' is also returned in *keyP. Returned
75// Bool is True iff a binding for 'key' actually existed.
76Bool VG_(lookupSWA) ( SparseWA* swa,
77 /*OUT*/UWord* keyP, /*OUT*/UWord* valP,
78 UWord key );
79
80// Set up 'swa' for iteration.
81void VG_(initIterSWA) ( SparseWA* swa );
82
83// Get the next key/val pair. Behaviour undefined (highly likely
84// to segfault) if 'swa' has been modified since initIterSWA was
85// called. Returned Bool is False iff there are no more pairs
86// that can be extracted.
87Bool VG_(nextIterSWA)( SparseWA* swa,
88 /*OUT*/UWord* keyP, /*OUT*/UWord* valP );
89
sewardjf35dbb82008-12-06 23:34:52 +000090// How many elements are there in 'swa'? NOTE: dangerous in the
91// sense that this is not an O(1) operation but rather O(N),
92// since it involves walking the whole tree.
93UWord VG_(sizeSWA) ( SparseWA* swa );
sewardj78b7ecf2008-12-06 22:07:35 +000094
95#endif // __PUB_TOOL_SPARSEWA_H
96
97/*--------------------------------------------------------------------*/
98/*--- end pub_tool_sparsewa.h ---*/
99/*--------------------------------------------------------------------*/