2005-08-11 23:42:59 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is C++ hashtable templates.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Benjamin Smedberg.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsTHashKeys_h__
|
|
|
|
#define nsTHashKeys_h__
|
|
|
|
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsISupports.h"
|
2005-11-18 17:18:49 +03:00
|
|
|
#include "nsIHashable.h"
|
2005-08-11 23:42:59 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include NEW_H
|
|
|
|
|
2005-11-02 23:38:21 +03:00
|
|
|
#include "nsStringGlue.h"
|
2006-06-15 17:48:29 +04:00
|
|
|
#include "nsCRTGlue.h"
|
2005-08-15 22:29:55 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-08-11 23:42:59 +04:00
|
|
|
/** @file nsHashKeys.h
|
2005-08-11 23:43:06 +04:00
|
|
|
* standard HashKey classes for nsBaseHashtable and relatives. Each of these
|
2005-08-11 23:42:59 +04:00
|
|
|
* classes follows the nsTHashtable::EntryType specification
|
|
|
|
*
|
2005-08-11 23:43:06 +04:00
|
|
|
* Lightweight keytypes provided here:
|
2005-08-11 23:42:59 +04:00
|
|
|
* nsStringHashKey
|
|
|
|
* nsCStringHashKey
|
|
|
|
* nsUint32HashKey
|
2010-10-21 04:24:16 +04:00
|
|
|
* nsUint64HashKey
|
2009-01-09 03:12:33 +03:00
|
|
|
* nsPtrHashkey
|
|
|
|
* nsClearingPtrHashKey
|
2007-02-09 23:44:10 +03:00
|
|
|
* nsVoidPtrHashKey
|
|
|
|
* nsClearingVoidPtrHashKey
|
2005-08-11 23:42:59 +04:00
|
|
|
* nsISupportsHashKey
|
|
|
|
* nsIDHashKey
|
2005-08-11 23:43:11 +04:00
|
|
|
* nsDepCharHashKey
|
2007-02-09 23:44:10 +03:00
|
|
|
* nsCharPtrHashKey
|
|
|
|
* nsUnicharPtrHashKey
|
|
|
|
* nsHashableHashKey
|
2005-08-11 23:42:59 +04:00
|
|
|
*/
|
|
|
|
|
2005-08-15 22:29:55 +04:00
|
|
|
NS_COM_GLUE PRUint32 HashString(const nsAString& aStr);
|
|
|
|
NS_COM_GLUE PRUint32 HashString(const nsACString& aStr);
|
2006-06-15 17:48:29 +04:00
|
|
|
NS_COM_GLUE PRUint32 HashString(const char* aKey);
|
|
|
|
NS_COM_GLUE PRUint32 HashString(const PRUnichar* aKey);
|
2005-08-15 22:29:55 +04:00
|
|
|
|
2005-08-11 23:42:59 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper using nsAString KeyType
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsStringHashKey : public PLDHashEntryHdr
|
2005-08-11 23:42:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const nsAString& KeyType;
|
|
|
|
typedef const nsAString* KeyTypePointer;
|
|
|
|
|
|
|
|
nsStringHashKey(KeyTypePointer aStr) : mStr(*aStr) { }
|
|
|
|
nsStringHashKey(const nsStringHashKey& toCopy) : mStr(toCopy.mStr) { }
|
|
|
|
~nsStringHashKey() { }
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mStr; }
|
|
|
|
PRBool KeyEquals(const KeyTypePointer aKey) const
|
|
|
|
{
|
|
|
|
return mStr.Equals(*aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey)
|
|
|
|
{
|
|
|
|
return HashString(*aKey);
|
|
|
|
}
|
2005-08-11 23:43:06 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2005-08-11 23:42:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const nsString mStr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hashkey wrapper using nsACString KeyType
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsCStringHashKey : public PLDHashEntryHdr
|
2005-08-11 23:42:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const nsACString& KeyType;
|
|
|
|
typedef const nsACString* KeyTypePointer;
|
|
|
|
|
|
|
|
nsCStringHashKey(const nsACString* aStr) : mStr(*aStr) { }
|
|
|
|
nsCStringHashKey(const nsCStringHashKey& toCopy) : mStr(toCopy.mStr) { }
|
|
|
|
~nsCStringHashKey() { }
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mStr; }
|
|
|
|
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const { return mStr.Equals(*aKey); }
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
|
|
{
|
|
|
|
return HashString(*aKey);
|
|
|
|
}
|
2005-08-11 23:43:06 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2005-08-11 23:42:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const nsCString mStr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hashkey wrapper using PRUint32 KeyType
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsUint32HashKey : public PLDHashEntryHdr
|
2005-08-11 23:42:59 +04:00
|
|
|
{
|
|
|
|
public:
|
2005-08-11 23:43:00 +04:00
|
|
|
typedef const PRUint32& KeyType;
|
2005-08-11 23:42:59 +04:00
|
|
|
typedef const PRUint32* KeyTypePointer;
|
|
|
|
|
|
|
|
nsUint32HashKey(KeyTypePointer aKey) : mValue(*aKey) { }
|
|
|
|
nsUint32HashKey(const nsUint32HashKey& toCopy) : mValue(toCopy.mValue) { }
|
|
|
|
~nsUint32HashKey() { }
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mValue; }
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const { return *aKey == mValue; }
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey) { return *aKey; }
|
2005-08-11 23:43:06 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2005-08-11 23:42:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const PRUint32 mValue;
|
|
|
|
};
|
|
|
|
|
2010-10-21 04:24:16 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper using PRUint64 KeyType
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
|
|
|
class nsUint64HashKey : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const PRUint64& KeyType;
|
|
|
|
typedef const PRUint64* KeyTypePointer;
|
|
|
|
|
|
|
|
nsUint64HashKey(KeyTypePointer aKey) : mValue(*aKey) { }
|
|
|
|
nsUint64HashKey(const nsUint64HashKey& toCopy) : mValue(toCopy.mValue) { }
|
|
|
|
~nsUint64HashKey() { }
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mValue; }
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const { return *aKey == mValue; }
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
2010-11-06 17:53:37 +03:00
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey) { return PLDHashNumber(*aKey); }
|
2010-10-21 04:24:16 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PRUint64 mValue;
|
|
|
|
};
|
|
|
|
|
2005-08-11 23:42:59 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper using nsISupports* KeyType
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsISupportsHashKey : public PLDHashEntryHdr
|
2005-08-11 23:42:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef nsISupports* KeyType;
|
|
|
|
typedef const nsISupports* KeyTypePointer;
|
|
|
|
|
2005-08-11 23:43:06 +04:00
|
|
|
nsISupportsHashKey(const nsISupports* key) :
|
2007-07-08 11:08:04 +04:00
|
|
|
mSupports(const_cast<nsISupports*>(key)) { }
|
2005-08-11 23:42:59 +04:00
|
|
|
nsISupportsHashKey(const nsISupportsHashKey& toCopy) :
|
|
|
|
mSupports(toCopy.mSupports) { }
|
|
|
|
~nsISupportsHashKey() { }
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mSupports; }
|
|
|
|
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const { return aKey == mSupports; }
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
|
|
{
|
|
|
|
return NS_PTR_TO_INT32(aKey) >>2;
|
|
|
|
}
|
2005-08-11 23:43:06 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2005-08-11 23:42:59 +04:00
|
|
|
|
|
|
|
private:
|
2005-08-11 23:43:06 +04:00
|
|
|
nsCOMPtr<nsISupports> mSupports;
|
2005-08-11 23:42:59 +04:00
|
|
|
};
|
|
|
|
|
2005-08-11 23:43:14 +04:00
|
|
|
/**
|
2009-01-09 03:12:33 +03:00
|
|
|
* hashkey wrapper using T* KeyType
|
2005-08-11 23:43:14 +04:00
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2009-01-09 03:12:33 +03:00
|
|
|
template<class T>
|
|
|
|
class nsPtrHashKey : public PLDHashEntryHdr
|
2005-08-11 23:43:14 +04:00
|
|
|
{
|
2009-01-09 03:12:33 +03:00
|
|
|
public:
|
|
|
|
typedef T *KeyType;
|
|
|
|
typedef const T *KeyTypePointer;
|
2005-08-11 23:43:14 +04:00
|
|
|
|
2009-01-09 03:12:33 +03:00
|
|
|
nsPtrHashKey(const T *key) : mKey(const_cast<T*>(key)) {}
|
|
|
|
nsPtrHashKey(const nsPtrHashKey<T> &toCopy) : mKey(toCopy.mKey) {}
|
|
|
|
~nsPtrHashKey() {}
|
2005-08-11 23:43:14 +04:00
|
|
|
|
|
|
|
KeyType GetKey() const { return mKey; }
|
|
|
|
|
2009-01-09 03:12:33 +03:00
|
|
|
PRBool KeyEquals(KeyTypePointer key) const { return key == mKey; }
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType key) { return key; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer key)
|
2005-08-11 23:43:14 +04:00
|
|
|
{
|
2009-01-09 03:12:33 +03:00
|
|
|
return NS_PTR_TO_INT32(key) >> 2;
|
2005-08-11 23:43:14 +04:00
|
|
|
}
|
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2007-01-05 01:31:26 +03:00
|
|
|
|
2009-01-09 03:12:33 +03:00
|
|
|
protected:
|
|
|
|
T *mKey;
|
2007-01-05 01:31:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2009-01-09 03:12:33 +03:00
|
|
|
* hashkey wrapper using T* KeyType that sets key to NULL upon
|
2007-01-05 01:31:26 +03:00
|
|
|
* destruction. Relevant only in cases where a memory pointer-scanner
|
|
|
|
* like valgrind might get confused about stale references.
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
|
|
|
|
2009-01-09 03:12:33 +03:00
|
|
|
template<class T>
|
|
|
|
class nsClearingPtrHashKey : public nsPtrHashKey<T>
|
2007-01-05 01:31:26 +03:00
|
|
|
{
|
2009-01-09 03:12:33 +03:00
|
|
|
public:
|
|
|
|
nsClearingPtrHashKey(const T *key) : nsPtrHashKey<T>(key) {}
|
|
|
|
nsClearingPtrHashKey(const nsClearingPtrHashKey<T> &toCopy) :
|
|
|
|
nsPtrHashKey<T>(toCopy) {}
|
|
|
|
~nsClearingPtrHashKey() { nsPtrHashKey<T>::mKey = nsnull; }
|
2005-08-11 23:43:14 +04:00
|
|
|
};
|
|
|
|
|
2009-01-09 03:12:33 +03:00
|
|
|
typedef nsPtrHashKey<const void> nsVoidPtrHashKey;
|
|
|
|
typedef nsClearingPtrHashKey<const void> nsClearingVoidPtrHashKey;
|
|
|
|
|
2005-08-11 23:42:59 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper using nsID KeyType
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsIDHashKey : public PLDHashEntryHdr
|
2005-08-11 23:42:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const nsID& KeyType;
|
|
|
|
typedef const nsID* KeyTypePointer;
|
|
|
|
|
2005-08-16 04:37:15 +04:00
|
|
|
nsIDHashKey(const nsID* inID) : mID(*inID) { }
|
2005-08-11 23:42:59 +04:00
|
|
|
nsIDHashKey(const nsIDHashKey& toCopy) : mID(toCopy.mID) { }
|
|
|
|
~nsIDHashKey() { }
|
|
|
|
|
|
|
|
KeyType GetKey() const { return mID; }
|
2005-08-11 23:43:15 +04:00
|
|
|
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const { return aKey->Equals(mID); }
|
2005-08-11 23:42:59 +04:00
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey);
|
2005-08-11 23:43:06 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2005-08-11 23:42:59 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const nsID mID;
|
|
|
|
};
|
|
|
|
|
2005-08-11 23:43:11 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper for "dependent" const char*; this class does not "own"
|
|
|
|
* its string pointer.
|
|
|
|
*
|
|
|
|
* This class must only be used if the strings have a lifetime longer than
|
|
|
|
* the hashtable they occupy. This normally occurs only for static
|
|
|
|
* strings or strings that have been arena-allocated.
|
|
|
|
*
|
|
|
|
* @see nsTHashtable::EntryType for specification
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsDepCharHashKey : public PLDHashEntryHdr
|
2005-08-11 23:43:11 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const char* KeyType;
|
|
|
|
typedef const char* KeyTypePointer;
|
|
|
|
|
|
|
|
nsDepCharHashKey(const char* aKey) { mKey = aKey; }
|
|
|
|
nsDepCharHashKey(const nsDepCharHashKey& toCopy) { mKey = toCopy.mKey; }
|
|
|
|
~nsDepCharHashKey() { }
|
|
|
|
|
|
|
|
const char* GetKey() const { return mKey; }
|
|
|
|
PRBool KeyEquals(const char* aKey) const
|
|
|
|
{
|
|
|
|
return !strcmp(mKey, aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* KeyToPointer(const char* aKey) { return aKey; }
|
2006-06-15 17:48:29 +04:00
|
|
|
static PLDHashNumber HashKey(const char* aKey) { return HashString(aKey); }
|
2005-08-11 23:43:11 +04:00
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* mKey;
|
|
|
|
};
|
|
|
|
|
2005-08-11 23:43:13 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper for const char*; at construction, this class duplicates
|
|
|
|
* a string pointed to by the pointer so that it doesn't matter whether or not
|
|
|
|
* the string lives longer than the hash table.
|
|
|
|
*/
|
2005-09-22 17:22:52 +04:00
|
|
|
class nsCharPtrHashKey : public PLDHashEntryHdr
|
2005-08-11 23:43:13 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const char* KeyType;
|
|
|
|
typedef const char* KeyTypePointer;
|
|
|
|
|
|
|
|
nsCharPtrHashKey(const char* aKey) : mKey(strdup(aKey)) { }
|
|
|
|
nsCharPtrHashKey(const nsCharPtrHashKey& toCopy) : mKey(strdup(toCopy.mKey)) { }
|
2007-07-08 11:08:04 +04:00
|
|
|
~nsCharPtrHashKey() { if (mKey) free(const_cast<char *>(mKey)); }
|
2005-08-11 23:43:13 +04:00
|
|
|
|
|
|
|
const char* GetKey() const { return mKey; }
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const
|
|
|
|
{
|
|
|
|
return !strcmp(mKey, aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
2006-06-15 17:48:29 +04:00
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey) { return HashString(aKey); }
|
2005-08-11 23:43:13 +04:00
|
|
|
|
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* mKey;
|
|
|
|
};
|
|
|
|
|
2006-06-15 17:48:29 +04:00
|
|
|
/**
|
|
|
|
* hashkey wrapper for const PRUnichar*; at construction, this class duplicates
|
|
|
|
* a string pointed to by the pointer so that it doesn't matter whether or not
|
|
|
|
* the string lives longer than the hash table.
|
|
|
|
*/
|
|
|
|
class nsUnicharPtrHashKey : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef const PRUnichar* KeyType;
|
|
|
|
typedef const PRUnichar* KeyTypePointer;
|
|
|
|
|
|
|
|
nsUnicharPtrHashKey(const PRUnichar* aKey) : mKey(NS_strdup(aKey)) { }
|
|
|
|
nsUnicharPtrHashKey(const nsUnicharPtrHashKey& toCopy) : mKey(NS_strdup(toCopy.mKey)) { }
|
2007-07-08 11:08:04 +04:00
|
|
|
~nsUnicharPtrHashKey() { if (mKey) NS_Free(const_cast<PRUnichar *>(mKey)); }
|
2006-06-15 17:48:29 +04:00
|
|
|
|
|
|
|
const PRUnichar* GetKey() const { return mKey; }
|
|
|
|
PRBool KeyEquals(KeyTypePointer aKey) const
|
|
|
|
{
|
|
|
|
return !NS_strcmp(mKey, aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey) { return HashString(aKey); }
|
|
|
|
|
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PRUnichar* mKey;
|
|
|
|
};
|
|
|
|
|
2005-11-18 17:18:49 +03:00
|
|
|
/**
|
|
|
|
* Hashtable key class to use with objects that support nsIHashable
|
|
|
|
*/
|
|
|
|
class nsHashableHashKey : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef nsIHashable* KeyType;
|
|
|
|
typedef const nsIHashable* KeyTypePointer;
|
|
|
|
|
|
|
|
nsHashableHashKey(const nsIHashable* aKey) :
|
2007-07-08 11:08:04 +04:00
|
|
|
mKey(const_cast<nsIHashable*>(aKey)) { }
|
2005-11-18 17:18:49 +03:00
|
|
|
nsHashableHashKey(const nsHashableHashKey& toCopy) :
|
|
|
|
mKey(toCopy.mKey) { }
|
|
|
|
~nsHashableHashKey() { }
|
|
|
|
|
|
|
|
nsIHashable* GetKey() const { return mKey; }
|
|
|
|
|
|
|
|
PRBool KeyEquals(const nsIHashable* aKey) const {
|
|
|
|
PRBool eq;
|
2007-07-08 11:08:04 +04:00
|
|
|
if (NS_SUCCEEDED(mKey->Equals(const_cast<nsIHashable*>(aKey), &eq))) {
|
2005-11-18 17:18:49 +03:00
|
|
|
return eq;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const nsIHashable* KeyToPointer(nsIHashable* aKey) { return aKey; }
|
|
|
|
static PLDHashNumber HashKey(const nsIHashable* aKey) {
|
|
|
|
PRUint32 code = 8888; // magic number if GetHashCode fails :-(
|
2005-12-01 22:35:27 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
2007-07-08 11:08:04 +04:00
|
|
|
const_cast<nsIHashable*>(aKey)->GetHashCode(&code);
|
2005-11-18 17:18:49 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetHashCode should not throw!");
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIHashable> mKey;
|
|
|
|
};
|
|
|
|
|
2005-08-11 23:42:59 +04:00
|
|
|
#endif // nsTHashKeys_h__
|