0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / TColStd / TColStd_PackedMapOfInteger.hxx
CommitLineData
b311480e 1// Created on: 2005-11-05
2// Created by: Alexander GRIGORIEV
973c2be1 3// Copyright (c) 2005-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#ifndef TColStd_PackedMapOfInteger_HeaderFile
17#define TColStd_PackedMapOfInteger_HeaderFile
18
1c35b92f 19#include <Standard_DefineAlloc.hxx>
7fd59977 20#include <TCollection_BasicMap.hxx>
21
22/**
ebc93ae7 23 * Optimized Map of integer values. Each block of 32 integers is stored in 8 bytes in memory.
7fd59977 24 */
7fd59977 25class TColStd_PackedMapOfInteger : private TCollection_BasicMap
26{
27 public:
28 // operators new and delete must be defined explicitly
29 // since inherited ones are not accessible
1c35b92f 30 DEFINE_STANDARD_ALLOC
7fd59977 31
32 public:
33 // ---------- PUBLIC METHODS ----------
34
35 /// Constructor
36 inline TColStd_PackedMapOfInteger (const Standard_Integer NbBuckets = 1)
37 : TCollection_BasicMap (NbBuckets, Standard_True),
38 myExtent (0) {}
39
39ef94f8 40 /// Copy constructor
41 inline TColStd_PackedMapOfInteger (const TColStd_PackedMapOfInteger& theOther)
42 : TCollection_BasicMap (1, Standard_True),
43 myExtent (0)
44 { Assign(theOther); }
45
7fd59977 46 inline TColStd_PackedMapOfInteger&
47 operator = (const TColStd_PackedMapOfInteger& Other)
48 { return Assign(Other); }
49
50 Standard_EXPORT TColStd_PackedMapOfInteger&
51 Assign (const TColStd_PackedMapOfInteger&);
52 Standard_EXPORT void ReSize (const Standard_Integer NbBuckets);
53 Standard_EXPORT void Clear ();
54 ~TColStd_PackedMapOfInteger() { Clear(); }
55 Standard_EXPORT Standard_Boolean
56 Add (const Standard_Integer aKey);
57 Standard_EXPORT Standard_Boolean
58 Contains (const Standard_Integer aKey) const;
59 Standard_EXPORT Standard_Boolean
60 Remove (const Standard_Integer aKey);
61
62 inline Standard_Integer NbBuckets () const
63 { return TCollection_BasicMap::NbBuckets(); }
64
65 inline Standard_Integer Extent () const
66 { return Standard_Integer (myExtent); }
67
dde68833 68 inline Standard_Boolean IsEmpty () const
7fd59977 69 { return TCollection_BasicMap::IsEmpty(); }
70
71 inline void Statistics (Standard_OStream& outStream) const
72 { TCollection_BasicMap::Statistics (outStream); }
73
74 /**
75 * Query the minimal contained key value.
76 */
77 Standard_EXPORT Standard_Integer GetMinimalMapped () const;
78
79 /**
80 * Query the maximal contained key value.
81 */
82 Standard_EXPORT Standard_Integer GetMaximalMapped () const;
83
84public:
85 //!@name Boolean operations with maps as sets of integers
86 //!@{
ebc93ae7 87
7fd59977 88 /**
ebc93ae7 89 * Sets this Map to be the result of union (aka addition, fuse, merge, boolean OR) operation between two given Maps.
90 * The new Map contains the values that are contained either in the first map or in the second map or in both.
91 * All previous contents of this Map is cleared. This map (result of the boolean operation) can also be passed as one of operands.
7fd59977 92 */
93 Standard_EXPORT void Union (const TColStd_PackedMapOfInteger&,
94 const TColStd_PackedMapOfInteger&);
95
96 /**
ebc93ae7 97 * Apply to this Map the boolean operation union (aka addition, fuse, merge, boolean OR) with another (given) Map.
98 * The result contains the values that were previously contained in this map or contained in the given (operand) map.
7fd59977 99 * This algorithm is similar to method Union().
ebc93ae7 100 * @return True if content of this map is changed
7fd59977 101 */
102 Standard_EXPORT Standard_Boolean Unite (const TColStd_PackedMapOfInteger&);
103
104 /**
105 * Overloaded operator version of Unite().
106 */
107 TColStd_PackedMapOfInteger& operator |= (const TColStd_PackedMapOfInteger& MM)
108 { Unite(MM); return *this; }
109
110 /**
ebc93ae7 111 * Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps.
112 * The new Map contains only the values that are contained in both map operands.
113 * All previous contents of this Map is cleared. This same map (result of the boolean operation) can also be used as one of operands.
114 * The order of operands makes no difference; the method minimizes internally the number of iterations using the smallest map for the loop.
7fd59977 115 */
116 Standard_EXPORT void Intersection (const TColStd_PackedMapOfInteger&,
117 const TColStd_PackedMapOfInteger&);
118
119 /**
ebc93ae7 120 * Apply to this Map the intersection operation (aka multiplication, common, boolean AND) with another (given) Map.
121 * The result contains only the values that are contained in both this and the given maps.
7fd59977 122 * This algorithm is similar to method Intersection().
ebc93ae7 123 * @return True if content of this map is changed
7fd59977 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 /**
ebc93ae7 134 * Sets this Map to be the result of subtraction
135 * (aka set-theoretic difference, 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 operands and not contained in the second one.
137 * All previous contents of this Map is cleared.
138 * This map (result of the boolean operation) can also be used as the first operand.
7fd59977 139 */
140 Standard_EXPORT void Subtraction (const TColStd_PackedMapOfInteger&,
141 const TColStd_PackedMapOfInteger&);
142
143 /**
ebc93ae7 144 * Apply to this Map the subtraction (aka set-theoretic difference, relative complement, exclude, cut, boolean NOT) operation with another (given) Map.
145 * The result contains only the values that were previously contained in this map and not contained in this map.
7fd59977 146 * This algorithm is similar to method Subtract() with two operands.
ebc93ae7 147 * @return True if contents of this map is changed
7fd59977 148 */
149 Standard_EXPORT Standard_Boolean Subtract (const TColStd_PackedMapOfInteger&);
150
151 /**
152 * Overloaded operator version of Subtract().
153 */
154 TColStd_PackedMapOfInteger& operator -= (const TColStd_PackedMapOfInteger& MM)
155 { Subtract(MM); return *this; }
156
157 /**
ebc93ae7 158 * Sets this Map to be the result of symmetric difference (aka exclusive disjunction, boolean XOR) operation between two given Maps.
159 * The new Map contains the values that are contained only in the first or the second operand maps but not in both.
160 * All previous contents of this Map is cleared.
161 * This map (result of the boolean operation) can also be used as one of operands.
7fd59977 162 */
163 Standard_EXPORT void Difference (const TColStd_PackedMapOfInteger&,
164 const TColStd_PackedMapOfInteger&);
165
166 /**
ebc93ae7 167 * Apply to this Map the symmetric difference (aka exclusive disjunction, boolean XOR) operation with another (given) Map.
168 * The result contains the values that are contained only in this or the operand map, but not in both.
7fd59977 169 * This algorithm is similar to method Difference().
ebc93ae7 170 * @return True if contents of this map is changed
7fd59977 171 */
172 Standard_EXPORT Standard_Boolean Differ (const TColStd_PackedMapOfInteger&);
173
174 /**
175 * Overloaded operator version of Differ().
176 */
177 TColStd_PackedMapOfInteger& operator ^= (const TColStd_PackedMapOfInteger& MM)
178 { Differ(MM); return *this; }
179
180 /**
181 * Returns True if this map is equal to the given one, i.e. they contain the
182 * same sets of elements
183 */
184 Standard_EXPORT Standard_Boolean IsEqual (const TColStd_PackedMapOfInteger&) const;
185
186 /**
187 * Overloaded operator version of IsEqual().
188 */
189 Standard_Boolean operator == (const TColStd_PackedMapOfInteger& MM) const
190 { return IsEqual(MM); }
191
192 /**
193 * Returns True if this map is subset of the given one, i.e. all elements
194 * contained in this map is contained also in the operand map.
195 * if this map is empty that this method returns true for any operand map.
196 */
197 Standard_EXPORT Standard_Boolean IsSubset (const TColStd_PackedMapOfInteger&) const;
198
199 /**
200 * Overloaded operator version of IsSubset().
201 */
202 Standard_Boolean operator <= (const TColStd_PackedMapOfInteger& MM) const
203 { return IsSubset(MM); }
204
205 /**
206 * Returns True if this map has common items with the given one.
207 */
208 Standard_EXPORT Standard_Boolean HasIntersection (const TColStd_PackedMapOfInteger&) const;
209
210 //!@}
211
212 protected:
213 // ---------- PROTECTED METHODS ----------
214 inline Standard_Integer InternalExtent () const
215 { return TCollection_BasicMap::Extent(); }
216
217
218 private:
7fd59977 219 // ---------- PRIVATE FIELDS ----------
220
221 size_t myExtent;
222
223 friend class TColStd_MapIteratorOfPackedMapOfInteger;
224};
225
226#endif