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

void TColStd_PackedMapOfInteger::Difference ( const TColStd_PackedMapOfInteger theMap1,
const TColStd_PackedMapOfInteger theMap2 
)

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 contents of this Map is cleared. This map (result of the boolean operation) can also be used as one of operands.

Definition at line 947 of file TColStd_PackedMapOfInteger.cxx.

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

{
  if (theMap1.IsEmpty()) // 0 ^ B == B
    Assign (theMap2);
  else if (theMap2.IsEmpty()) // A ^ 0 == A
    Assign (theMap1);
  else if (myData1 == theMap1.myData1)
    Differ(theMap2);
  else if (myData1 == theMap2.myData1)
    Differ(theMap1);
  else {
    Standard_Integer i;
    const TColStd_intMapNode** aData1 =
      (const TColStd_intMapNode**) theMap1.myData1;
    const TColStd_intMapNode** aData2 =
      (const TColStd_intMapNode**) theMap2.myData1;
    const Standard_Integer nBuckets1 = theMap1.NbBuckets();
    const Standard_Integer nBuckets2 = theMap2.NbBuckets();
    Clear();
    TColStd_intMapNode** aData = (TColStd_intMapNode**) myData1;

    // Iteration of the 1st map.
    for (i = 0; i <= nBuckets1; i++) {
      const TColStd_intMapNode * p1 = aData1[i];
      while (p1 != 0L) {
        // Find aKey - the base address of currently iterated block of integers
        const Standard_Integer aKey = p1->Key();
        const Standard_Integer aKeyInt = aKey >> 5;
        unsigned int aNewMask = p1->Mask();
        unsigned int aNewData = p1->Data();
        size_t       nValues (p1->NbValues());
        // Find the corresponding block in the 2nd map
        const TColStd_intMapNode * p2 =
          aData2 [HashCode (aKeyInt, nBuckets2)];
        while (p2) {
          if (p2->IsEqual(aKeyInt)) {
            aNewData ^= p2->Data();
            nValues = TColStd_Population (aNewMask, aNewData);
            break;
          }
          p2 = reinterpret_cast <const TColStd_intMapNode*> (p2->Next());
        }
        // Store the block - result of operation
        if (aNewData) {
          if (Resizable()) {
            ReSize(InternalExtent());
            aData = (TColStd_intMapNode**) myData1;
          }
          const Standard_Integer aHashCode = HashCode (aKeyInt, NbBuckets());
          aData[aHashCode]= new TColStd_intMapNode (aNewMask, aNewData,
                                                    aData[aHashCode]);
          Increment();
          myExtent += nValues;
        }
        p1 = reinterpret_cast <const TColStd_intMapNode*> (p1->Next());
      }
    }
    
    // Iteration of the 2nd map.
    for (i = 0; i <= nBuckets2; i++) {
      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
        const TColStd_intMapNode * p1 =
          aData1 [HashCode (aKeyInt, nBuckets1)];
        while (p1) {
          if (p1->IsEqual(aKeyInt))
            break;
          p1 = reinterpret_cast <const TColStd_intMapNode*> (p1->Next());
        }
        // Add the block from the 2nd map only in the case when the similar
        // block has not been found in the 1st map
        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();
          myExtent += p2->NbValues();
        }
        p2 = reinterpret_cast <const TColStd_intMapNode*> (p2->Next());
      }
    }
  }
}


Generated by  Doxygen 1.6.0   Back to index