51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
54
// $Id: GContainer.h,v 1.15 2004/05/13 15:16:34 leonb Exp $
55
// $Name: debian_version_3_5_16-1 $
54
// $Id: GContainer.h,v 1.18 2006/03/14 19:50:27 leonb Exp $
55
// $Name: debian_version_3_5_17-1 $
57
57
#ifndef _GCONTAINER_H_
58
58
#define _GCONTAINER_H_
130
130
L\'eon Bottou <leonb@research.att.com> -- initial implementation.\\
131
131
Andrei Erofeev <eaf@geocities.com> -- bug fixes.
133
#$Id: GContainer.h,v 1.15 2004/05/13 15:16:34 leonb Exp $# */
133
#$Id: GContainer.h,v 1.18 2006/03/14 19:50:27 leonb Exp $# */
138
// ------------------------------------------------------------
140
// ------------------------------------------------------------
143
/** @name Hash functions
144
These functions let you use template class \Ref{GMap} with the
145
corresponding elementary types. The returned hash code may be reduced to
146
an arbitrary range by computing its remainder modulo the upper bound of
148
@memo Hash functions for elementary types. */
151
/** Hashing function (unsigned int). */
152
static inline unsigned int
153
hash(const unsigned int & x)
158
/** Hashing function (int). */
159
static inline unsigned int
162
return (unsigned int)x;
165
/** Hashing function (long). */
166
static inline unsigned int
169
return (unsigned int)x;
172
/** Hashing function (unsigned long). */
173
static inline unsigned int
174
hash(const unsigned long & x)
176
return (unsigned int)x;
179
/** Hashing function (const void *). */
180
static inline unsigned int
181
hash(const void * const & x)
183
return (unsigned long) x;
186
/** Hashing function (float). */
187
static inline unsigned int
188
hash(const float & x)
190
// optimizer will get rid of unnecessary code
191
unsigned int *addr = (unsigned int*)&x;
192
if (sizeof(float)<2*sizeof(unsigned int))
195
return addr[0]^addr[1];
198
/** Hashing function (double). */
199
static inline unsigned int
200
hash(const double & x)
202
// optimizer will get rid of unnecessary code
203
unsigned int *addr = (unsigned int*)&x;
204
if (sizeof(double)<2*sizeof(unsigned int))
206
else if (sizeof(double)<4*sizeof(unsigned int))
207
return addr[0]^addr[1];
209
return addr[0]^addr[1]^addr[2]^addr[3];
394
469
invocation of this conversion operator. */
395
470
operator const TYPE* () const
396
471
{ return ((const TYPE*)data)-minlo; }
397
operator const TYPE* () // suppress warning with gcc-2.95
398
{ return ((const TYPE*)data)-minlo; }
400
473
/** Erases the array contents. All elements in the array are destroyed.
401
474
The valid subscript range is set to the empty range. */
749
822
GListBase & operator= (const GListBase & gl);
750
823
GPosition firstpos() const { return GPosition(head.next, (void*)this); }
751
824
GPosition lastpos() const { return GPosition(head.prev, (void*)this); }
752
int isempty() const { return nelem==0; };
825
bool isempty() const { return nelem==0; };
753
826
GPosition nth(unsigned int n) const;
846
919
/** Tests whether a list is empty.
847
920
Returns a non zero value if the list contains no elements. */
849
922
{ return this->nelem==0; }
850
923
/** Compares two lists. Returns a non zero value if and only if both lists
851
924
contain the same elements (as tested by #TYPE::operator==(const TYPE&)#
1158
1231
{ return firstpos(); }
1159
1232
/** Tests whether the associative map is empty.
1160
1233
Returns a non zero value if and only if the map contains zero entries. */
1234
bool isempty() const
1162
1235
{ return this->nelems==0; }
1163
1236
/** Searches an entry for key #key#. If the map contains an entry whose key
1164
1237
is equal to #key# according to #KTYPE::operator==(const KTYPE&)#, this
1269
// ------------------------------------------------------------
1271
// ------------------------------------------------------------
1274
/** @name Hash functions
1275
These functions let you use template class \Ref{GMap} with the
1276
corresponding elementary types. The returned hash code may be reduced to
1277
an arbitrary range by computing its remainder modulo the upper bound of
1279
@memo Hash functions for elementary types. */
1282
/** Hashing function (unsigned int). */
1283
static inline unsigned int
1284
hash(const unsigned int & x)
1289
/** Hashing function (int). */
1290
static inline unsigned int
1293
return (unsigned int)x;
1296
/** Hashing function (long). */
1297
static inline unsigned int
1298
hash(const long & x)
1300
return (unsigned int)x;
1303
/** Hashing function (unsigned long). */
1304
static inline unsigned int
1305
hash(const unsigned long & x)
1307
return (unsigned int)x;
1310
/** Hashing function (void *). */
1311
static inline unsigned int
1312
hash(void * const & x)
1314
return (unsigned long) x;
1317
/** Hashing function (const void *). */
1318
static inline unsigned int
1319
hash(const void * const & x)
1321
return (unsigned long) x;
1324
/** Hashing function (float). */
1325
static inline unsigned int
1326
hash(const float & x)
1328
// optimizer will get rid of unnecessary code
1329
unsigned int *addr = (unsigned int*)&x;
1330
if (sizeof(float)<2*sizeof(unsigned int))
1333
return addr[0]^addr[1];
1336
/** Hashing function (double). */
1337
static inline unsigned int
1338
hash(const double & x)
1340
// optimizer will get rid of unnecessary code
1341
unsigned int *addr = (unsigned int*)&x;
1342
if (sizeof(double)<2*sizeof(unsigned int))
1344
else if (sizeof(double)<4*sizeof(unsigned int))
1345
return addr[0]^addr[1];
1347
return addr[0]^addr[1]^addr[2]^addr[3];