28 #ifndef CASA_HASHMAP_H 29 #define CASA_HASHMAP_H 31 #ifndef AIPS_USE_DEPRECATED 32 #error "HashMap.h is deprecated; use -DBUILD_DEPRECATED=ON to use it" 36 #include <casacore/casa/aips.h> 37 #include <casacore/casa/Containers/Block.h> 38 #include <casacore/casa/Containers/List.h> 39 #include <casacore/casa/Containers/OrderedPair.h> 40 #include <casacore/casa/Exceptions/Error.h> 84 const Int &defaultHashValue(
const Int *);
85 const uInt &defaultHashValue(
const uInt *);
86 const Long &defaultHashValue(
const Long *);
301 template<
class key,
class val>
class HashMap {
310 typedef uInt (*Func)(
const key&);
330 HashMap(
const val &dflt = defaultHashValue((
const val*)(0)),
333 float maxlf =
float(defaultMaxLoad_))
346 float maxlf =
float(defaultMaxLoad_))
354 hashClass(newfunc.
clone()),
375 HashMap(
const val &dflt, Func newfunc,
float maxlf =
float(defaultMaxLoad_))
376 : total_(
uInt(defaultSize())), used_(
uInt(defaultSize())),
377 filled_(0), defs_(0), maxLoad_(maxlf),
379 func(newfunc), hashClass(0), dfltVal(dflt)
383 float maxlf =
float(defaultMaxLoad_))
384 : total_(defaultSize()), used_(defaultSize()),
385 filled_(0), defs_(0), maxLoad_(maxlf),
387 hashClass(newfunc.
clone()), dfltVal(dflt)
405 const val &operator() (
const key &ky)
const;
406 val &operator() (
const key &ky);
412 val &define(
const key &k,
const val &v);
418 void remove(
const key &k);
423 Bool isDefined(
const key &k)
const;
469 float loading()
const {
return ndefined() ? (float) ndefined() / (float) availableBuckets() : 0.0; }
477 uInt totalSize()
const;
484 enum {HashMapVersion = 1};
489 uInt off = func ? (*func)(k) % totalBuckets() :
490 hashClass ? hashClass->hash(k) % totalBuckets() : 0;
491 return off >= availableBuckets() ? off - (totalBuckets() >> 1) : off;
528 #ifndef CASACORE_NO_AUTO_TEMPLATES 529 #include <casacore/casa/Containers/HashMap.tcc> 530 #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.