/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Muc/MucGeomSvc/MucGeomSvc-00-02-25/MucGeomSvc/tmp/hash_vector.hh

Go to the documentation of this file.
00001 //======================================================================
00002 //  File:        hash.h
00003 //  Author:      Timothy A. Budd
00004 //  Description: This file contains the interface and implementation
00005 //               of the hash template classes.
00006 //
00007 //  Copyright (c) 1992 by Timothy A. Budd.  All Rights Reserved.
00008 //      may be reproduced for any non-commercial purpose
00009 //
00010 //  Modified:  March 11, 1998 by Kyle Pope
00011 //             Inherit from STL std::vector<T> class.
00012 //
00013 //======================================================================
00014 
00015 #ifndef HASH_H
00016 #define HASH_H
00017 
00018 #include <stddef.h>
00019 #include <vector>
00020 
00021 //----------------------------------------------------------------------
00022 //      class hashVector
00023 //              vector indexed using hashed key values
00024 //              template types are type of key
00025 //              and type of value stored in vector
00026 //----------------------------------------------------------------------
00027 
00028 //template <class T> class vector;
00029 
00030 using namespace std;
00031 
00032 template <class H, class T> class hashVector : public vector<T>
00033 {
00034 public:
00035     // constructors
00036     hashVector(size_t max, size_t (*f)(const H &));
00037     hashVector(size_t max, size_t (*f)(const H &), T & initialValue);
00038     hashVector(const hashVector<H, T> & v);
00039 
00040     // subscript operation
00041     T & operator [] (const H & index);
00042     const T & operator [] (const H & index) const;
00043 
00044 private:
00045     // store the hash function
00046     size_t (*hashfun)(const H &);
00047 };
00048 
00049 //----------------------------------------------------------------------
00050 //      class hashVector implementation
00051 //----------------------------------------------------------------------
00052 
00053 template <class H, class T>
00054 inline hashVector<H, T>::hashVector(size_t max, size_t (*f)(const H &))
00055     : vector<T>(max), hashfun(f)
00056 {
00057     // no further initialization
00058 }
00059 
00060 
00061 
00062 template <class H, class T>
00063 inline hashVector<H, T>::hashVector(size_t max, size_t (*f)(const H&), T& initialValue)
00064     : vector<T>(max, initialValue), hashfun(f)
00065 {
00066     // no further initialization
00067 }
00068 
00069 
00070 
00071 template <class H, class T>
00072 inline hashVector<H, T>::hashVector(const hashVector<H,T> & v)
00073     : vector<T>(v), hashfun(v.hashfun)
00074 {
00075     // no further initialization
00076 }
00077 
00078 
00079 
00080 template <class H, class T>
00081 inline T & hashVector<H, T>::operator[] (const H & index)
00082 {
00083   // subscript a hash vector
00084   // hash the index value before indexing vector
00085   return vector<T>::operator[] ((*hashfun)(index) % size());
00086 }
00087 
00088 
00089 template <class H, class T>
00090 inline const T & hashVector<H, T>::operator[] (const H & index) const
00091 {
00092   // subscript a hash vector
00093   // hash the index value before indexing vector
00094   return vector<T>::operator[] ((*hashfun)(index) % size());
00095 }
00096 
00097 //----------------------------------------------------------------------
00098 //      miscellaneous template functions
00099 //----------------------------------------------------------------------
00100 
00101 #endif

Generated on Tue Nov 29 23:12:57 2016 for BOSS_7.0.2 by  doxygen 1.4.7