~ubuntu-branches/ubuntu/edgy/djvulibre/edgy

« back to all changes in this revision

Viewing changes to libdjvu/GContainer.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-07-03 11:38:23 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703113823-un2te7742kk04c63
Tags: 3.5.17-1ubuntu1
* Sync with Debian
* debian/rules:
  - use dh_iconcache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
53
53
// 
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 $
56
56
 
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.
132
132
    @version 
133
 
    #$Id: GContainer.h,v 1.15 2004/05/13 15:16:34 leonb Exp $# */
134
 
//@{
 
133
    #$Id: GContainer.h,v 1.18 2006/03/14 19:50:27 leonb Exp $# */
 
134
//@{
 
135
 
 
136
 
 
137
 
 
138
// ------------------------------------------------------------
 
139
// HASH FUNCTIONS
 
140
// ------------------------------------------------------------
 
141
 
 
142
 
 
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
 
147
    the range.
 
148
    @memo Hash functions for elementary types. */
 
149
//@{
 
150
 
 
151
/** Hashing function (unsigned int). */
 
152
static inline unsigned int 
 
153
hash(const unsigned int & x) 
 
154
 
155
  return x; 
 
156
}
 
157
 
 
158
/** Hashing function (int). */
 
159
static inline unsigned int 
 
160
hash(const int & x) 
 
161
 
162
  return (unsigned int)x;
 
163
}
 
164
 
 
165
/** Hashing function (long). */
 
166
static inline unsigned int
 
167
hash(const long & x) 
 
168
 
169
  return (unsigned int)x;
 
170
}
 
171
 
 
172
/** Hashing function (unsigned long). */
 
173
static inline unsigned int
 
174
hash(const unsigned long & x) 
 
175
 
176
  return (unsigned int)x;
 
177
}
 
178
 
 
179
/** Hashing function (const void *). */
 
180
static inline unsigned int 
 
181
hash(const void * const & x) 
 
182
 
183
  return (unsigned long) x; 
 
184
}
 
185
 
 
186
/** Hashing function (float). */
 
187
static inline unsigned int
 
188
hash(const float & x) 
 
189
 
190
  // optimizer will get rid of unnecessary code  
 
191
  unsigned int *addr = (unsigned int*)&x;
 
192
  if (sizeof(float)<2*sizeof(unsigned int))
 
193
    return addr[0];
 
194
  else
 
195
    return addr[0]^addr[1];
 
196
}
 
197
 
 
198
/** Hashing function (double). */
 
199
static inline unsigned int
 
200
hash(const double & x) 
 
201
 
202
  // optimizer will get rid of unnecessary code
 
203
  unsigned int *addr = (unsigned int*)&x;
 
204
  if (sizeof(double)<2*sizeof(unsigned int))
 
205
    return addr[0];
 
206
  else if (sizeof(double)<4*sizeof(unsigned int))
 
207
    return addr[0]^addr[1];
 
208
  else
 
209
    return addr[0]^addr[1]^addr[2]^addr[3];    
 
210
}
135
211
 
136
212
 
137
213
 
332
408
protected:
333
409
  const Traits &traits;
334
410
  void  *data;
335
 
  GPBufferBase gdata;
336
411
  int   minlo;
337
412
  int   maxhi;
338
413
  int   lobound;
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; }
399
472
  // -- ALTERATION
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;
754
827
  void empty();
755
828
};
845
918
  // -- TEST
846
919
  /** Tests whether a list is empty.  
847
920
      Returns a non zero value if the list contains no elements. */
848
 
  int isempty() const 
 
921
  bool isempty() const 
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. */
1161
 
  int isempty() const
 
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
1266
1339
};
1267
1340
 
1268
1341
 
1269
 
// ------------------------------------------------------------
1270
 
// HASH FUNCTIONS
1271
 
// ------------------------------------------------------------
1272
 
 
1273
 
 
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
1278
 
    the range.
1279
 
    @memo Hash functions for elementary types. */
1280
 
//@{
1281
 
 
1282
 
/** Hashing function (unsigned int). */
1283
 
static inline unsigned int 
1284
 
hash(const unsigned int & x) 
1285
 
1286
 
  return x; 
1287
 
}
1288
 
 
1289
 
/** Hashing function (int). */
1290
 
static inline unsigned int 
1291
 
hash(const int & x) 
1292
 
1293
 
  return (unsigned int)x;
1294
 
}
1295
 
 
1296
 
/** Hashing function (long). */
1297
 
static inline unsigned int
1298
 
hash(const long & x) 
1299
 
1300
 
  return (unsigned int)x;
1301
 
}
1302
 
 
1303
 
/** Hashing function (unsigned long). */
1304
 
static inline unsigned int
1305
 
hash(const unsigned long & x) 
1306
 
1307
 
  return (unsigned int)x;
1308
 
}
1309
 
 
1310
 
/** Hashing function (void *). */
1311
 
static inline unsigned int 
1312
 
hash(void * const & x) 
1313
 
1314
 
  return (unsigned long) x; 
1315
 
}
1316
 
 
1317
 
/** Hashing function (const void *). */
1318
 
static inline unsigned int 
1319
 
hash(const void * const & x) 
1320
 
1321
 
  return (unsigned long) x; 
1322
 
}
1323
 
 
1324
 
/** Hashing function (float). */
1325
 
static inline unsigned int
1326
 
hash(const float & x) 
1327
 
1328
 
  // optimizer will get rid of unnecessary code  
1329
 
  unsigned int *addr = (unsigned int*)&x;
1330
 
  if (sizeof(float)<2*sizeof(unsigned int))
1331
 
    return addr[0];
1332
 
  else
1333
 
    return addr[0]^addr[1];
1334
 
}
1335
 
 
1336
 
/** Hashing function (double). */
1337
 
static inline unsigned int
1338
 
hash(const double & x) 
1339
 
1340
 
  // optimizer will get rid of unnecessary code
1341
 
  unsigned int *addr = (unsigned int*)&x;
1342
 
  if (sizeof(double)<2*sizeof(unsigned int))
1343
 
    return addr[0];
1344
 
  else if (sizeof(double)<4*sizeof(unsigned int))
1345
 
    return addr[0]^addr[1];
1346
 
  else
1347
 
    return addr[0]^addr[1]^addr[2]^addr[3];    
1348
 
}
1349
 
 
1350
1342
 
1351
1343
//@}
1352
1344
//@}