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

Standard_Boolean TColStd_PackedMapOfInteger::Intersect ( const TColStd_PackedMapOfInteger theMap  ) 

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.

Definition at line 741 of file TColStd_PackedMapOfInteger.cxx.

References TColStd_intMapNode::ChangeData(), TColStd_intMapNode::ChangeMask(), TColStd_intMapNode::Data(), TCollection_BasicMap::Decrement(), IsEmpty(), TColStd_intMapNode::IsEqual(), TColStd_intMapNode::Key(), TCollection_BasicMap::myData1, and NbBuckets().

Referenced by Intersection(), operator &=(), and NIS_InteractiveContext::ProcessSelection().

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

    // Iteration of this map.
    for (Standard_Integer i = 0; i <= NbBuckets(); i++) {
      TColStd_intMapNode * q  = 0L;
      TColStd_intMapNode * p1 = aData[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;
        // Find the corresponding block in the 2nd map
        const TColStd_intMapNode * p2 =
          aData2 [HashCode (aKeyInt, nBuckets2)];
        while (p2) {
          if (p2->IsEqual(aKeyInt)) {
            const unsigned int aNewData = p1->Data() & p2->Data();
            // Store the block - result of operation
            if (aNewData == 0)
              p2 = 0L;  // no match - the block has to be removed
            else if ( aNewData != p1->Data() ) {
              p1->ChangeData() = aNewData;
              aNewExtent += TColStd_Population (p1->ChangeMask(), aNewData);
            }
            break;
          }
          p2 = reinterpret_cast <const TColStd_intMapNode*> (p2->Next());
        }
        TColStd_intMapNode* pNext =
          reinterpret_cast <TColStd_intMapNode*> (p1->Next());
        // If p2!=NULL, then the map node is kept and we move to the next one
        // Otherwise we should remove the current node
        if (p2)
          q = p1;
        else {
          Decrement();
          if (q)  q->Next() = pNext;
          else    aData[i]  = pNext;
          delete p1;
        }
        p1 = pNext;
      }
    }
    Standard_Boolean isChanged = ( myExtent != aNewExtent );
    myExtent = aNewExtent;
    return isChanged;
  }
}


Generated by  Doxygen 1.6.0   Back to index