~ubuntu-branches/ubuntu/raring/clucene-core/raring-proposed

« back to all changes in this revision

Viewing changes to src/CLucene/util/VoidMap.h

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-08-11 09:33:38 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120811093338-fgrx41ftqew3qt6a
Tags: 2.3.3.4-1
* New upstream release (Closes: #661703).
* Convert package to multiarch.
* Drop obsolete patches:
  - 01_add_missing_include_bug505667.diff
  - 02_posixness_fix_bug530308.diff
* Add patches:
  - Fixing_ZLIB_configuration_in_shared_CMakeLists.patch
  - Fix-pkgconfig-file-by-adding-clucene-shared-library.patch
  - Install-contribs-lib.patch
  - multiarch.patch
* Update debian/compat: bump to 8.
* Update debian/control:
  - update build dependencies (add cmake, libboost-dev and libz-dev).
  - bump Standards-Version to 3.9.3.
  - rename packages due to ABI bump: libclucene0ldbl -> libclucene-core1.
  - add libclucene-contribs1 package.
* Update debian/rules:
  - rewrite to use CMake.
  - add multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*------------------------------------------------------------------------------
2
 
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3
 
4
 
* Distributable under the terms of either the Apache License (Version 2.0) or 
5
 
* the GNU Lesser General Public License, as specified in the COPYING file.
6
 
------------------------------------------------------------------------------*/
7
 
#ifndef _lucene_util_VoidMap_
8
 
#define _lucene_util_VoidMap_
9
 
 
10
 
#if defined(_LUCENE_PRAGMA_ONCE)
11
 
# pragma once
12
 
#endif
13
 
 
14
 
 
15
 
CL_NS_DEF(util)
16
 
 
17
 
/**
18
 
* A template to encapsulate various map type classes
19
 
* @internal
20
 
*/
21
 
template<typename _kt, typename _vt, 
22
 
        typename _base,
23
 
        typename _KeyDeletor=CL_NS(util)::Deletor::Dummy,
24
 
        typename _ValueDeletor=CL_NS(util)::Deletor::Dummy>
25
 
class __CLMap:public _base,LUCENE_BASE {
26
 
private:
27
 
        bool dk;
28
 
        bool dv;
29
 
        typedef _base base;
30
 
public:
31
 
   DEFINE_MUTEX(THIS_LOCK)
32
 
 
33
 
        typedef typename _base::iterator iterator;
34
 
        typedef typename _base::const_iterator const_iterator;
35
 
        typedef CL_NS_STD(pair)<_kt, _vt> _pair;
36
 
 
37
 
        ///Default constructor for the __CLMap
38
 
        __CLMap ():
39
 
                dk(true),
40
 
                dv(true)
41
 
        {
42
 
        }
43
 
 
44
 
        ///Deconstructor for the __CLMap
45
 
        ~__CLMap (){
46
 
                clear();
47
 
        }
48
 
 
49
 
        void setDeleteKey(bool val){ dk = val; }
50
 
        void setDeleteValue(bool val){ dv = val; }
51
 
 
52
 
        ///Construct the VoidMap and set the deleteTypes to the specified values
53
 
        ///\param deleteKey if true then the key variable is deleted when an object is deleted
54
 
        ///\param keyDelType delete the key variable using the specified type
55
 
        ///\param deleteValue if true then the value variable is deleted when an object is deleted
56
 
        ///\param valueDelType delete the value variable using the specified type
57
 
        /*__CLMap ( const bool deleteKey, const bool deleteValue ):
58
 
                dk(deleteKey),
59
 
                dv(deleteValue)
60
 
        {
61
 
        }*/
62
 
 
63
 
        ///checks to see if the specified key exists
64
 
        ///\param k the key to check for
65
 
        ///\returns true if the key exists
66
 
        bool exists(_kt k)const{
67
 
                const_iterator itr = base::find(k);
68
 
                bool ret = itr!=base::end();
69
 
                return ret;
70
 
        }
71
 
 
72
 
        ///put the specified pair into the map. remove any old items first
73
 
        ///\param k the key
74
 
        ///\param v the value
75
 
        void put(_kt k,_vt v){
76
 
                //todo: check if this is always right!
77
 
                //must should look through code, for
78
 
                //cases where map is not unique!!!
79
 
                if ( dk || dv )
80
 
                        remove(k);
81
 
                        
82
 
                //todo: replacing the old item might be quicker...
83
 
                
84
 
                base::insert(_pair(k,v));
85
 
        }
86
 
 
87
 
        
88
 
        ///using a non-const key, get a non-const value
89
 
        _vt get( _kt k) const {
90
 
                const_iterator itr = base::find(k);
91
 
                if ( itr==base::end() ) 
92
 
                        return NULL;
93
 
                else 
94
 
                        return itr->second;
95
 
        }
96
 
        ///using a non-const key, get the actual key
97
 
        _kt getKey( _kt k) const {
98
 
                const_iterator itr = base::find(k);
99
 
                if ( itr==base::end() ) 
100
 
                        return NULL;
101
 
                else 
102
 
                        return itr->first;
103
 
        }
104
 
 
105
 
        void removeitr (iterator itr, const bool dontDeleteKey = false, const bool dontDeleteValue = false){
106
 
                //delete key&val first. This prevents potential loops (deleting object removes itself)
107
 
                _kt key = itr->first;
108
 
                _vt val = itr->second;
109
 
                base::erase(itr);
110
 
                
111
 
                //keys & vals need to be deleted after erase, because the hashvalue is still needed
112
 
                if ( dk && !dontDeleteKey ) 
113
 
                        _KeyDeletor::doDelete(key);
114
 
                if ( dv && !dontDeleteValue ) 
115
 
                        _ValueDeletor::doDelete(val);
116
 
        }
117
 
        ///delete and optionally delete the specified key and associated value
118
 
        void remove(_kt key, const bool dontDeleteKey = false, const bool dontDeleteValue = false){
119
 
                iterator itr = base::find(key);
120
 
                if ( itr!=base::end() )
121
 
                        removeitr(itr,dontDeleteKey,dontDeleteValue);
122
 
        }
123
 
 
124
 
        ///clear all keys and values in the map
125
 
        void clear(){
126
 
                if ( dk || dv ){
127
 
                        iterator itr = base::begin();
128
 
                        while ( itr!=base::end() ){
129
 
                                #ifdef _CL_HAVE_EXT_HASH_MAP
130
 
                                removeitr(itr);
131
 
                                itr = base::begin();
132
 
 
133
 
                                #else
134
 
                                if ( dk ) 
135
 
                                        _KeyDeletor::doDelete(itr->first);
136
 
                                if ( dv ) 
137
 
                                        _ValueDeletor::doDelete(itr->second);
138
 
                                ++itr;
139
 
                                
140
 
                                #endif
141
 
                        }
142
 
                }
143
 
                base::clear();
144
 
        }
145
 
};
146
 
 
147
 
// makes no guarantees as to the order of the map
148
 
// cannot contain duplicate keys; each key can map to at most one value
149
 
#define CLHashtable CLHashMap
150
 
 
151
 
#if defined(_CL_HAVE_GOOGLE_DENSE_HASH_MAP)
152
 
//do nothing, implementations is done later...
153
 
#elif defined(LUCENE_DISABLE_HASHING)
154
 
 
155
 
 //a CLSet with CLHashMap traits
156
 
template<typename _kt, typename _vt, 
157
 
        typename _Compare,
158
 
        typename _EqualDummy,
159
 
        typename _KeyDeletor=CL_NS(util)::Deletor::Dummy,
160
 
        typename _ValueDeletor=CL_NS(util)::Deletor::Dummy>
161
 
class CLHashMap:public __CLMap<_kt,_vt,
162
 
        CL_NS_STD(map)<_kt,_vt, _Compare>,
163
 
        _KeyDeletor,_ValueDeletor>
164
 
{
165
 
        typedef typename CL_NS_STD(map)<_kt,_vt,_Compare> _base;
166
 
        typedef __CLMap<_kt, _vt, CL_NS_STD(map)<_kt,_vt, _Compare>,
167
 
                _KeyDeletor,_ValueDeletor> _this;
168
 
public:
169
 
        CLHashMap ( const bool deleteKey=false, const bool deleteValue=false )
170
 
        {
171
 
                _this::setDeleteKey(deleteKey);
172
 
                _this::setDeleteValue(deleteValue);
173
 
        }
174
 
};
175
 
#elif defined(_CL_HAVE_EXT_HASH_MAP)
176
 
 //ext/hash_map syntax
177
 
//HashMap  class is roughly equivalent to Hashtable, except that it is unsynchronized
178
 
template<typename _kt, typename _vt,
179
 
        typename _Hasher,
180
 
        typename _Equals,
181
 
        typename _KeyDeletor=CL_NS(util)::Deletor::Dummy,
182
 
        typename _ValueDeletor=CL_NS(util)::Deletor::Dummy>
183
 
class CLHashMap:public __CLMap<_kt,_vt,
184
 
        CL_NS_HASHING(hash_map)<_kt,_vt, _Hasher,_Equals>,
185
 
        _KeyDeletor,_ValueDeletor>
186
 
{
187
 
        typedef __CLMap<_kt,_vt, CL_NS_HASHING(hash_map)<_kt,_vt, _Hasher,_Equals>,
188
 
                _KeyDeletor,_ValueDeletor> _this;
189
 
public:
190
 
        CLHashMap ( const bool deleteKey=false, const bool deleteValue=false )
191
 
        {
192
 
                _this::setDeleteKey(deleteKey);
193
 
                _this::setDeleteValue(deleteValue);
194
 
        }
195
 
};
196
 
 
197
 
#else
198
 
//HashMap  class is roughly equivalent to Hashtable, except that it is unsynchronized
199
 
template<typename _kt, typename _vt,
200
 
        typename _Hasher,
201
 
        typename _Equals,
202
 
        typename _KeyDeletor=CL_NS(util)::Deletor::Dummy,
203
 
        typename _ValueDeletor=CL_NS(util)::Deletor::Dummy>
204
 
class CLHashMap:public __CLMap<_kt,_vt,
205
 
        CL_NS_HASHING(hash_map)<_kt,_vt, _Hasher>,
206
 
        _KeyDeletor,_ValueDeletor>
207
 
{
208
 
        typedef __CLMap<_kt,_vt, CL_NS_HASHING(hash_map)<_kt,_vt, _Hasher>,
209
 
                _KeyDeletor,_ValueDeletor> _this;
210
 
public:
211
 
        CLHashMap ( const bool deleteKey=false, const bool deleteValue=false )
212
 
        {
213
 
                _this::setDeleteKey(deleteKey);
214
 
                _this::setDeleteValue(deleteValue);
215
 
        }
216
 
};
217
 
#endif
218
 
 
219
 
//A collection that contains no duplicates
220
 
//does not guarantee that the order will remain constant over time
221
 
template<typename _kt, typename _vt, 
222
 
        typename _Compare,
223
 
        typename _KeyDeletor=CL_NS(util)::Deletor::Dummy,
224
 
        typename _ValueDeletor=CL_NS(util)::Deletor::Dummy>
225
 
class CLSet:public __CLMap<_kt,_vt,
226
 
        CL_NS_STD(map)<_kt,_vt, _Compare>,
227
 
        _KeyDeletor,_ValueDeletor>
228
 
{
229
 
        typedef typename CL_NS_STD(map)<_kt,_vt,_Compare> _base;
230
 
        typedef __CLMap<_kt, _vt, CL_NS_STD(map)<_kt,_vt, _Compare>,
231
 
                _KeyDeletor,_ValueDeletor> _this;
232
 
public:
233
 
        CLSet ( const bool deleteKey=false, const bool deleteValue=false )
234
 
        {
235
 
                _this::setDeleteKey(deleteKey);
236
 
                _this::setDeleteValue(deleteValue);
237
 
        }
238
 
};
239
 
 
240
 
 
241
 
//A collection that can contains duplicates
242
 
template<typename _kt, typename _vt,
243
 
        typename _Compare,
244
 
        typename _KeyDeletor=CL_NS(util)::Deletor::Dummy,
245
 
        typename _ValueDeletor=CL_NS(util)::Deletor::Dummy>
246
 
class CLMultiMap:public __CLMap<_kt,_vt,
247
 
        CL_NS_STD(multimap)<_kt,_vt>,
248
 
        _KeyDeletor,_ValueDeletor>
249
 
{
250
 
        typedef typename CL_NS_STD(multimap)<_kt,_vt> _base;
251
 
        typedef __CLMap<_kt, _vt, CL_NS_STD(multimap)<_kt,_vt>,
252
 
                _KeyDeletor,_ValueDeletor> _this;
253
 
public:
254
 
        CLMultiMap ( const bool deleteKey=false, const bool deleteValue=false )
255
 
        {
256
 
                _this::setDeleteKey(deleteKey);
257
 
                _this::setDeleteValue(deleteValue);
258
 
        }
259
 
};
260
 
 
261
 
 
262
 
//*** need to create a class that allows duplicates - use <set>
263
 
//#define CLSet __CLMap
264
 
CL_NS_END
265
 
 
266
 
#ifdef _CL_HAVE_GOOGLE_DENSE_HASH_MAP
267
 
#include "GoogleSparseMap.h"
268
 
#endif
269
 
 
270
 
#endif