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

Standard_Boolean TColStd_PackedMapOfInteger::Differ ( const TColStd_PackedMapOfInteger theMap  ) 

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.

Definition at line 1045 of file TColStd_PackedMapOfInteger.cxx.

References TColStd_intMapNode::ChangeData(), TColStd_intMapNode::ChangeMask(), TColStd_intMapNode::Data(), TCollection_BasicMap::Decrement(), 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 Difference(), and operator^=().

{
  if (theMap.IsEmpty()) // A ^ 0 = A
    return Standard_False;    
  else if (IsEmpty()) { // 0 ^ B = B
    Assign ( theMap );
    return Standard_True;
  }
  else if( myData1 == theMap.myData1) { // A ^ A == 0
    Clear();
    return Standard_True;
  }
  else {
    size_t aNewExtent (0);
    TColStd_intMapNode** aData1 = (TColStd_intMapNode**) myData1;
    const TColStd_intMapNode** aData2 =
      (const TColStd_intMapNode**) theMap.myData1;
    const Standard_Integer nBuckets2 = theMap.NbBuckets();
    Standard_Boolean isChanged = Standard_False;
    Standard_Integer i = 0;
    // Iteration by other map
    for ( ; i <= nBuckets2; i++) {
       TColStd_intMapNode * q  = 0L;
      const TColStd_intMapNode * p2 = aData2[i];
      while (p2 != 0L) {
        // Find aKey - the base address of currently iterated block
        const Standard_Integer aKey = p2->Key();
        const Standard_Integer aKeyInt = aKey >> 5;
        
        // Find the corresponding block in the 1st map
        TColStd_intMapNode * p1 =
          aData1[HashCode (aKeyInt, NbBuckets())];
        TColStd_intMapNode* pNext =
          reinterpret_cast <TColStd_intMapNode*> (p1->Next());
        
        while (p1) {
          if (p1->IsEqual(aKeyInt)) {
            const unsigned int aNewData = p1->Data() ^ p2->Data();
            // Store the block - result of operation
            if (aNewData == 0) {
              // no match - the block has to be removed
              Decrement();
              if (q)  q->Next() = pNext;
              else    aData1[i]  = pNext;
              delete p1;
            } 
            else if ( aNewData != p1->Data() ) {
              p1->ChangeData() = aNewData;
              isChanged = Standard_True;
              aNewExtent += TColStd_Population (p1->ChangeMask(), aNewData);
              q = p1;
            }
            break;
          }
          p1 = pNext;
        }
        // Add the block from the 2nd map only in the case when the similar
        // block has not been found in the 1st map
        TColStd_intMapNode** aData = NULL;
        if (p1 == 0L) {
          if (Resizable()) {
            ReSize(InternalExtent());
            aData = (TColStd_intMapNode**) myData1;
          }
          const Standard_Integer aHashCode = HashCode (aKeyInt, NbBuckets());
          aData[aHashCode]= new TColStd_intMapNode (p2->Mask(), p2->Data(),
                                                    aData[aHashCode]);
          Increment();
          aNewExtent += p2->NbValues();
          isChanged = Standard_True;
        }
        p2 = reinterpret_cast <const TColStd_intMapNode*> (p2->Next());
      }
    }
    myExtent = aNewExtent;
    return isChanged;
  }
}


Generated by  Doxygen 1.6.0   Back to index