Logo Search packages:      
Sourcecode: opencascade version File versions  Download package

Standard_Boolean TColStd_PackedMapOfInteger::Unite ( const TColStd_PackedMapOfInteger theMap  ) 

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.

Definition at line 607 of file TColStd_PackedMapOfInteger.cxx.

References TColStd_intMapNode::ChangeData(), TColStd_intMapNode::ChangeMask(), TColStd_intMapNode::Data(), TCollection_BasicMap::Increment(), IsEmpty(), TColStd_intMapNode::IsEqual(), TColStd_intMapNode::Key(), TColStd_intMapNode::Mask(), TCollection_BasicMap::myData1, NbBuckets(), TColStd_intMapNode::NbValues(), and TCollection_BasicMap::Resizable().

Referenced by operator|=(), NIS_InteractiveContext::ProcessSelection(), NIS_InteractiveContext::SetSelectable(), NIS_InteractiveContext::SetSelected(), and Union().

{
  if (theMap.IsEmpty() || myData1 == theMap.myData1) // A | 0 == A | A == A
    return Standard_False;
  else if ( IsEmpty() ) { // 0 | B == B
    Assign ( theMap );
    return Standard_True;
  }
  else {
    size_t aNewExtent (myExtent);
    TColStd_intMapNode** aData = (TColStd_intMapNode**) myData1;
    const TColStd_intMapNode** aData2 =
      (const TColStd_intMapNode**) theMap.myData1;
    const Standard_Integer nBuckets2 = theMap.NbBuckets();

    // Iteration of the 2nd map.
    for (Standard_Integer i = 0; i <= nBuckets2; i++) {
      const TColStd_intMapNode * p2 = aData2[i];
      while (p2 != 0L) {
        // Find aKey - the base address of currently iterated block of integers
        const Standard_Integer aKey = p2->Key();
        const Standard_Integer aKeyInt = aKey >> 5;
        // Find the corresponding block in the 1st (this) map
        Standard_Integer aHashCode = HashCode (aKeyInt, NbBuckets());
        TColStd_intMapNode * p1 = aData[aHashCode];
        while (p1) {
          if (p1->IsEqual(aKeyInt)) {
            const size_t anOldPop = p1->NbValues();
            Standard_Integer newData = p1->Data() | p2->Data();
            if ( newData != p1->Data() ) {
              p1->ChangeData() = newData;
              aNewExtent = aNewExtent - anOldPop +
                           TColStd_Population (p1->ChangeMask(), newData);
            }
            break;
          }
          p1 = reinterpret_cast <TColStd_intMapNode*> (p1->Next());
        }
        // If the block is not found in the 1st map, add it to the 1st map
        if (p1 == 0L) {
          if (Resizable()) {
            ReSize(InternalExtent());
            aData = (TColStd_intMapNode**) myData1;
            aHashCode = HashCode (aKeyInt, NbBuckets());
          }
          aData[aHashCode] = new TColStd_intMapNode (p2->Mask(), p2->Data(),
                                                     aData[aHashCode]);
          Increment();
          aNewExtent += p2->NbValues();
        }
        p2 = reinterpret_cast <TColStd_intMapNode*> (p2->Next());
      }
    }
    Standard_Boolean isChanged = ( myExtent != aNewExtent );
    myExtent = aNewExtent;
    return isChanged;
  }
}


Generated by  Doxygen 1.6.0   Back to index