version 1.13, 2002/06/01 00:56:33
|
version 1.25, 2008/01/15 23:19:30
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// The Open Group, Tivoli Systems |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
|
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
|
// |
|
// Modified By: |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#ifndef Pegasus_HashTable_h | #ifndef Pegasus_HashTable_h |
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/String.h> | #include <Pegasus/Common/String.h> |
|
#include <Pegasus/Common/CIMObjectPath.h> |
|
#include <Pegasus/Common/Linkage.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
static Uint32 hash(Uint32 x) { return x + 13; } | static Uint32 hash(Uint32 x) { return x + 13; } |
}; | }; |
| |
|
PEGASUS_TEMPLATE_SPECIALIZATION struct HashFunc <CIMObjectPath> |
|
{ |
|
static Uint32 hash (const CIMObjectPath & path) |
|
{ |
|
return path.makeHashCode (); |
|
} |
|
}; |
|
|
|
// |
|
// Computes a hash code for a string without regard to case. For example, it |
|
// yields the same hash code for "AB", "ab", "Ab", and "aB". |
|
// |
|
struct PEGASUS_COMMON_LINKAGE HashLowerCaseFunc |
|
{ |
|
static Uint32 hash(const String& str); |
|
}; |
|
|
/* This is a function object used by the HashTable to compare keys. This is | /* This is a function object used by the HashTable to compare keys. This is |
the default implementation. Others may be defined and passed in the | the default implementation. Others may be defined and passed in the |
template argument list to perform other kinds of comparisons. | template argument list to perform other kinds of comparisons. |
|
|
} | } |
}; | }; |
| |
|
PEGASUS_TEMPLATE_SPECIALIZATION struct EqualFunc <CIMObjectPath> |
|
{ |
|
static Boolean equal (const CIMObjectPath & x, const CIMObjectPath & y) |
|
{ |
|
return x.identical (y); |
|
} |
|
}; |
|
|
|
/* |
|
Equal function object that can be used by HashTable to compare keys that |
|
should be treated as case insensitive. |
|
|
|
This function can be used for hash table keys constructed from strings that |
|
should be treated as case insensitive (e.g. class names, namespace names, |
|
system names). |
|
|
|
Note: this function compares Strings based on the process locale. |
|
*/ |
|
struct EqualNoCaseFunc |
|
{ |
|
static Boolean equal (const String & x, const String & y) |
|
{ |
|
return (0 == String::compareNoCase (x, y)); |
|
} |
|
}; |
|
|
/* Representation for a bucket. The HashTable class derives from this | /* Representation for a bucket. The HashTable class derives from this |
bucket to append a key and value. This base class just defines | bucket to append a key and value. This base class just defines |
the pointer to the next bucket in the chain. | the pointer to the next bucket in the chain. |
|
|
(which by the way has exactly the same effect). | (which by the way has exactly the same effect). |
| |
<pre> | <pre> |
typedef HashTable<String, Uint32, EqualFunc<String>, HashFunc<String>> HT; |
typedef HashTable<String, Uint32, |
|
EqualFunc<String>, HashFunc<String>> HT; |
</pre> | </pre> |
| |
The third and forth arguments are described more in detail later. |
The third and fourth arguments are described more in detail later. |
| |
Then, entries may be inserted like this: | Then, entries may be inserted like this: |
| |
|
|
} | } |
</pre> | </pre> |
| |
Note that only forward iteration is supported (no backwards iteration). |
Note that only forward iteration is supported (no backwards iteration), |
|
AND that the hashtable MUST NOT be modified during the iteration!!! |
| |
Equality of keys is determined using the EqualFunc class which is | Equality of keys is determined using the EqualFunc class which is |
the default third argument of the template argument list. A new function | the default third argument of the template argument list. A new function |