Home | History | Annotate | Download | only in graphics
      1 /*
      2  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
      3 
      4  This library is free software; you can redistribute it and/or
      5  modify it under the terms of the GNU Library General Public
      6  License as published by the Free Software Foundation; either
      7  version 2 of the License, or (at your option) any later version.
      8 
      9  This library is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  Library General Public License for more details.
     13 
     14  You should have received a copy of the GNU Library General Public License
     15  along with this library; see the file COPYING.LIB.  If not, write to
     16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef IntPointHash_h
     21 #define IntPointHash_h
     22 
     23 #include "IntPoint.h"
     24 #include <wtf/HashFunctions.h>
     25 #include <wtf/HashTraits.h>
     26 
     27 namespace WTF {
     28 
     29 // The empty value is (0, INT_MIN), the deleted value is (INT_MIN, 0)
     30 struct IntPointHash {
     31     static unsigned hash(const WebCore::IntPoint& p) { return WTF::intHash(static_cast<uint64_t>(p.x()) << 32 | p.y()); }
     32     static bool equal(const WebCore::IntPoint& a, const WebCore::IntPoint& b) { return a == b; }
     33     static const bool safeToCompareToEmptyOrDeleted = true;
     34 };
     35 template<> struct HashTraits<WebCore::IntPoint> : GenericHashTraits<WebCore::IntPoint> {
     36     static const bool needsDestruction = false;
     37     static WebCore::IntPoint emptyValue() { return WebCore::IntPoint(0, std::numeric_limits<int>::min()); }
     38 
     39     static void constructDeletedValue(WebCore::IntPoint& slot) { slot = WebCore::IntPoint(std::numeric_limits<int>::min(), 0); }
     40     static bool isDeletedValue(const WebCore::IntPoint& slot) { return slot == WebCore::IntPoint(std::numeric_limits<int>::min(), 0); }
     41 };
     42 template<> struct DefaultHash<WebCore::IntPoint> {
     43     typedef IntPointHash Hash;
     44 };
     45 
     46 }
     47 
     48 #endif
     49