For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Could we have an Expalnation about HashCode() ?

Omar Msaaf's picture
Forums: 

Hello, I am trying to create my Own structure TopTools_MapOfMapOfShapes I understand that i have to create a

1) maphasher

2) StdMapNode

3) Iterator

4) Handle_StpMapNode

All this works fine. I succeeded in creating all of this, and making a library with it. What i can not understand is the function HashCode(). I created a function HashCode related to the class TopTools_MapOfShape. the body of TopTools_MapOfShape::HashCode(const Standard_Integer Upper) const is the following ::

if (this->Extent() > 1 ) {

TopTools_LIPPS_MapIteratorOfMapOfShape Me_Iterator,Other_Iterator;

Me_Iterator.Initialize( *this );

Test = Me_Iterator.Key().HashCode(Upper);

while(Me_Iterator.More())

{

Test = Test ^ ( Me_Iterator.Key().HashCode(Upper) );

Me_Iterator.Next();

}

Hash = Test; }

return Hash;

It links and everything, but i am not sure if it really works.......

Could you help me out with this point ? That would be really greatful... Omar Msaaf

Maxim ZVEREV's picture

Hello!

HashCode() method must return UNIQUE value for each instance of your class. So, as I see if you will have two different instances of MapOfShape but they will have the same content (i.e. will store the same shapes) you will have the same Hash Code for these two instances. If you need it - OK, if you not need it - try to keep in mind not only contents but also unique property of the map itself. Only one remark: at the end of your method insert the following adjacement:

Hash = Test;

return ::HashCode((Standard_Integer)Hash, Upper);

About this method you can see in Standard_Integer.hxx.

Also interesting information you can see in Standard_HashCode.cxx where you will find implementations of this function for the pointers (all CAS.CADE handles return HashCode computed by this way).

Best regards,

Maxim ZVEREV.

Omar Msaaf's picture

I really appreciate it Omar Msaaf