1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef __nsHashSets_h__
39 #define __nsHashSets_h__
41 #include "nsDoubleHashtable.h"
46 * These hash classes describe hashtables that contain keys without values.
47 * This is useful when you want to store things and then just test for their
48 * existence later. We have defined standard ones for string, int and void.
50 * nsStringHashSet: nsAString&
51 * nsCStringHashSet: nsACString&
52 * nsInt32HashSet: PRInt32
53 * nsVoidHashSet: void*
56 * Put(): put a thing of the given type into the set
57 * Contains(): whether it contains a thing of the given type
58 * To use, you just do: (for example)
60 * #include "nsDoubleHashtable.h"
61 * nsInt32HashSet mySet;
64 * if (mySet.Contains(5)) {
68 * There is a nice convenient macro for declaring empty map classes:
69 * DECL_DHASH_SET(CLASSNAME, ENTRY_CLASS, KEY_TYPE)
70 * - CLASSNAME: the name of the class
71 * - ENTRY_CLASS: the name of the entry class with the key in it
72 * - KEY_TYPE: the type of key for Put() and Contains()
74 * DHASH_SET(CLASSNAME, ENTRY_CLASS, KEY_TYPE) is the companion macro
75 * you must put in the .cpp (implementation) code.
78 #define DECL_DHASH_SET(CLASSNAME,ENTRY_CLASS,KEY_TYPE) \
79 DECL_DHASH_WRAPPER(CLASSNAME##Super,ENTRY_CLASS,KEY_TYPE) \
80 class DHASH_EXPORT CLASSNAME : public CLASSNAME##Super { \
82 CLASSNAME() : CLASSNAME##Super() { } \
84 nsresult Put(const KEY_TYPE aKey) { \
85 return AddEntry(aKey) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; \
87 PRBool Contains(const KEY_TYPE aKey) { \
88 return GetEntry(aKey) ? PR_TRUE : PR_FALSE; \
92 #define DHASH_SET(CLASSNAME,ENTRY_CLASS,KEY_TYPE) \
93 DHASH_WRAPPER(CLASSNAME##Super,ENTRY_CLASS,KEY_TYPE)
96 #define DHASH_EXPORT NS_COM
98 DECL_DHASH_SET(nsStringHashSet
, PLDHashStringEntry
, nsAString
&)
99 DECL_DHASH_SET(nsCStringHashSet
,PLDHashCStringEntry
,nsACString
&)
100 DECL_DHASH_SET(nsInt32HashSet
, PLDHashInt32Entry
, PRInt32
)
101 DECL_DHASH_SET(nsVoidHashSet
, PLDHashVoidEntry
, void*)