Status & Roadmap
Authors & License
Funding Ultimate++
Search on this site

SourceForge.net Logo



template <class K, class T, class V, class Less>

class FixedAMap

FixedAMap is a simple adapter class over Vector of keys and values container (Vector or Array) which is space-effective variant of map in useful situation where map content is constant and known before map is created. Fundamental difference is that this kind of map is not capable of searching unless Finish method is called. Current implementation is using sorted vector of keys, thus memory consumption of FixedAMap is the same as that of two original containers. Search have log(N) complexity and thus FixedAMap is slower that standard hashing based maps, but the memory footprint is much better.


Public Method List


T& Add(const K& k, const T& x)

T& AddPick(const K& k, T&& x)

T& Add(const K& k)

Adds new key-value pair to the map, returns a reference to value. After calling Add one or more times, Finish has to be called to get map ready for searching.



void Finish()

Prepares map for searching (current implementation IndexSorts keys and values).



int Find(const K& kconst

Returns the minimum index of element with key equal to k or negative number if not found.



int FindNext(int iconst

If the key at i + 1 is equal to the key at i , returns i + 1, otherwise returns negative number.



T& Get(const K& k)

const T& Get(const K& kconst

Returns the value of the first element with key k. If not found, behaviour is undefined.



const T& Get(const K& k, const T& dconst

Returns the value of the first element with key k. If not found, returns d.



T *FindPtr(const K& k)

const T *FindPtr(const K& kconst

Returns to pointer to the value of the first element with key k. If not found, returns NULL.



const T& operator[](int iconst

T& operator[](int i)

Returns the value of element at i.



int GetCount() const

Returns the number of elements.



bool IsEmpty() const

Same as GetCount() == 0.



void Clear()

Removes all elements.



void Shrink()

Minimizes the memory usage, dropping allocation reserves.



void Reserve(int xtra)

Reserves capacity. If the required capacity is greater than current capacity, capacity is increased to the required value.



int GetAlloc() const

Returns the current capacity of Array.



const K& GetKey(int iconst

Returns the key of element at i.



void Serialize(Stream& s)

Serializes the content of AMap to/from Stream.



void Xmlize(XmlIO& xio)

Serializes the content of AMap to/from XML.



void Jsonize(JsonIO& jio)

Serializes the content of AMap to/from JSON.



void Swap(FixedAMap& x)

Swaps this FixedAMap with another one.



const Vector<K>& GetKeys() const

Returns keys. Note that keys are sorted.



Vector<KPickKeys() pick_

Picks keys.



const V& GetValues() const

V& GetValues()

Returns values.



V PickValues() pick_

Picks values.



bool IsPicked() const

Returns true if map is picked.



FixedAMap& operator()(const K& k, const T& v)

Same as Add(k, v), returns *this. Convenience variant for creating maps.



FixedAMap(const FixedAMap& s, int)

Deep copy constructor.



FixedAMap(Vector<K>&& key, V&& val)

Constructor from containers (which are picked).



KeyConstIterator KeyBegin() const

KeyConstIterator KeyEnd() const

KeyConstIterator KeyGetIter(int posconst

Returns iterator to key at begin/end/pos.



Iterator Begin()

Iterator End()

Iterator GetIter(int pos)

ConstIterator Begin() const

ConstIterator End() const

ConstIterator GetIter(int posconst

Returns iterator to value at begin/end/pos.




template <class K, class T, class Less = StdLess<K> >

class FixedVectorMap : public MoveableAndDeepCopyOption<FixedVectorMap<K, T, Less> >, public FixedAMapK, T, Vector<T>, Less > 

Vector flavor of fixed map.




template <class K, class T, class Less = StdLess<K> >

class FixedArrayMap : public MoveableAndDeepCopyOptionFixedArrayMap<K, T, Less> >, public FixedAMapK, T, Array<T>, Less > 

Array flavor of fixed map.



Last edit by cxl on 02/11/2016. Do you want to contribute?. T++