1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Definitions for nsPtrHashKey<T> and nsVoidPtrHashKey. */
9 #ifndef nsPointerHashKeys_h
10 #define nsPointerHashKeys_h
14 #include "mozilla/Attributes.h"
15 #include "mozilla/HashFunctions.h"
17 #include "PLDHashTable.h"
20 * hashkey wrapper using T* KeyType
22 * @see nsTHashtable::EntryType for specification
25 class nsPtrHashKey
: public PLDHashEntryHdr
{
28 using KeyTypePointer
= const T
*;
30 explicit nsPtrHashKey(const T
* aKey
) : mKey(const_cast<T
*>(aKey
)) {}
31 nsPtrHashKey(nsPtrHashKey
&& aToMove
) = default;
32 ~nsPtrHashKey() = default;
34 KeyType
GetKey() const { return mKey
; }
35 bool KeyEquals(KeyTypePointer aKey
) const { return aKey
== mKey
; }
37 static KeyTypePointer
KeyToPointer(KeyType aKey
) { return aKey
; }
38 static PLDHashNumber
HashKey(KeyTypePointer aKey
) {
39 return mozilla::HashGeneric(aKey
);
41 enum { ALLOW_MEMMOVE
= true };
44 T
* MOZ_NON_OWNING_REF mKey
;
47 using nsVoidPtrHashKey
= nsPtrHashKey
<const void>;
49 #endif // nsPointerHashKeys_h