7fd59977 |
1 | // File: TColStd_PackedMapOfInteger.hxx |
2 | // Created: 05.11.05 10:43:14 |
3 | // Author: Alexander GRIGORIEV |
4 | // Copyright: Open Cascade 2005 |
5 | |
6 | |
7 | #ifndef TColStd_PackedMapOfInteger_HeaderFile |
8 | #define TColStd_PackedMapOfInteger_HeaderFile |
9 | |
10 | #include <TCollection_BasicMap.hxx> |
11 | |
12 | /** |
13 | * Optimized Map of integer values. Each block of 32 integers is stored in |
14 | * 8 bytes in memory. |
15 | */ |
16 | |
17 | class TColStd_PackedMapOfInteger : private TCollection_BasicMap |
18 | { |
19 | public: |
20 | // operators new and delete must be defined explicitly |
21 | // since inherited ones are not accessible |
22 | void* operator new(size_t size) |
23 | { return TCollection_BasicMap::operator new(size); } |
24 | void operator delete(void *anAddress) |
25 | { TCollection_BasicMap::operator delete (anAddress); } |
26 | |
27 | public: |
28 | // ---------- PUBLIC METHODS ---------- |
29 | |
30 | /// Constructor |
31 | inline TColStd_PackedMapOfInteger (const Standard_Integer NbBuckets = 1) |
32 | : TCollection_BasicMap (NbBuckets, Standard_True), |
33 | myExtent (0) {} |
34 | |
35 | inline TColStd_PackedMapOfInteger& |
36 | operator = (const TColStd_PackedMapOfInteger& Other) |
37 | { return Assign(Other); } |
38 | |
39 | Standard_EXPORT TColStd_PackedMapOfInteger& |
40 | Assign (const TColStd_PackedMapOfInteger&); |
41 | Standard_EXPORT void ReSize (const Standard_Integer NbBuckets); |
42 | Standard_EXPORT void Clear (); |
43 | ~TColStd_PackedMapOfInteger() { Clear(); } |
44 | Standard_EXPORT Standard_Boolean |
45 | Add (const Standard_Integer aKey); |
46 | Standard_EXPORT Standard_Boolean |
47 | Contains (const Standard_Integer aKey) const; |
48 | Standard_EXPORT Standard_Boolean |
49 | Remove (const Standard_Integer aKey); |
50 | |
51 | inline Standard_Integer NbBuckets () const |
52 | { return TCollection_BasicMap::NbBuckets(); } |
53 | |
54 | inline Standard_Integer Extent () const |
55 | { return Standard_Integer (myExtent); } |
56 | |
57 | inline Standard_Integer IsEmpty () const |
58 | { return TCollection_BasicMap::IsEmpty(); } |
59 | |
60 | inline void Statistics (Standard_OStream& outStream) const |
61 | { TCollection_BasicMap::Statistics (outStream); } |
62 | |
63 | /** |
64 | * Query the minimal contained key value. |
65 | */ |
66 | Standard_EXPORT Standard_Integer GetMinimalMapped () const; |
67 | |
68 | /** |
69 | * Query the maximal contained key value. |
70 | */ |
71 | Standard_EXPORT Standard_Integer GetMaximalMapped () const; |
72 | |
73 | public: |
74 | //!@name Boolean operations with maps as sets of integers |
75 | //!@{ |
76 | |
77 | /** |
78 | * Sets this Map to be the result of union (aka addition, fuse, merge, |
79 | * boolean OR) operation between two given Maps. |
80 | * The new Map contains the values that are contained either in the |
81 | * first map or in the second map or in both.<br> |
82 | * All previous contents of this Map is cleared. This map (result of the |
83 | * boolean operation) can also be passed as one of operands.<br> |
84 | */ |
85 | Standard_EXPORT void Union (const TColStd_PackedMapOfInteger&, |
86 | const TColStd_PackedMapOfInteger&); |
87 | |
88 | /** |
89 | * Apply to this Map the boolean operation union (aka addition, fuse, merge, |
90 | * boolean OR) with another (given) Map. |
91 | * The result contains the values that were previously contained in |
92 | * this map or contained in the given (operand) map.<br> |
93 | * This algorithm is similar to method Union(). |
94 | * Returns True if contents of this map is changed. |
95 | */ |
96 | Standard_EXPORT Standard_Boolean Unite (const TColStd_PackedMapOfInteger&); |
97 | |
98 | /** |
99 | * Overloaded operator version of Unite(). |
100 | */ |
101 | TColStd_PackedMapOfInteger& operator |= (const TColStd_PackedMapOfInteger& MM) |
102 | { Unite(MM); return *this; } |
103 | |
104 | /** |
105 | * Sets this Map to be the result of intersection (aka multiplication, common, |
106 | * boolean AND) operation between two given Maps. |
107 | * The new Map contains only the values that are contained in both map |
108 | * operands.<br> |
109 | * All previous contents of this Map is cleared. This same map (result of the |
110 | * boolean operation) can also be used as one of operands.<br> |
111 | * The order of operands makes no difference; the method minimizes internally |
112 | * the number of iterations using the smallest map for the loop. |
113 | */ |
114 | Standard_EXPORT void Intersection (const TColStd_PackedMapOfInteger&, |
115 | const TColStd_PackedMapOfInteger&); |
116 | |
117 | /** |
118 | * Apply to this Map the intersection operation (aka multiplication, common, |
119 | * boolean AND) with another (given) Map. |
120 | * The result contains only the values that are contained in both this and |
121 | * the given maps.<br> |
122 | * This algorithm is similar to method Intersection(). |
123 | * Returns True if contents of this map is changed. |
124 | */ |
125 | Standard_EXPORT Standard_Boolean Intersect (const TColStd_PackedMapOfInteger&); |
126 | |
127 | /** |
128 | * Overloaded operator version of Intersect(). |
129 | */ |
130 | TColStd_PackedMapOfInteger& operator &= (const TColStd_PackedMapOfInteger& MM) |
131 | { Intersect(MM); return *this; } |
132 | |
133 | /** |
134 | * Sets this Map to be the result of subtraction (aka set-theoretic difference, |
135 | * relative complement, exclude, cut, boolean NOT) operation between two given Maps. |
136 | * The new Map contains only the values that are contained in the first map |
137 | * operands and not contained in the second one.<br> |
138 | * All previous contents of this Map is cleared. This map (result of the |
139 | * boolean operation) can also be used as the first operand.<br> |
140 | */ |
141 | Standard_EXPORT void Subtraction (const TColStd_PackedMapOfInteger&, |
142 | const TColStd_PackedMapOfInteger&); |
143 | |
144 | /** |
145 | * Apply to this Map the subtraction (aka set-theoretic difference, relative |
146 | * complement, exclude, cut, boolean NOT) operation with another (given) Map. |
147 | * The result contains only the values that were previously contained in |
148 | * this map and not contained in this map.<br> |
149 | * This algorithm is similar to method Subtract() with two operands. |
150 | * Returns True if contents of this map is changed. |
151 | */ |
152 | Standard_EXPORT Standard_Boolean Subtract (const TColStd_PackedMapOfInteger&); |
153 | |
154 | /** |
155 | * Overloaded operator version of Subtract(). |
156 | */ |
157 | TColStd_PackedMapOfInteger& operator -= (const TColStd_PackedMapOfInteger& MM) |
158 | { Subtract(MM); return *this; } |
159 | |
160 | /** |
161 | * Sets this Map to be the result of symmetric difference (aka exclusive |
162 | * disjunction, boolean XOR) operation between two given Maps. |
163 | * The new Map contains the values that are contained only in the |
164 | * first or the second operand maps but not in both.<br> |
165 | * All previous contents of this Map is cleared. This map (result of the |
166 | * boolean operation) can also be used as one of operands.<br> |
167 | */ |
168 | Standard_EXPORT void Difference (const TColStd_PackedMapOfInteger&, |
169 | const TColStd_PackedMapOfInteger&); |
170 | |
171 | /** |
172 | * Apply to this Map the symmetric difference (aka exclusive |
173 | * disjunction, boolean XOR) operation with another (given) Map. |
174 | * The result contains the values that are contained only in this |
175 | * or the operand map, but not in both.<br> |
176 | * This algorithm is similar to method Difference(). |
177 | * Returns True if contents of this map is changed. |
178 | */ |
179 | Standard_EXPORT Standard_Boolean Differ (const TColStd_PackedMapOfInteger&); |
180 | |
181 | /** |
182 | * Overloaded operator version of Differ(). |
183 | */ |
184 | TColStd_PackedMapOfInteger& operator ^= (const TColStd_PackedMapOfInteger& MM) |
185 | { Differ(MM); return *this; } |
186 | |
187 | /** |
188 | * Returns True if this map is equal to the given one, i.e. they contain the |
189 | * same sets of elements |
190 | */ |
191 | Standard_EXPORT Standard_Boolean IsEqual (const TColStd_PackedMapOfInteger&) const; |
192 | |
193 | /** |
194 | * Overloaded operator version of IsEqual(). |
195 | */ |
196 | Standard_Boolean operator == (const TColStd_PackedMapOfInteger& MM) const |
197 | { return IsEqual(MM); } |
198 | |
199 | /** |
200 | * Returns True if this map is subset of the given one, i.e. all elements |
201 | * contained in this map is contained also in the operand map. |
202 | * if this map is empty that this method returns true for any operand map. |
203 | */ |
204 | Standard_EXPORT Standard_Boolean IsSubset (const TColStd_PackedMapOfInteger&) const; |
205 | |
206 | /** |
207 | * Overloaded operator version of IsSubset(). |
208 | */ |
209 | Standard_Boolean operator <= (const TColStd_PackedMapOfInteger& MM) const |
210 | { return IsSubset(MM); } |
211 | |
212 | /** |
213 | * Returns True if this map has common items with the given one. |
214 | */ |
215 | Standard_EXPORT Standard_Boolean HasIntersection (const TColStd_PackedMapOfInteger&) const; |
216 | |
217 | //!@} |
218 | |
219 | protected: |
220 | // ---------- PROTECTED METHODS ---------- |
221 | inline Standard_Integer InternalExtent () const |
222 | { return TCollection_BasicMap::Extent(); } |
223 | |
224 | |
225 | private: |
226 | // ----------- PRIVATE (PROHIBITED) methods |
227 | /// Copy constructor - prohibited. |
228 | TColStd_PackedMapOfInteger (const TColStd_PackedMapOfInteger& theOther); |
229 | |
230 | |
231 | // ---------- PRIVATE FIELDS ---------- |
232 | |
233 | size_t myExtent; |
234 | |
235 | friend class TColStd_MapIteratorOfPackedMapOfInteger; |
236 | }; |
237 | |
238 | #endif |