1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-20 11:54:07 +03:00
occt/src/PCollection/PCollection_HDoubleMap.gxx
bugmaster b311480ed5 0023024: Update headers of OCCT files
Added appropriate copyright and license information in source files
2012-03-21 19:43:04 +04:00

328 lines
11 KiB
Plaintext
Executable File

// Copyright (c) 1992-1999 Matra Datavision
// Copyright (c) 1999-2012 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
// except in compliance with the License. Please obtain a copy of the License
// at http://www.opencascade.org and read it completely before using this file.
//
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
//
// The Original Code and all software distributed under the License is
// distributed on an "AS IS" basis, without warranty of any kind, and the
// Initial Developer hereby disclaims all such warranties, including without
// limitation, any warranties of merchantability, fitness for a particular
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
//-Version:
// Version Date Purpose
// 14/12/92 Creation
//-Language C++2.0
//-Declarations
#include <Standard_MultiplyDefined.hxx>
#include <Standard_NoSuchObject.hxx>
//=======================================================================
// Function : HDoubleMap
//=======================================================================
PCollection_HDoubleMap::PCollection_HDoubleMap
(
const Standard_Integer NbBuckets ,
const KeyHash &fhKey,
const ItemHash &fhItem )
{
myArrayKey = new PCollection_ArrayDoubleMap(1,NbBuckets);
myArrayItem = new PCollection_ArrayDoubleMap(1,NbBuckets);
myKeyHash = fhKey;
myItemHash = fhItem;
myNumber = 0;
}
//=======================================================================
// Function : NbBuckets
//=======================================================================
Standard_Integer PCollection_HDoubleMap::NbBuckets() const
{
return myArrayKey->Length();
}
//=======================================================================
// Function : Extent
//=======================================================================
Standard_Integer PCollection_HDoubleMap::Extent() const
{
return myNumber;
}
//=======================================================================
// Function : Bind
//=======================================================================
void PCollection_HDoubleMap::Bind (const Key &aKey , const Item &anItem)
{
Standard_Integer ResHashKey,ResHashItem;
Handle(PCollection_DoubleMapNode) theNewNode;
if ( IsBoundByKey(aKey) || IsBoundByItem(anItem) )
Standard_MultiplyDefined::Raise();
else {
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
theNewNode =
new PCollection_DoubleMapNode(aKey,anItem,
myArrayKey->Value(ResHashKey),
myArrayItem->Value(ResHashItem));
myArrayKey->SetValue(ResHashKey,theNewNode);
myArrayItem->SetValue(ResHashItem,theNewNode);
myNumber++;
}
}
//=======================================================================
// Function : FindItem
//=======================================================================
Item PCollection_HDoubleMap::FindItem ( const Key &aKey ) const
{
Standard_Integer ResHashKey;
Handle(PCollection_DoubleMapNode) theKeyNode;
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
theKeyNode = myArrayKey->Value(ResHashKey);
while ( ! theKeyNode.IsNull() ) {
if ( myKeyHash.Compare(theKeyNode->GetKey(),aKey) )
return theKeyNode->GetItem();
else theKeyNode = theKeyNode->NextKey();
}
Standard_NoSuchObject::Raise();
}
//=======================================================================
// Function : FindKey
//=======================================================================
Key PCollection_HDoubleMap::FindKey ( const Item &anItem ) const
{
Standard_Integer ResHashItem;
Handle(PCollection_DoubleMapNode) theItemNode;
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
theItemNode = myArrayItem->Value(ResHashItem);
while ( ! theItemNode.IsNull() ) {
if ( myItemHash.Compare(theItemNode->GetItem(),anItem) )
return theItemNode->GetKey();
else theItemNode = theItemNode->NextItem();
}
Standard_NoSuchObject::Raise();
}
//=======================================================================
// Function : UnbindKey
//=======================================================================
void PCollection_HDoubleMap::UnbindKey ( const Key &aKey )
{
Standard_Integer ResHashKey,ResHashItem;
Handle(PCollection_DoubleMapNode)
currentKeyNode,previousKeyNode,previousItemNode,currentItemNode,nullNode;
Standard_Boolean NoKey = Standard_True;
Standard_Boolean NoItem = Standard_True;
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
currentKeyNode = myArrayKey->Value(ResHashKey);
while ( NoKey && !currentKeyNode.IsNull() ) {
if ( myKeyHash.Compare(currentKeyNode->GetKey(),aKey) )
NoKey = Standard_False;
else {
previousKeyNode = currentKeyNode;
currentKeyNode = currentKeyNode->NextKey();
}
}
if ( NoKey ) Standard_NoSuchObject::Raise();
else {
ResHashItem =
myItemHash.HashCode(currentKeyNode->GetItem(),myArrayItem->Length());
currentItemNode = myArrayItem->Value(ResHashItem);
while ( NoItem && !currentItemNode.IsNull() ) {
if ( currentItemNode == currentKeyNode ) NoItem = Standard_False;
else {
previousItemNode = currentItemNode;
currentItemNode = currentItemNode->NextItem();
}
}
if ( NoItem ) Standard_NoSuchObject::Raise();
else {
if ( previousKeyNode.IsNull() )
myArrayKey->SetValue(ResHashKey,currentKeyNode->NextKey());
else
previousKeyNode->SetNextKey(currentKeyNode->NextKey());
if ( previousItemNode.IsNull() )
myArrayItem->SetValue(ResHashItem,currentItemNode->NextItem());
else
previousItemNode->SetNextItem(currentItemNode->NextItem());
myNumber--;
currentKeyNode->SetNextKey(nullNode);
currentKeyNode->SetNextItem(nullNode);
currentKeyNode.Delete();
}
}
}
//=======================================================================
// Function : UnbindItem
//=======================================================================
void PCollection_HDoubleMap::UnbindItem ( const Item &anItem )
{
Standard_Integer ResHashKey,ResHashItem;
Handle(PCollection_DoubleMapNode)
currentKeyNode,previousKeyNode,previousItemNode,currentItemNode,nullNode;
Standard_Boolean NoKey = Standard_True;
Standard_Boolean NoItem = Standard_True;
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
currentItemNode = myArrayItem->Value(ResHashItem);
while ( NoItem && !currentItemNode.IsNull() ) {
if ( myItemHash.Compare(currentItemNode->GetItem(),anItem) )
NoItem = Standard_False;
else {
previousItemNode = currentItemNode;
currentItemNode = currentItemNode->NextItem();
}
}
if ( NoItem ) Standard_NoSuchObject::Raise();
else {
ResHashKey =
myKeyHash.HashCode(currentItemNode->GetKey(),myArrayKey->Length());
currentKeyNode = myArrayKey->Value(ResHashKey);
while ( NoKey && !currentKeyNode.IsNull() ) {
if ( currentKeyNode == currentItemNode ) NoKey = Standard_False;
else {
previousKeyNode = currentKeyNode;
currentKeyNode = currentKeyNode->NextKey();
}
}
if ( NoKey ) Standard_NoSuchObject::Raise();
else {
if ( previousItemNode.IsNull() )
myArrayItem->SetValue(ResHashItem,currentItemNode->NextItem());
else
previousItemNode->SetNextItem(currentItemNode->NextItem());
if ( previousKeyNode.IsNull() )
myArrayKey->SetValue(ResHashKey,currentKeyNode->NextKey());
else
previousKeyNode->SetNextKey(currentKeyNode->NextKey());
myNumber--;
currentItemNode->SetNextItem(nullNode);
currentItemNode->SetNextKey(nullNode);
currentItemNode.Delete();
}
}
}
//=======================================================================
// Function : Clear
//=======================================================================
void PCollection_HDoubleMap::Clear ()
{
Handle(PCollection_DoubleMapNode) nullNode,theNode,delNode;
Standard_Integer I;
myNumber = 0;
for ( I = 1 ; I <= myArrayItem->Length() ; I++ ) {
theNode = myArrayItem->Value(I);
myArrayKey->SetValue(I,nullNode);
myArrayItem->SetValue(I,nullNode);
while ( !theNode.IsNull() ) {
delNode = theNode;
theNode = theNode->NextItem();
delNode->SetNextKey(nullNode);
delNode->SetNextItem(nullNode);
delNode.Delete();
}
}
}
//=======================================================================
// Function : IsBoundByKey
//=======================================================================
Standard_Boolean PCollection_HDoubleMap::IsBoundByKey ( const Key &aKey ) const
{
Standard_Integer ResHashKey;
Handle(PCollection_DoubleMapNode) theKeyNode;
ResHashKey = myKeyHash.HashCode(aKey,myArrayKey->Length());
theKeyNode = myArrayKey->Value(ResHashKey);
while ( ! theKeyNode.IsNull() ) {
if ( myKeyHash.Compare(theKeyNode->GetKey(),aKey) )
return Standard_True;
else theKeyNode = theKeyNode->NextKey();
}
return Standard_False;
}
//=======================================================================
// Function : IsBoundByItem
//=======================================================================
Standard_Boolean PCollection_HDoubleMap::IsBoundByItem(const Item &anItem) const
{
Standard_Integer ResHashItem;
Handle(PCollection_DoubleMapNode) theItemNode;
ResHashItem = myItemHash.HashCode(anItem,myArrayItem->Length());
theItemNode = myArrayItem->Value(ResHashItem);
while ( ! theItemNode.IsNull() ) {
if ( myItemHash.Compare(theItemNode->GetItem(),anItem) )
return Standard_True;
else theItemNode = theItemNode->NextItem();
}
return Standard_False;
}
//=======================================================================
// Function : IsEmpty
//=======================================================================
Standard_Boolean PCollection_HDoubleMap::IsEmpty () const
{
Standard_Boolean Empty = Standard_True;
for ( Standard_Integer I = 1 ; I <= myArrayKey->Length() && Empty ; I++ )
if ( ! myArrayKey->Value(I).IsNull() ) Empty = Standard_False;
return Empty;
}
//=======================================================================
// Function : GetArrayKey
//=======================================================================
Handle(PCollection_ArrayDoubleMap) PCollection_HDoubleMap::
GetArrayKey () const
{
return myArrayKey;
}