View Issue Details

IDProjectCategoryView StatusLast Update
0022718CommunityOCCT:Foundation Classespublic2012-09-18 19:12
ReporterszyAssigned Toagv 
PrioritynormalSeverityfeature 
Status closedResolutionduplicate 
PlatformAOSL 
Product Version6.5.1 
Target Version6.5.3Fixed in Version6.5.3 
Summary0022718: NCollection improvement request
DescriptionPost from the Forum - http://www.opencascade.org/org/forum/thread_21658/.
"Right now associative containers in NCollection (e.g. NCollection_DataMap) use global functions ::HashCode() and ::IsEqual() to compute hash value for the key and to compare keys. This makes it impossible to use containers requiring different functions for the same key in one compilation unit.

An example is use of NCollection_DataMap with TopoDS_Shape as key and IsEqual() using TopoDS_Shape::IsSame(), ignoring orientation and used in most cases and TopoDS_Shape::IsEqual() taking orientation into account. Though I have realized this limitation long ago, I have not reported it until the moment I encountered it (though probably should have). Salome includes SMESHDS_DataMapOfShape.hxx which enforces use of TopoDS_Shape::IsSame() and I need a map of oriented shapes.

Obvious suggestion is to extend NCollection templates with additional template arguments, just like standard collections allow (e.g. in STL or Boost). Parameters would default to current behavior to retain source compatibility.

Until this is available directly in Open CASCADE, the work-around could be to use boost::unordered_map with provided custom hash and equality functions. This is the way I am going to pursue."
Additional information
and documentation updates
ABV:
Please note that this idea has already been considered (initially proposed by PKV), just it requires some efforts to be completed.
See attached couple of mails I exchanged with Roman.
=================
1. Hello Roman,

We have tried to implement this idea; the problem was to keep existing ease-to-use by providing default hash functions for typical OCCT data.
I do not recall what was a blocking point exactly (likely poor old SUN comiler, dropped some time ago for reasons like that).
Thanks for reminder, I shall reiterate on this when I have time.

Best Regards,
Andrey
==============
2. Hi Andrey,

Thanks for paying attention to this. Here is the code I had in mind that would retain default behavior. I believe it is compilable by any decent modern compiler.
HTH.
Roman

The requirement to new extra template parameters - to have defined operator() with signature similar to ::HashCode() and ::IsEqual(). Use of operator() is taken
from boost (and STL I believe). The added value of it is that you can use lambda functions to define them.



template<typename T>
class Hasher
{
public:
    Standard_Integer operator() (const T& theKey, const Standard_Integer theUpper) const
    { return ::HashCode (theKey, theUpper); }
};

template<typename T>
class IsEqualFunction
{
public:
    Standard_Boolean operator() (const T& theKey1, const T& theKey2) const
    { return ::IsEqual (theKey1, theKey2); }
};



template <class TheKeyType, class TheItemType, class TheHasher=Hasher<TheKeyType>, class TheEqualFunction=IsEqualFunction<TheKeyType> >
class NCollection_DataMap
....

  //extra constructor for even further flexibility
  NCollection_DataMap (const TheHasher& theHasher, const theEqualFunction& theEqualFunction,
                     const Standard_Integer NbBuckets=1,
                     const Handle(NCollection_BaseAllocator)& theAllocator = 0L) : myHasher (theHasher), myEqualFunction (theEqualFunction),...
   
};

Roman
============
TagsNo tags attached.
Test case number

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2011-09-02 11:46 szy New Issue
2011-09-02 11:46 szy Assigned To => agv
2011-09-21 11:11 bugmaster Target Version 6.5.2 => 6.5.3
2011-09-22 16:49 szy Status new => assigned
2011-12-01 11:29 szy Additional Information Updated
2011-12-07 07:14 abv Target Version 6.5.3 => 6.5.4
2012-09-13 13:36 abv Status assigned => closed
2012-09-13 13:37 abv Resolution open => duplicate
2012-09-13 13:37 abv Fixed in Version => 6.5.3
2012-09-18 19:12 abv Target Version 6.5.4 => 6.5.3