HPCToolkit
WordSet.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // WordSet.h
50 //
51 // Author: John Mellor-Crummey January 1994
52 //
53 //**************************************************************************/
54 
55 #ifndef WordSet_h
56 #define WordSet_h
57 
58 //************************* System Include Files ****************************
59 
60 #include <iostream>
61 
62 //*************************** User Include Files ****************************
63 
64 #include "HashTable.hpp"
65 
66 //***************************************************************************
67 
68 //-------------------------------------------------------------
69 // class WordSet
70 //-------------------------------------------------------------
71 class WordSet : private HashTable {
72 public:
73  WordSet();
74  WordSet(const WordSet &rhs);
75  virtual ~WordSet();
76 
77  void Add(unsigned long entry);
78  void Delete(unsigned long entry);
79  int IsMember(unsigned long entry) const;
80  bool Intersects(const WordSet& rhs) const;
81  void Clear();
82 
83  unsigned long GetEntryByIndex(unsigned int indx) const;
84 
85  int operator==(const WordSet &rhs) const; // equality
86  WordSet& operator|=(const WordSet &rhs); // union
87  WordSet& operator&=(const WordSet &rhs); // intersection
88  WordSet& operator-=(const WordSet &rhs); // difference
89  WordSet& operator=(const WordSet &rhs); // copy
90 
92 
93  void Dump(std::ostream& file = std::cerr,
94  const char* name = "",
95  const char* indent = "");
96 
97 private:
98  //-------------------------------------------------------------
99  // virtual functions for hashing and comparing
100  // that override the defaults for HashTable
101  //-------------------------------------------------------------
102  uint HashFunct(const void *entry, const uint size);
103  int EntryCompare(const void *entry1, const void *entry2); // 0 if equal
104 
105 //-------------------------------------------------------------
106 // friend declaration required so HashTableIterator can be
107 // used with the private base class
108 //-------------------------------------------------------------
109 friend class WordSetIterator;
110 };
111 
112 
113 //-------------------------------------------------------------
114 // class WordSetIterator
115 //-------------------------------------------------------------
117  : private HashTableIterator {
118 public:
119  WordSetIterator(const WordSet *theTable);
120  virtual ~WordSetIterator() { }
121  unsigned long *Current() const;
122  using HashTableIterator::operator++;
124 };
125 
126 //-------------------------------------------------------------
127 // class WordSetSortedIterator
128 //-------------------------------------------------------------
130 public:
131  WordSetSortedIterator(WordSet const *theTable,
134  unsigned long *Current() const;
135  using HashTableSortedIterator::operator++;
137 
138 private:
139  unsigned long current;
140 };
141 
142 
143 #endif /* WordSet_h */
unsigned long current
Definition: WordSet.hpp:139
int(* EntryCompareFunctPtr)(const void *, const void *)
Definition: HashTable.hpp:300
WordSet & operator-=(const WordSet &rhs)
Definition: WordSet.cpp:223
friend class WordSetIterator
Definition: WordSet.hpp:109
WordSet & operator|=(const WordSet &rhs)
Definition: WordSet.cpp:179
void Clear()
Definition: WordSet.cpp:146
int operator==(const WordSet &rhs) const
Definition: WordSet.cpp:161
int IsMember(unsigned long entry) const
Definition: WordSet.cpp:119
virtual ~WordSetSortedIterator()
Definition: WordSet.hpp:133
virtual ~WordSet()
Definition: WordSet.cpp:89
unsigned int uint
Definition: uint.h:124
WordSet & operator &=(const WordSet &rhs)
void Dump()
Definition: HashTable.cpp:475
WordSet()
Definition: WordSet.cpp:76
void Add(unsigned long entry)
Definition: WordSet.cpp:107
virtual ~WordSetIterator()
Definition: WordSet.hpp:120
uint NumberOfEntries() const
Definition: HashTable.cpp:460
WordSet & operator=(const WordSet &rhs)
Definition: WordSet.cpp:188
int EntryCompare(const void *entry1, const void *entry2)
Definition: WordSet.cpp:101
bool Intersects(const WordSet &rhs) const
Definition: WordSet.cpp:126
void Delete(unsigned long entry)
Definition: WordSet.cpp:113
unsigned long GetEntryByIndex(unsigned int indx) const
Definition: WordSet.cpp:155
uint HashFunct(const void *entry, const uint size)
Definition: WordSet.cpp:95