blob: e7a3b5e44c237bc9451074d4fae0c807c6efcf76 [file] [log] [blame]
sewardjb4112022007-11-09 22:49:28 +00001
2/*--------------------------------------------------------------------*/
3/*--- Sets of words, with unique set identifiers. ---*/
4/*--- hg_wordset.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Helgrind, a Valgrind tool for detecting errors
9 in threaded programs.
10
sewardj0f157dd2013-10-18 14:27:36 +000011 Copyright (C) 2007-2013 OpenWorks LLP
sewardjb4112022007-11-09 22:49:28 +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 Neither the names of the U.S. Department of Energy nor the
32 University of California nor the names of its contributors may be
33 used to endorse or promote products derived from this software
34 without prior written permission.
35*/
36
37#ifndef __HG_WORDSET_H
38#define __HG_WORDSET_H
39
40//------------------------------------------------------------------//
41//--- WordSet ---//
42//--- Public Interface ---//
43//------------------------------------------------------------------//
44
45typedef struct _WordSetU WordSetU; /* opaque */
46
47typedef UInt WordSet; /* opaque, small int index */
48
49/* Allocate and initialise a WordSetU */
florian54fe2022012-10-27 23:07:42 +000050WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( const HChar*, SizeT ),
51 const HChar* cc,
sewardjb4112022007-11-09 22:49:28 +000052 void (*dealloc)(void*),
53 Word cacheSize );
54
55/* Free up the WordSetU. */
56void HG_(deleteWordSetU) ( WordSetU* );
57
sewardj866c80c2011-10-22 19:29:51 +000058/* Get the number of elements in this WordSetU. Note that the dead
59 WordSet are included in the WordSetU number of elements. */
sewardj250ec2e2008-02-15 22:02:30 +000060UWord HG_(cardinalityWSU) ( WordSetU* );
sewardjb4112022007-11-09 22:49:28 +000061
62/* Show performance stats for this WordSetU. */
florian54fe2022012-10-27 23:07:42 +000063void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name );
sewardjb4112022007-11-09 22:49:28 +000064
65
66/* Element-level operations on WordSets. Note that the WordSet
67 numbers given out are 0, 1, 2, 3, etc, and as it happens 0 always
68 represents the empty set. */
69
70WordSet HG_(emptyWS) ( WordSetU* );
sewardj250ec2e2008-02-15 22:02:30 +000071WordSet HG_(addToWS) ( WordSetU*, WordSet, UWord );
72WordSet HG_(delFromWS) ( WordSetU*, WordSet, UWord );
sewardjb4112022007-11-09 22:49:28 +000073WordSet HG_(unionWS) ( WordSetU*, WordSet, WordSet );
74WordSet HG_(intersectWS) ( WordSetU*, WordSet, WordSet );
75WordSet HG_(minusWS) ( WordSetU*, WordSet, WordSet );
76Bool HG_(isEmptyWS) ( WordSetU*, WordSet );
sewardj250ec2e2008-02-15 22:02:30 +000077Bool HG_(isSingletonWS) ( WordSetU*, WordSet, UWord );
78UWord HG_(anyElementOfWS) ( WordSetU*, WordSet );
79UWord HG_(cardinalityWS) ( WordSetU*, WordSet );
80Bool HG_(elemWS) ( WordSetU*, WordSet, UWord );
81WordSet HG_(doubletonWS) ( WordSetU*, UWord, UWord );
82WordSet HG_(singletonWS) ( WordSetU*, UWord );
sewardjb4112022007-11-09 22:49:28 +000083WordSet HG_(isSubsetOf) ( WordSetU*, WordSet, WordSet );
84
85Bool HG_(plausibleWS) ( WordSetU*, WordSet );
sewardj866c80c2011-10-22 19:29:51 +000086
87
sewardjb4112022007-11-09 22:49:28 +000088Bool HG_(saneWS_SLOW) ( WordSetU*, WordSet );
89
90void HG_(ppWS) ( WordSetU*, WordSet );
sewardj866c80c2011-10-22 19:29:51 +000091
sewardj250ec2e2008-02-15 22:02:30 +000092void HG_(getPayloadWS) ( /*OUT*/UWord** words, /*OUT*/UWord* nWords,
sewardjb4112022007-11-09 22:49:28 +000093 WordSetU*, WordSet );
94
sewardj866c80c2011-10-22 19:29:51 +000095/* HG_(dieWS) indicates WordSet is not used/not referenced anymore,
96 and its memory can be reclaimed.
97 If ever a WordSet with the same content would be needed again,
98 a new WordSet will be reallocated.
99
100 BUG ALERT: !!! Using HG_(dieWS) on a WSU introduces a risk of
101 dangling references. Dangling references can be created by keeping
102 a ws after having marked it dead. This ws (just an index in
103 reality) will be re-cycled : a newly created wv can get the same
104 index. This implies that the wrong wv will be used if the
105 "old" ws has been kept.
106 Re-using a "dead" ws will be detected if the index has not been
107 re-cycled yet.
108
109 Another possibility of bug is to ask for the payload of a ws, and
110 then have this ws marked dead while the payload is still being
111 examined. This is a real dangling reference in free or re-allocated
112 memory. */
113void HG_(dieWS) ( WordSetU*, WordSet );
114
115
sewardjb4112022007-11-09 22:49:28 +0000116
117//------------------------------------------------------------------//
118//--- end WordSet ---//
119//--- Public Interface ---//
120//------------------------------------------------------------------//
121
122#endif /* ! __HG_WORDSET_H */
123
124/*--------------------------------------------------------------------*/
125/*--- end hg_wordset.h ---*/
126/*--------------------------------------------------------------------*/