summaryrefslogtreecommitdiff
path: root/src/Standard/Standard_HashCode.cxx
blob: d67789b2c6ee65d6140518c8140df93b1f774ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Standard_Transient.hxx>
#include <Standard_Persistent.hxx>
#include <Standard_Type.hxx>
#include <Standard_RangeError.hxx>

//============================================================================
Standard_EXPORT Standard_Integer HashCode(const Standard_Address me,const Standard_Integer Upper,const Handle(Standard_Type)& aType)
{
  char             *mecharPtr;
  Standard_Integer *meintPtr = (Standard_Integer *) me;
  Standard_Integer aHashCode, aRest, i, aSize = aType->Size();
  
  Standard_RangeError_Raise_if (Upper < 1,
      "Try to apply HashCode method with negative or null argument.");

  aRest = aSize % sizeof(Standard_Integer);

  aHashCode = 0;

  if (aSize == 0) 
    aHashCode = (Standard_Integer) ptrdiff_t(me);


  for (i = 0;  (unsigned int ) i < aSize / sizeof(Standard_Integer); i++)
  {
    aHashCode = aHashCode ^ *meintPtr;
    meintPtr++;
  }
  
  mecharPtr = (char *) meintPtr;

  for (i = 0; i < aRest; i++) 
  {
    aHashCode = aHashCode ^ *mecharPtr;
    mecharPtr++;
  }


  return HashCode( aHashCode , Upper) ;
}

//============================================================================
Standard_EXPORT Standard_Integer HashCode (const Handle(Standard_Transient)& me,
                                           const Standard_Integer Upper )
{
  Standard_RangeError_Raise_if (Upper < 1,
                                "Try to apply HashCode method "
                                "with negative or null argument.");

  const Standard_Integer I = (Standard_Integer) ptrdiff_t(me.operator->());
  return HashCode( I , Upper ) ;
}

//============================================================================
Standard_EXPORT Standard_Integer HashCode(const Handle(Standard_Persistent)& me,
                                          const Standard_Integer Upper )
{
  Standard_RangeError_Raise_if (Upper < 1,
                                "Try to apply HashCode method "
                                "with negative or null argument.");

  const Standard_Integer I = (Standard_Integer) ptrdiff_t(me.operator->());
  return HashCode( I , Upper) ;
}