A Qt based implementation of an ordered map.
An ordered map stores key-value pairs according to the insertion order of the keys. It supports a sub-set of the QMap API, as certain APIs like QMap::insertMulti()
etc do not make sense for an ordered map.
OrderedMap
stores keys according to their insertion order, so if you add a key that already exists, it's order is changed to being the last key in the map. Eg:
#include "orderedmap.h"
...
OrderedMap<int, int> om;
om.insert(1,1);
om.insert(2,2);
// Order of keys is [1, 2]
om.insert(1,1);
// Order of keys is [2, 1]
- The key type for the
OrderedMap
must provideoperator==()
and a global hash function calledqHash()
.
- OrderedMap currently does NOT support implicit sharing like other Qt containers. A deep-copy will be made whenever copying the container with either copy constructor or assignment operator.
OrderedMap
uses a hashtable (QHash
) for storing the data and a map (QLinkedList
) for storing the order of the keys.
Key Lookup | Insertion | Removal | ||||
---|---|---|---|---|---|---|
Average | Worst Case | Average | Worst Case | Average | Worst Case | |
OrderedMap | Amortized O(1) | O(n) | Amortized O(1) | O(n) | Amortized O(1) | O(n) |