deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* ***** BEGIN LICENSE BLOCK *****
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Version: MPL 1.1/GPL 2.0/LGPL 2.1
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * The contents of this file are subject to the Mozilla Public License Version
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * 1.1 (the "License"); you may not use this file except in compliance with
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * the License. You may obtain a copy of the License at
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * http://www.mozilla.org/MPL/
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Software distributed under the License is distributed on an "AS IS" basis,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * for the specific language governing rights and limitations under the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * License.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * The Original Code is Mozilla Communicator client code.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * The Initial Developer of the Original Code is
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Netscape Communications Corporation.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Portions created by the Initial Developer are Copyright (C) 1998
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * the Initial Developer. All Rights Reserved.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Contributor(s):
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Alternatively, the contents of this file may be used under the terms of
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * either of the GNU General Public License Version 2 or later (the "GPL"),
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * in which case the provisions of the GPL or the LGPL are applicable instead
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * of those above. If you wish to allow use of your version of this file only
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * under the terms of either the GPL or the LGPL, and not to allow others to
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * use your version of this file under the terms of the MPL, indicate your
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * decision by deleting the provisions above and replace them with the notice
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * and other provisions required by the GPL or the LGPL. If you do not delete
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * the provisions above, a recipient may use your version of this file under
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * the terms of any one of the MPL, the GPL or the LGPL.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * ***** END LICENSE BLOCK ***** */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#ifndef __nsHashSets_h__
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define __nsHashSets_h__
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#include "nsDoubleHashtable.h"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * HASH SETS
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * These hash classes describe hashtables that contain keys without values.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * This is useful when you want to store things and then just test for their
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * existence later. We have defined standard ones for string, int and void.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * nsStringHashSet: nsAString&
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * nsCStringHashSet: nsACString&
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * nsInt32HashSet: PRInt32
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * nsVoidHashSet: void*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * USAGE:
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Put(): put a thing of the given type into the set
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Contains(): whether it contains a thing of the given type
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * To use, you just do: (for example)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * #include "nsDoubleHashtable.h"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * nsInt32HashSet mySet;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * mySet.Init(1);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * mySet.Put(5);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * if (mySet.Contains(5)) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * printf("yay\n");
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * There is a nice convenient macro for declaring empty map classes:
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * DECL_DHASH_SET(CLASSNAME, ENTRY_CLASS, KEY_TYPE)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - CLASSNAME: the name of the class
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - ENTRY_CLASS: the name of the entry class with the key in it
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * - KEY_TYPE: the type of key for Put() and Contains()
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * DHASH_SET(CLASSNAME, ENTRY_CLASS, KEY_TYPE) is the companion macro
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * you must put in the .cpp (implementation) code.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define DECL_DHASH_SET(CLASSNAME,ENTRY_CLASS,KEY_TYPE) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncDECL_DHASH_WRAPPER(CLASSNAME##Super,ENTRY_CLASS,KEY_TYPE) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncclass DHASH_EXPORT CLASSNAME : public CLASSNAME##Super { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncpublic: \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync CLASSNAME() : CLASSNAME##Super() { } \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync ~CLASSNAME() { } \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync nsresult Put(const KEY_TYPE aKey) { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync return AddEntry(aKey) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync } \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync PRBool Contains(const KEY_TYPE aKey) { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync return GetEntry(aKey) ? PR_TRUE : PR_FALSE; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync } \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync};
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define DHASH_SET(CLASSNAME,ENTRY_CLASS,KEY_TYPE) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncDHASH_WRAPPER(CLASSNAME##Super,ENTRY_CLASS,KEY_TYPE)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#undef DHASH_EXPORT
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define DHASH_EXPORT NS_COM
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncDECL_DHASH_SET(nsStringHashSet, PLDHashStringEntry, nsAString&)
DECL_DHASH_SET(nsCStringHashSet,PLDHashCStringEntry,nsACString&)
DECL_DHASH_SET(nsInt32HashSet, PLDHashInt32Entry, PRInt32)
DECL_DHASH_SET(nsVoidHashSet, PLDHashVoidEntry, void*)
#undef DHASH_EXPORT
#define DHASH_EXPORT
#endif