CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 //note: you may be bound by the google license if you choose 00008 //to compile your source code with the google sparsemap library 00009 #ifndef _lucene_util_GoogleSparseMaps_H 00010 #define _lucene_util_GoogleSparseMaps_H 00011 00012 #if defined(_LUCENE_PRAGMA_ONCE) 00013 # pragma once 00014 #endif 00015 00016 #ifdef _CL_HAVE_GOOGLE_DENSE_HASH_MAP 00017 00018 #include <google/dense_hash_map> 00019 00020 CL_NS_DEF(util) 00021 00022 00023 template<typename _Type, typename _Equals> 00024 class SparseMapEquals{ 00025 _Equals equals; 00026 public: 00027 bool operator()( _Type val1, _Type val2 ) const{ 00028 if ( val1==val2 ) 00029 return true; 00030 else if ( val1 == NULL || val2 == NULL ) 00031 return false; 00032 else if ( val1 == (_Type)0x02 || val2 == (_Type)0x02 ) 00033 return false; 00034 return equals(val1,val2); 00035 } 00036 }; 00037 00038 template<typename _kt, typename _vt, 00039 typename _Hasher, 00040 typename _Equals, 00041 typename _KeyDeletor=CL_NS(util)::Deletor::Dummy, 00042 typename _ValueDeletor=CL_NS(util)::Deletor::Dummy > 00043 class CLHashMap:public __CLMap<_kt,_vt, 00044 GOOGLE_NAMESPACE::dense_hash_map<_kt,_vt, _Hasher, SparseMapEquals<_kt,_Equals> >, 00045 _KeyDeletor,_ValueDeletor> 00046 { 00047 typedef __CLMap<_kt,_vt, 00048 GOOGLE_NAMESPACE::dense_hash_map<_kt,_vt, _Hasher, SparseMapEquals<_kt,_Equals> >, 00049 _KeyDeletor,_ValueDeletor> _this; 00050 public: 00051 CLHashMap ( bool deleteKey=false, bool deleteValue=false ) 00052 { 00053 GOOGLE_NAMESPACE::dense_hash_map<_kt,_vt, _Hasher, SparseMapEquals<_kt,_Equals> >::set_empty_key(NULL); 00054 GOOGLE_NAMESPACE::dense_hash_map<_kt,_vt, _Hasher, SparseMapEquals<_kt,_Equals> >::set_deleted_key((_kt)0x02); 00055 _this::setDeleteKey(deleteKey); 00056 _this::setDeleteValue(deleteValue); 00057 } 00058 ~CLHashMap(){ 00059 00060 } 00061 }; 00062 00063 00064 CL_NS_END 00065 #endif //LUCENE_USE_GOOGLEMAPS 00066 #endif