SimOrdMap.h

Classes

SimpleOrderedMap -- Simple map with keys ordered (full description)

template<class K, class V> class SimpleOrderedMap

Interface

Public Members
SimpleOrderedMap (const V& defaultValue, uInt size)
explicit SimpleOrderedMap (const V& defaultValue)
SimpleOrderedMap (const SimpleOrderedMap<K,V>&)
~SimpleOrderedMap ()
SimpleOrderedMap<K,V>& operator= (const SimpleOrderedMap<K,V>&)
V &define (const K&, const V&)
V &operator()(const K &ky)
const V &operator()(const K &ky) const
V &defaultVal()
const V &defaultVal() const
V *isDefined(const K&)
const V *isDefined(const K& k) const
uInt ndefined() const
const K& getKey (uInt inx) const
const V& getVal (uInt inx) const
V& getVal (uInt inx)
void rename (const K& newkey, const K& oldkey)
void remove (const K&)
void clear ()
uInt ntot() const
uInt incr() const
uInt incr(uInt nri)
Bool ok() const
static uInt Version()
Protected Members
uInt findKey (const K&, Bool&) const
void copyBlock (const SimpleOrderedMap<K,V>&)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

SimpleOrderedMap is a template class. It is similar to OrderedMap, but lacks its sophisticated iterator capability. Instead iteration can be done using the getKey and getVal function with a simple index. The function ndefined() gives the number of key,value pairs in the map.

It uses a Block to store an array of pointers to the keys and the associated values. The keys and values themselves are stored on the heap. The keys are kept in order to allow a binary search through the keys for rapid access.

This is one (simple) implementation of an ordered map. It is not suitable for large arrays of keys, since the overhead of keeping the keys in order would get too big.

Exceptions are raised when new[] is failing or when the next() getKey() or getValue() function is failing.

The AipsIO >> and << operators are defined in .

Member Description

SimpleOrderedMap (const V& defaultValue, uInt size)

Creates a map with the specified default value, "value", and the internal block size.

explicit SimpleOrderedMap (const V& defaultValue)

Creates a map with the specified default value, "value".

SimpleOrderedMap (const SimpleOrderedMap<K,V>&)

Creates a map from another one; use copy semantics.

Thrown Exceptions

~SimpleOrderedMap ()

Removes a map.

SimpleOrderedMap<K,V>& operator= (const SimpleOrderedMap<K,V>&)

Assigns this SimpleOrderedMap to another with copy semantics.

Thrown Exceptions

V &define (const K&, const V&)

Defines a mapping (ie. create a key value mapping)

Thrown Exceptions

V &operator()(const K &ky)

This is the mapping function which maps keys to values. If the map from the key to a value is not defined, a mapping will be defined from the key to the default value (which is set from the constructor. The "isDefined()" member function can be used to check to see if a mapping is defined before using the "operator()()".

With a constant map in the case where the key is not defined, the mapping between key and default value is not created, but rather an exception is thrown. +grp

const V &operator()(const K &ky) const

Thrown Exceptions

V &defaultVal()

-grp

Returns the default value for the Map. +grp

const V &defaultVal() const

V *isDefined(const K&)

-grp

These functions check to see if a mapping is defined between the specified key and some value. If one is, a pointer to the value is returned, otherwise 0 is returned. +grp

const V *isDefined(const K& k) const

uInt ndefined() const

-grp

Get the number of elements in the map.

const K& getKey (uInt inx) const

Get the i-th key in the map. It can be used to iterate through the keys as: for (uInt i=0; i Index checking is only done if Block is doing it.

const V& getVal (uInt inx) const

Get the i-th value in the map. It can be used to iterate through the keys as: for (uInt i=0; i Index checking is only done if Block is doing it. +grp

V& getVal (uInt inx)

void rename (const K& newkey, const K& oldkey)

-grp

Rename a key. If the new key already exists, the existing key will be removed.

Thrown Exceptions

void remove (const K&)

Undefines a mapping (ie. remove a key value mapping).

Thrown Exceptions

void clear ()

Clear the entire map (ie. remove all mappings).

uInt ntot() const

Get the total size of the block in use.

uInt incr() const

Get or set the Block allocation increment. +grp

uInt incr(uInt nri)

Bool ok() const

-grp

Check the internal state.

Thrown Exceptions

static uInt Version()

Version for major change (used by SimOrdMapIO). enum did not work properly with cfront 3.0.1), so replaced by a static inline function. Users won't normally use this.

uInt findKey (const K&, Bool&) const

Binary search for the key.

void copyBlock (const SimpleOrderedMap<K,V>&)

Copy from another Block of OrderedPair's.

Thrown Exceptions