(file) Return to HashTable.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/HashTable.h between version 1.3 and 1.27

version 1.3, 2001/04/27 18:46:20 version 1.27, 2008/05/02 19:02:56
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   // 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  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // copy of this software and associated documentation files (the "Software"),  // of this software and associated documentation files (the "Software"), to
 // to deal in the Software without restriction, including without limitation  // deal in the Software without restriction, including without limitation the
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // and/or sell copies of the Software, and to permit persons to whom the  // sell copies of the Software, and to permit persons to whom the Software is
 // Software is furnished to do so, subject to the following conditions:  // furnished to do so, subject to the following conditions:
 // //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 // DEALINGS IN THE SOFTWARE.  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By:  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifndef Pegasus_HashTable_h #ifndef Pegasus_HashTable_h
Line 30 
Line 36 
  
 #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
  
Line 41 
Line 49 
 { {
 }; };
  
 template<> struct PEGASUS_COMMON_LINKAGE HashFunc<String>  PEGASUS_TEMPLATE_SPECIALIZATION struct PEGASUS_COMMON_LINKAGE HashFunc<String>
 { {
     static Uint32 hash(const String& str);     static Uint32 hash(const String& str);
 }; };
  
 template<> struct HashFunc<Uint32>  PEGASUS_TEMPLATE_SPECIALIZATION struct HashFunc<Uint32>
 { {
     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.
Line 64 
Line 89 
     }     }
 }; };
  
   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.
Line 92 
Line 143 
     _BucketBase* next;     _BucketBase* next;
 }; };
  
 class _HashTableRep;  
   
 /* This class implements a simple hash table forward iterator. */ /* This class implements a simple hash table forward iterator. */
 class PEGASUS_COMMON_LINKAGE _HashTableIteratorBase class PEGASUS_COMMON_LINKAGE _HashTableIteratorBase
 { {
 public: public:
  
     _HashTableIteratorBase() : _first(0), _last(0), _bucket(0) { }      _HashTableIteratorBase(_BucketBase** first, _BucketBase** last);
  
     operator Boolean() const { return _bucket != 0; }      operator int() const { return _bucket != 0; }
  
     _HashTableIteratorBase operator++(int);     _HashTableIteratorBase operator++(int);
  
     _HashTableIteratorBase& operator++();     _HashTableIteratorBase& operator++();
  
     _HashTableIteratorBase(_BucketBase** first, _BucketBase** last);  
   
 protected: protected:
  
       // Note:  The default copy constructor/assignment operator is used by the
       // postfix increment operator.  The member pointers may be safely copied
       // because they refer to structures that must not change while the iterator
       // is in scope.
   
     _BucketBase** _first;     _BucketBase** _first;
     _BucketBase** _last;     _BucketBase** _last;
     _BucketBase* _bucket;     _BucketBase* _bucket;
     friend _HashTableRep;  
 }; };
  
 // ATTN: reorganization not supported yet. // ATTN: reorganization not supported yet.
Line 156 
Line 207 
     _HashTableRep& operator=(const _HashTableRep& x);     _HashTableRep& operator=(const _HashTableRep& x);
  
     /*- Returns the size of this hash table (the number of entries). */     /*- Returns the size of this hash table (the number of entries). */
     Uint32 getSize() const { return _size; }      Uint32 size() const { return _size; }
  
     /*- Clears the contents of this hash table. After this is called, the     /*- Clears the contents of this hash table. After this is called, the
         getSize() method returns zero.          size() method returns zero.
     */     */
     void clear();     void clear();
  
Line 178 
Line 229 
         @param key void pointer to key.         @param key void pointer to key.
         @return pointer to bucket with that key or zero otherwise.         @return pointer to bucket with that key or zero otherwise.
     */     */
     const _BucketBase* lookup(Uint32 hashCode, const void* key);      const _BucketBase* lookup(Uint32 hashCode, const void* key) const;
  
     /*- Removes the bucket with the given key. This method uses the     /*- Removes the bucket with the given key. This method uses the
         _BucketBase::equal() method to compare keys.         _BucketBase::equal() method to compare keys.
Line 248 
Line 299 
 { {
 public: public:
  
     _HashTableIterator()  
         : _HashTableIteratorBase() { }  
   
     _HashTableIterator(_BucketBase** first, _BucketBase** last)     _HashTableIterator(_BucketBase** first, _BucketBase** last)
         : _HashTableIteratorBase(first, last) { }         : _HashTableIteratorBase(first, last) { }
  
Line 322 
Line 370 
     (which by the way has exactly the same effect).     (which by the way has exactly the same effect).
  
         <pre>         <pre>
         typedef HashTable&lt;String, Uint32, EqualFunc&lt;String&gt;, HashFunc&lt;String&gt;&gt; HT;          typedef HashTable&lt;String, Uint32,
               EqualFunc&lt;String&gt;, HashFunc&lt;String&gt;&gt; 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:
  
Line 358 
Line 407 
         }         }
         </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
Line 407 
Line 457 
     the pathalogical case in which all entries are placed in the first     the pathalogical case in which all entries are placed in the first
     chain.     chain.
 */ */
 template<class K, class V, class E = EqualFunc<K>, class H = HashFunc<K> >  template<class K, class V, class E , class H >
 class HashTable class HashTable
 { {
 public: public:
Line 426 
Line 476 
     }     }
  
     /** Copy constructor. */     /** Copy constructor. */
     HashTable(const HashTable& x) : _rep(x._rep)      HashTable(const HashTable<K,V,E,H>& x) : _rep(x._rep)
     {     {
  
     }     }
  
     /** Assignment operator. */     /** Assignment operator. */
     HashTable& operator=(const HashTable& x)      HashTable<K,V,E,H>& operator=(const HashTable<K,V,E,H>& x)
     {     {
         if (this != &x)         if (this != &x)
             _rep = x._rep;             _rep = x._rep;
Line 440 
Line 490 
     }     }
  
     /** Returns the size of this hash table (the number of entries). */     /** Returns the size of this hash table (the number of entries). */
     Uint32 getSize() const { return _rep.getSize(); }      Uint32 size() const { return _rep.size(); }
  
     /** Clears the contents of this hash table. After this is called, the     /** Clears the contents of this hash table. After this is called, the
         getSize() method returns zero.          size() method returns zero.
     */     */
     void clear() { _rep.clear(); }     void clear() { _rep.clear(); }
  
Line 458 
Line 508 
             H::hash(key), new _Bucket<K, V, E>(key, value), &key);             H::hash(key), new _Bucket<K, V, E>(key, value), &key);
     }     }
  
       /** Checks to see if hash table contains an entry with the given key.
           @param key key to be searched for
           @return true if hash table contains an entry with the given key.
       */
       Boolean contains(const K& key) const
       {
           V value;
           return lookup(key, value);
       }
   
     /** Looks up the entry with the given key.     /** Looks up the entry with the given key.
         @param key key of entry to be located.         @param key key of entry to be located.
         @param value output value.         @param value output value.
         @return true if found; false otherwise.         @return true if found; false otherwise.
     */     */
     Boolean lookup(const K& key, V& value);      Boolean lookup(const K& key, V& value) const;
   
       /** Looks up the entry with the given key and returns a pointer to the
           value.  Note that this pointer may become invalid when the HashTable
           is updated.
           @param key key of entry to be located.
           @param value Output pointer to the value.
           @return true if found; false otherwise.
       */
       Boolean lookupReference(const K& key, V*& value);
  
     /** Removes the entry with the given key.     /** Removes the entry with the given key.
         @param key key of entry to be removed.         @param key key of entry to be removed.
Line 487 
Line 556 
 }; };
  
 template<class K, class V, class E, class H> template<class K, class V, class E, class H>
 inline Boolean HashTable<K, V, E, H>::lookup(const K& key, V& value)  inline Boolean HashTable<K, V, E, H>::lookup(const K& key, V& value) const
 { {
     _Bucket<K, V, E>* bucket     _Bucket<K, V, E>* bucket
         = (_Bucket<K, V, E>*)_rep.lookup(H::hash(key), &key);         = (_Bucket<K, V, E>*)_rep.lookup(H::hash(key), &key);
Line 501 
Line 570 
     return false;     return false;
 } }
  
   template<class K, class V, class E, class H>
   inline Boolean HashTable<K, V, E, H>::lookupReference(const K& key, V*& value)
   {
       _Bucket<K, V, E>* bucket =
           (_Bucket<K, V, E>*)_rep.lookup(H::hash(key), &key);
   
       if (bucket)
       {
           value = &bucket->getValue();
           return true;
       }
   
       return false;
   }
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  
 #endif /* Pegasus_HashTable_h */ #endif /* Pegasus_HashTable_h */


Legend:
Removed from v.1.3  
changed lines
  Added in v.1.27

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2