Open CASCADE Technology 7.8.0
Data Structures | Public Types | Public Member Functions
NCollection_Map< TheKeyType, Hasher > Class Template Reference

#include <NCollection_Map.hxx>

Inheritance diagram for NCollection_Map< TheKeyType, Hasher >:
Inheritance graph
[legend]

Data Structures

class  Iterator
 Implementation of the Iterator interface. More...
 
class  MapNode
 Adaptation of the TListNode to the map notations. More...
 

Public Types

typedef TheKeyType key_type
 STL-compliant typedef for key type.
 
typedef Hasher hasher
 
typedef NCollection_StlIterator< std::forward_iterator_tag, Iterator, TheKeyType, trueconst_iterator
 Shorthand for a constant iterator type.
 

Public Member Functions

const_iterator cbegin () const
 Returns a const iterator pointing to the first element in the map.
 
const_iterator cend () const
 Returns a const iterator referring to the past-the-end element in the map.
 
 NCollection_Map ()
 Empty constructor.
 
 NCollection_Map (const Standard_Integer theNbBuckets, const Handle< NCollection_BaseAllocator > &theAllocator=0L)
 Constructor.
 
 NCollection_Map (const NCollection_Map &theOther)
 Copy constructor.
 
 NCollection_Map (NCollection_Map &&theOther) noexcept
 Move constructor.
 
void Exchange (NCollection_Map &theOther)
 Exchange the content of two maps without re-allocations. Notice that allocators will be swapped as well!
 
NCollection_MapAssign (const NCollection_Map &theOther)
 Assign. This method does not change the internal allocator.
 
NCollection_Mapoperator= (const NCollection_Map &theOther)
 Assign operator.
 
NCollection_Mapoperator= (NCollection_Map &&theOther) noexcept
 Move operator.
 
void ReSize (const Standard_Integer N)
 ReSize.
 
Standard_Boolean Add (const TheKeyType &theKey)
 Add.
 
Standard_Boolean Add (TheKeyType &&theKey)
 Add.
 
const TheKeyTypeAdded (const TheKeyType &theKey)
 Added: add a new key if not yet in the map, and return reference to either newly added or previously existing object.
 
const TheKeyTypeAdded (TheKeyType &&theKey)
 Added: add a new key if not yet in the map, and return reference to either newly added or previously existing object.
 
Standard_Boolean Contains (const TheKeyType &theKey) const
 Contains.
 
Standard_Boolean Remove (const TheKeyType &K)
 Remove.
 
void Clear (const Standard_Boolean doReleaseMemory=Standard_False)
 Clear data. If doReleaseMemory is false then the table of buckets is not released and will be reused.
 
void Clear (const Handle< NCollection_BaseAllocator > &theAllocator)
 Clear data and reset allocator.
 
virtual ~NCollection_Map (void)
 Destructor.
 
Standard_Integer Size (void) const
 Size.
 
- Public Member Functions inherited from NCollection_BaseMap
Standard_Integer NbBuckets () const
 NbBuckets.
 
Standard_Integer Extent () const
 Extent.
 
Standard_Boolean IsEmpty () const
 IsEmpty.
 
void Statistics (Standard_OStream &S) const
 Statistics.
 
const Handle< NCollection_BaseAllocator > & Allocator () const
 Returns attached allocator.
 

Boolean operations with maps as sets of keys

Hasher myHasher
 
Standard_Boolean IsEqual (const NCollection_Map &theOther) const
 
Standard_Boolean Contains (const NCollection_Map &theOther) const
 
void Union (const NCollection_Map &theLeft, const NCollection_Map &theRight)
 Sets this Map to be the result of union (aka addition, fuse, merge, boolean OR) operation between two given Maps The new Map contains the values that are contained either in the first map or in the second map or in both. All previous content of this Map is cleared. This map (result of the boolean operation) can also be passed as one of operands.
 
Standard_Boolean Unite (const NCollection_Map &theOther)
 Apply to this Map the boolean operation union (aka addition, fuse, merge, boolean OR) with another (given) Map. The result contains the values that were previously contained in this map or contained in the given (operand) map. This algorithm is similar to method Union(). Returns True if contents of this map is changed.
 
Standard_Boolean HasIntersection (const NCollection_Map &theMap) const
 Returns true if this and theMap have common elements.
 
void Intersection (const NCollection_Map &theLeft, const NCollection_Map &theRight)
 Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps. The new Map contains only the values that are contained in both map operands. All previous content of this Map is cleared. This same map (result of the boolean operation) can also be used as one of operands.
 
Standard_Boolean Intersect (const NCollection_Map &theOther)
 Apply to this Map the intersection operation (aka multiplication, common, boolean AND) with another (given) Map. The result contains only the values that are contained in both this and the given maps. This algorithm is similar to method Intersection(). Returns True if contents of this map is changed.
 
void Subtraction (const NCollection_Map &theLeft, const NCollection_Map &theRight)
 Sets this Map to be the result of subtraction (aka set-theoretic difference, relative complement, exclude, cut, boolean NOT) operation between two given Maps. The new Map contains only the values that are contained in the first map operands and not contained in the second one. All previous content of this Map is cleared.
 
Standard_Boolean Subtract (const NCollection_Map &theOther)
 Apply to this Map the subtraction (aka set-theoretic difference, relative complement, exclude, cut, boolean NOT) operation with another (given) Map. The result contains only the values that were previously contained in this map and not contained in this map. This algorithm is similar to method Subtract() with two operands. Returns True if contents of this map is changed.
 
void Difference (const NCollection_Map &theLeft, const NCollection_Map &theRight)
 Sets this Map to be the result of symmetric difference (aka exclusive disjunction, boolean XOR) operation between two given Maps. The new Map contains the values that are contained only in the first or the second operand maps but not in both. All previous content of this Map is cleared. This map (result of the boolean operation) can also be used as one of operands.
 
Standard_Boolean Differ (const NCollection_Map &theOther)
 Apply to this Map the symmetric difference (aka exclusive disjunction, boolean XOR) operation with another (given) Map. The result contains the values that are contained only in this or the operand map, but not in both. This algorithm is similar to method Difference(). Returns True if contents of this map is changed.
 
Standard_Boolean lookup (const TheKeyType &theKey, MapNode *&theNode, size_t &theHash) const
 Lookup for particular key in map.
 
Standard_Boolean lookup (const TheKeyType &theKey, MapNode *&theNode) const
 Lookup for particular key in map.
 
bool IsEqual (const TheKeyType &theKey1, const TheKeyType &theKey2) const
 
size_t HashCode (const TheKeyType &theKey, const int theUpperBound) const
 

Additional Inherited Members

- Protected Member Functions inherited from NCollection_BaseMap
 NCollection_BaseMap (const Standard_Integer NbBuckets, const Standard_Boolean single, const Handle< NCollection_BaseAllocator > &theAllocator)
 Constructor.
 
 NCollection_BaseMap (NCollection_BaseMap &&theOther) noexcept
 Move Constructor.
 
virtual ~NCollection_BaseMap ()
 Destructor.
 
Standard_Boolean BeginResize (const Standard_Integer NbBuckets, Standard_Integer &NewBuckets, NCollection_ListNode **&data1, NCollection_ListNode **&data2) const
 BeginResize.
 
void EndResize (const Standard_Integer NbBuckets, const Standard_Integer NewBuckets, NCollection_ListNode **data1, NCollection_ListNode **data2)
 EndResize.
 
Standard_Boolean Resizable () const
 Resizable.
 
Standard_Integer Increment ()
 Increment.
 
Standard_Integer Decrement ()
 Decrement.
 
void Destroy (NCollection_DelMapNode fDel, Standard_Boolean doReleaseMemory=Standard_True)
 Destroy.
 
Standard_Integer NextPrimeForMap (const Standard_Integer N) const
 NextPrimeForMap.
 
void exchangeMapsData (NCollection_BaseMap &theOther)
 Exchange content of two maps without data copying.
 
NCollection_BaseMapoperator= (NCollection_BaseMap &&) noexcept=delete
 Move operator.
 
 NCollection_BaseMap (const NCollection_BaseMap &)=delete
 Copy Constructor.
 
NCollection_BaseMapoperator= (const NCollection_BaseMap &)=delete
 Assign operator.
 
- Protected Attributes inherited from NCollection_BaseMap
Handle< NCollection_BaseAllocatormyAllocator
 
NCollection_ListNode ** myData1
 
NCollection_ListNode ** myData2
 

Detailed Description

template<class TheKeyType, class Hasher = NCollection_DefaultHasher<TheKeyType>>
class NCollection_Map< TheKeyType, Hasher >

Purpose: Single hashed Map. This Map is used to store and retrieve keys in linear time.

The ::Iterator class can be used to explore the content of the map. It is not wise to iterate and modify a map in parallel.

To compute the hashcode of the key the function HashCode must be defined in the global namespace

To compare two keys the function IsEqual must be defined in the global namespace.

The performance of a Map is conditioned by its number of buckets that should be kept greater to the number of keys. This map has an automatic management of the number of buckets. It is resized when the number of Keys becomes greater than the number of buckets.

If you have a fair idea of the number of objects you can save on automatic resizing by giving a number of buckets at creation or using the ReSize method. This should be consider only for crucial optimisation issues.

Member Typedef Documentation

◆ const_iterator

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
typedef NCollection_StlIterator<std::forward_iterator_tag, Iterator, TheKeyType, true> NCollection_Map< TheKeyType, Hasher >::const_iterator

Shorthand for a constant iterator type.

◆ hasher

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
typedef Hasher NCollection_Map< TheKeyType, Hasher >::hasher

◆ key_type

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
typedef TheKeyType NCollection_Map< TheKeyType, Hasher >::key_type

STL-compliant typedef for key type.

Constructor & Destructor Documentation

◆ NCollection_Map() [1/4]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map< TheKeyType, Hasher >::NCollection_Map ( )
inline

Empty constructor.

◆ NCollection_Map() [2/4]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map< TheKeyType, Hasher >::NCollection_Map ( const Standard_Integer  theNbBuckets,
const Handle< NCollection_BaseAllocator > &  theAllocator = 0L 
)
inlineexplicit

Constructor.

◆ NCollection_Map() [3/4]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map< TheKeyType, Hasher >::NCollection_Map ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Copy constructor.

◆ NCollection_Map() [4/4]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map< TheKeyType, Hasher >::NCollection_Map ( NCollection_Map< TheKeyType, Hasher > &&  theOther)
inlinenoexcept

Move constructor.

◆ ~NCollection_Map()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
virtual NCollection_Map< TheKeyType, Hasher >::~NCollection_Map ( void  )
inlinevirtual

Destructor.

Member Function Documentation

◆ Add() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Add ( const TheKeyType theKey)
inline

Add.

◆ Add() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Add ( TheKeyType &&  theKey)
inline

Add.

◆ Added() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
const TheKeyType & NCollection_Map< TheKeyType, Hasher >::Added ( const TheKeyType theKey)
inline

Added: add a new key if not yet in the map, and return reference to either newly added or previously existing object.

◆ Added() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
const TheKeyType & NCollection_Map< TheKeyType, Hasher >::Added ( TheKeyType &&  theKey)
inline

Added: add a new key if not yet in the map, and return reference to either newly added or previously existing object.

◆ Assign()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map & NCollection_Map< TheKeyType, Hasher >::Assign ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Assign. This method does not change the internal allocator.

◆ cbegin()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
const_iterator NCollection_Map< TheKeyType, Hasher >::cbegin ( ) const
inline

Returns a const iterator pointing to the first element in the map.

◆ cend()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
const_iterator NCollection_Map< TheKeyType, Hasher >::cend ( ) const
inline

Returns a const iterator referring to the past-the-end element in the map.

◆ Clear() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Clear ( const Handle< NCollection_BaseAllocator > &  theAllocator)
inline

Clear data and reset allocator.

◆ Clear() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Clear ( const Standard_Boolean  doReleaseMemory = Standard_False)
inline

Clear data. If doReleaseMemory is false then the table of buckets is not released and will be reused.

◆ Contains() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Contains ( const NCollection_Map< TheKeyType, Hasher > &  theOther) const
inline
Returns
true if this map contains ALL keys of another map.

◆ Contains() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Contains ( const TheKeyType theKey) const
inline

Contains.

◆ Differ()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Differ ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Apply to this Map the symmetric difference (aka exclusive disjunction, boolean XOR) operation with another (given) Map. The result contains the values that are contained only in this or the operand map, but not in both. This algorithm is similar to method Difference(). Returns True if contents of this map is changed.

◆ Difference()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Difference ( const NCollection_Map< TheKeyType, Hasher > &  theLeft,
const NCollection_Map< TheKeyType, Hasher > &  theRight 
)
inline

Sets this Map to be the result of symmetric difference (aka exclusive disjunction, boolean XOR) operation between two given Maps. The new Map contains the values that are contained only in the first or the second operand maps but not in both. All previous content of this Map is cleared. This map (result of the boolean operation) can also be used as one of operands.

◆ Exchange()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Exchange ( NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Exchange the content of two maps without re-allocations. Notice that allocators will be swapped as well!

◆ HashCode()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
size_t NCollection_Map< TheKeyType, Hasher >::HashCode ( const TheKeyType theKey,
const int  theUpperBound 
) const
inlineprotected
Returns
true if two maps contains exactly the same keys

◆ HasIntersection()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::HasIntersection ( const NCollection_Map< TheKeyType, Hasher > &  theMap) const
inline

Returns true if this and theMap have common elements.

◆ Intersect()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Intersect ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Apply to this Map the intersection operation (aka multiplication, common, boolean AND) with another (given) Map. The result contains only the values that are contained in both this and the given maps. This algorithm is similar to method Intersection(). Returns True if contents of this map is changed.

◆ Intersection()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Intersection ( const NCollection_Map< TheKeyType, Hasher > &  theLeft,
const NCollection_Map< TheKeyType, Hasher > &  theRight 
)
inline

Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps. The new Map contains only the values that are contained in both map operands. All previous content of this Map is cleared. This same map (result of the boolean operation) can also be used as one of operands.

◆ IsEqual() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::IsEqual ( const NCollection_Map< TheKeyType, Hasher > &  theOther) const
inline
Returns
true if two maps contains exactly the same keys

◆ IsEqual() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
bool NCollection_Map< TheKeyType, Hasher >::IsEqual ( const TheKeyType theKey1,
const TheKeyType theKey2 
) const
inlineprotected
Returns
true if two maps contains exactly the same keys

◆ lookup() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::lookup ( const TheKeyType theKey,
MapNode *&  theNode 
) const
inlineprotected

Lookup for particular key in map.

Parameters
[in]theKeykey to compute hash
[out]theNodethe detected node with equal key. Can be null.
Returns
true if key is found

◆ lookup() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::lookup ( const TheKeyType theKey,
MapNode *&  theNode,
size_t theHash 
) const
inlineprotected

Lookup for particular key in map.

Parameters
[in]theKeykey to compute hash
[out]theNodethe detected node with equal key. Can be null.
[out]theHashcomputed bounded hash code for current key.
Returns
true if key is found

◆ operator=() [1/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map & NCollection_Map< TheKeyType, Hasher >::operator= ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Assign operator.

◆ operator=() [2/2]

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
NCollection_Map & NCollection_Map< TheKeyType, Hasher >::operator= ( NCollection_Map< TheKeyType, Hasher > &&  theOther)
inlinenoexcept

Move operator.

◆ Remove()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Remove ( const TheKeyType K)
inline

Remove.

◆ ReSize()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::ReSize ( const Standard_Integer  N)
inline

ReSize.

◆ Size()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Integer NCollection_Map< TheKeyType, Hasher >::Size ( void  ) const
inline

Size.

◆ Subtract()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Subtract ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Apply to this Map the subtraction (aka set-theoretic difference, relative complement, exclude, cut, boolean NOT) operation with another (given) Map. The result contains only the values that were previously contained in this map and not contained in this map. This algorithm is similar to method Subtract() with two operands. Returns True if contents of this map is changed.

◆ Subtraction()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Subtraction ( const NCollection_Map< TheKeyType, Hasher > &  theLeft,
const NCollection_Map< TheKeyType, Hasher > &  theRight 
)
inline

Sets this Map to be the result of subtraction (aka set-theoretic difference, relative complement, exclude, cut, boolean NOT) operation between two given Maps. The new Map contains only the values that are contained in the first map operands and not contained in the second one. All previous content of this Map is cleared.

◆ Union()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
void NCollection_Map< TheKeyType, Hasher >::Union ( const NCollection_Map< TheKeyType, Hasher > &  theLeft,
const NCollection_Map< TheKeyType, Hasher > &  theRight 
)
inline

Sets this Map to be the result of union (aka addition, fuse, merge, boolean OR) operation between two given Maps The new Map contains the values that are contained either in the first map or in the second map or in both. All previous content of this Map is cleared. This map (result of the boolean operation) can also be passed as one of operands.

◆ Unite()

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Standard_Boolean NCollection_Map< TheKeyType, Hasher >::Unite ( const NCollection_Map< TheKeyType, Hasher > &  theOther)
inline

Apply to this Map the boolean operation union (aka addition, fuse, merge, boolean OR) with another (given) Map. The result contains the values that were previously contained in this map or contained in the given (operand) map. This algorithm is similar to method Union(). Returns True if contents of this map is changed.

Field Documentation

◆ myHasher

template<class TheKeyType , class Hasher = NCollection_DefaultHasher<TheKeyType>>
Hasher NCollection_Map< TheKeyType, Hasher >::myHasher
protected
Returns
true if two maps contains exactly the same keys

The documentation for this class was generated from the following file: