1 // Created on: 2016-12-13
2 // Copyright (c) 2016 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Quantity_ColorHasher_HeaderFile
16 #define _Quantity_ColorHasher_HeaderFile
18 #include <Quantity_Color.hxx>
20 //! Hasher of Quantity_Color.
21 struct Quantity_ColorHasher
23 //! Returns hash code for the given color.
24 static Standard_Integer HashCode (const Quantity_Color& theColor,
25 const Standard_Integer theUpper)
27 Standard_Integer aRed = Standard_Integer (255 * theColor.Red());
28 Standard_Integer aGreen = Standard_Integer (255 * theColor.Green());
29 Standard_Integer aBlue = Standard_Integer (255 * theColor.Blue());
31 Standard_Integer aHash = 0;
32 updateHash (aHash, aRed);
33 updateHash (aHash, aGreen);
34 updateHash (aHash, aBlue);
35 aHash += (aHash << 3);
36 aHash ^= (aHash >> 11);
37 aHash += (aHash << 15);
38 return ((aHash & 0x7fff) % theUpper) + 1;
41 //! Returns true if two colors are equal.
42 static Standard_Boolean IsEqual (const Quantity_Color& theColor1,
43 const Quantity_Color& theColor2)
45 return theColor1 == theColor2;
49 static void updateHash (Standard_Integer& theHash,
50 const Standard_Integer theValue)
53 theHash += (theHash << 10);
54 theHash ^= (theHash >> 6);