TAPs 0.7.7.3
TAPsHashTableBySTLVector.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsHashTableBySTLVector.hpp
00003 
00004 Class TAPsHashTableBySTLVector is a hash table created from STL vector class.
00005 All values, assume numbers, in bucket will be sorted.
00006 
00007 SUKITTI PUNAK   (04/08/2005)
00008 UPDATE          (04/15/2005)
00009 ******************************************************************************/
00010 #ifndef TAPs_HASH_TABLE_BY_STL_VECTOR_HPP
00011 #define TAPs_HASH_TABLE_BY_STL_VECTOR_HPP
00012 
00013 #include "../Core/TAPsStdLib.hpp"
00014 #include <vector>
00015 
00016 BEGIN_NAMESPACE_TAPs__DS
00017 //=============================================================================
00018 template <typename T>
00019 class HashTableBySTLVector {
00020 //=============================================================================
00021 // DATA MEMBERS
00022 //=============================================================================
00023 private:
00024     int m_iNoOfBuckets;             // number of buckets
00025     std::vector<T> *m_pvBucketNo;   // bucket number
00026 //=============================================================================
00027 // MEMBER FUNCTIONS
00028 //=============================================================================
00029 public:
00030     //-------------------------------------------------------------------------
00031     // Output Operator <<
00032     friend std::ostream & operator<< ( std::ostream &output, 
00033                                        HashTableBySTLVector<T> const &o )
00034     {
00035         output  << "HashTableBySTLVector<" << typeid(T).name() << "> has "
00036                 << o.m_iNoOfBuckets << " bucket(s):\n";
00037         //------------------------------------------------------------
00038         // Output all bucket
00039         for ( int i = 0; i < o.m_iNoOfBuckets; ++i ) {
00040             output << "Bucket# " << i << ":";
00041             for ( int j = 0; j < static_cast<int>( o.m_pvBucketNo[i].size() ); ++j ) {
00042                 output << " " << o.m_pvBucketNo[i][j];
00043             }
00044             output << "\n";
00045         }
00046         return output;
00047     }
00048     //-------------------------------------------------------------------------
00049     // Constructor(s) and Destructor
00050     HashTableBySTLVector ( int numberOfBuckets );
00051     ~HashTableBySTLVector ();
00052     //-------------------------------------------------------------------------
00053     // Get/Set Fns
00054     inline int GetNoOfBuckets () const { return m_iNoOfBuckets; }
00055     inline std::vector<T> const & GetBucketNo ( int i ) const
00056     { return m_pvBucketNo[i]; }
00057     //-------------------------------------------------------------------------
00058     // Operation(s) Unsorted Elements
00059     //-------------------------------------------------------------------------
00060     // Insert in into bucket#
00061     // All values, assume numbers, in bucket will not be sorted.
00062     // Return the inserted index
00063     int Insert ( T in,  int bucketNo );
00064     // Search key in bucket# with unsorted values
00065     // Return the first index that contains the key, else return -1
00066     int  Search ( T key, int bucketNo );
00067     //void Remove ( T key );
00068     //-------------------------------------------------------------------------
00069     // Operation(s) Sorted Elements
00070     //-------------------------------------------------------------------------
00071     // Insert in into bucket#
00072     // All values, assume numbers, in bucket will be sorted.
00073     // Return the inserted index
00074     int InsertSort ( T in,  int bucketNo );
00075     // Search key in bucket# with sorted values
00076     // Return the first index that contains the key, else return -1
00077     int  SearchSort ( T key, int bucketNo );    
00078     //void RemoveSort ( T key );
00079     //-------------------------------------------------------------------------
00080 }; // END CLASS HashTableBySTLVector
00081 //=============================================================================
00082 END_NAMESPACE_TAPs__DS
00083 //-----------------------------------------------------------------------------
00084 // Include definition if TAPs_USE_EXPORT is not defined
00085 //#if !defined( TAPs_USE_EXPORT )
00086     #include "TAPsHashTableBySTLVector.cpp"
00087 //#endif
00088 //-----------------------------------------------------------------------------
00089 #endif
00090 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00091 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines