28 #ifndef CASA_HASHMAP_H 29 #define CASA_HASHMAP_H 32 #include <casacore/casa/aips.h> 33 #include <casacore/casa/Containers/Block.h> 34 #include <casacore/casa/Containers/List.h> 35 #include <casacore/casa/Containers/OrderedPair.h> 36 #include <casacore/casa/Exceptions/Error.h> 80 const Int &defaultHashValue(
const Int *);
81 const uInt &defaultHashValue(
const uInt *);
82 const Long &defaultHashValue(
const Long *);
297 template<
class key,
class val>
class HashMap {
306 typedef uInt (*Func)(
const key&);
326 HashMap(
const val &dflt = defaultHashValue((
const val*)(0)),
329 float maxlf =
float(defaultMaxLoad_))
342 float maxlf =
float(defaultMaxLoad_))
350 hashClass(newfunc.
clone()),
371 HashMap(
const val &dflt, Func newfunc,
float maxlf =
float(defaultMaxLoad_))
372 : total_(
uInt(defaultSize())), used_(
uInt(defaultSize())),
373 filled_(0), defs_(0), maxLoad_(maxlf),
375 func(newfunc), hashClass(0), dfltVal(dflt)
379 float maxlf =
float(defaultMaxLoad_))
380 : total_(defaultSize()), used_(defaultSize()),
381 filled_(0), defs_(0), maxLoad_(maxlf),
383 hashClass(newfunc.
clone()), dfltVal(dflt)
401 const val &operator() (
const key &ky)
const;
402 val &operator() (
const key &ky);
408 val &define(
const key &k,
const val &v);
414 void remove(
const key &k);
419 Bool isDefined(
const key &k)
const;
465 float loading()
const {
return ndefined() ? (float) ndefined() / (float) availableBuckets() : 0.0; }
473 uInt totalSize()
const;
480 enum {HashMapVersion = 1};
485 uInt off = func ? (*func)(k) % totalBuckets() :
486 hashClass ? hashClass->hash(k) % totalBuckets() : 0;
487 return off >= availableBuckets() ? off - (totalBuckets() >> 1) : off;
524 #ifndef CASACORE_NO_AUTO_TEMPLATES 525 #include <casacore/casa/Containers/HashMap.tcc> 526 #endif //# CASACORE_NO_AUTO_TEMPLATES
uInt totalBuckets() const
Total number of buckets, i.e.
HashMap(const val &dflt, uInt size, const HashClass< key > &newfunc, float maxlf=float(defaultMaxLoad_))
const val & defaultVal() const
Retrieve the default value.
uInt usedBuckets() const
Number of buckets currently populated by a bucket list.
uInt availableBuckets() const
Number of buckets available, i.e.
PtrBlock< List< OrderedPair< key, val > > * > blk
PtrHolder< T > & operator=(const PtrHolder< T > &other)
Bool empty() const
Have any mappings been defined by the user.
void throw_hashmapiter_init_error()
HashMap(const val &dflt, Func newfunc, float maxlf=float(defaultMaxLoad_))
Constructor which allows for specifying:
float maxLoad_
Maximum load.
static uInt defaultSize()
uInt ndefined() const
Number of mappings which have been defined by the user.
Hash function with state.
virtual HashClass< key > * clone() const =0
This function is used to make a deep copy.
static float defaultMaxLoad()
HashMap(const val &dflt, const HashClass< key > &newfunc, float maxlf=float(defaultMaxLoad_))
uInt used_
Slots Being Used.
uInt filled_
Slots with At Least One Value in the Bucket.
bool Bool
Define the standard types used by Casacore.
uInt hashFunc(const ObjectID &)
HashMap(const val &dflt=defaultHashValue((const val *)(0)), uInt size=uInt(defaultSize_), Func newfunc=hashFunc, float maxlf=float(defaultMaxLoad_))
Default constructor (and variation) which allows for specifying:
uInt defs_
Number of Defined Mappings.
A drop-in replacement for Block<T*>.
void setMaxLoad(float new_max)
void throw_invalid_hashmapiter_error()
virtual uInt hash(const key &)=0
This function maps elements of key type to any integer.
HashClass< key > * hashClass
uInt hash(const key &k) const
Call the hash function.
float loading() const
Current hash table loading factor.
String: the storage and methods of handling collections of characters.
uInt allocBuckets() const
Number of buckets which have been allocated, i.e.
void clear()
Remove all user defined mapping.
this file contains all the compiler specific defines
float maxLoad() const
Get or set the maximum load factor.
Associative Array with a hash table implementation.