build-artifacts/win/product/include/gfcpp/HashFunction.hpp

Go to the documentation of this file.
00001 #ifndef _GEMFIRE_HASHFUNCTION_HPP_
00002 #define _GEMFIRE_HASHFUNCTION_HPP_
00003 
00004 
00005 /*=========================================================================
00006  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
00007  * This product is protected by U.S. and international copyright
00008  * and intellectual property laws. Pivotal products are covered by
00009  * more patents listed at http://www.pivotal.io/patents.
00010  *========================================================================
00011  */
00012 
00013 #include "gfcpp_globals.hpp"
00014 #include "SharedPtr.hpp"
00015 #include "CacheableKey.hpp"
00016 
00017 
00021 namespace gemfire
00022 {
00023 
00025   typedef int32_t (*Hasher) ( const SharedBasePtr& );
00026 
00028   typedef bool (*EqualTo) ( const SharedBasePtr&, const SharedBasePtr& );
00029 
00030 
00031   class HashSB
00032   {
00033     private:
00034 
00035       Hasher m_hashFn;
00036 
00037       // Never defined.
00038       HashSB( );
00039 
00040 
00041     public:
00042 
00043       HashSB( const Hasher hashFn )
00044         : m_hashFn( hashFn )
00045       {
00046       }
00047 
00048       int32_t operator () ( const SharedBasePtr& p ) const
00049       {
00050         return m_hashFn( p );
00051       }
00052   };
00053 
00054 
00055   class EqualToSB
00056   {
00057     private:
00058 
00059       EqualTo m_equalFn;
00060 
00061       // Never defined.
00062       EqualToSB( );
00063 
00064 
00065     public:
00066 
00067       EqualToSB( const EqualTo equalFn)
00068         : m_equalFn( equalFn )
00069       {
00070       }
00071 
00072       bool operator () ( const SharedBasePtr& x, const SharedBasePtr& y ) const
00073       {
00074         return m_equalFn( x, y );
00075       }
00076   };
00077 
00078 
00079   template < typename TKEY >
00080   inline int32_t hashFunction( const TKEY& k )
00081   {
00082     return k->hashcode( );
00083   }
00084 
00085   template < typename TKEY >
00086   inline bool equalToFunction( const TKEY& x, const TKEY& y )
00087   {
00088     return ( *x.ptr( ) == *y.ptr( ) );
00089   }
00090 
00091 }
00092 
00093 
00094 #endif

GemFire C++ Cache API Documentation