IXMap

For various types of Key and Payload, xmap<Key,Payload> is implemented as a B+Tree in application libraries. An IXMap allows for accessing any xmap in a type invariant manner.

For example, PrintReflectedVariable makes use of the abstract iterator to iterate through each (Key,Payload) pair of ay given xmap.


$interface+ IXMap
{
    void Construct();
    InputArchive Search(InputArchive ar, const void*& payload) const;
    void* Insert(const void* key);
    InputArchive DeserialiseAndInsert(InputArchive ar, void*& payload);
    ssize_t size() const;
    ssize_t GetPayloadOffset() const;
    ptr<IBiDirIterator> GetIterator() const;
    ptr<IKeyType> GetKeyType() const;
};


void Construct()

A bit weird to think this as a method!


InputArchive Search(InputArchive ar, const void*& payload) const

Performs a look up on the xmap. Reads the key from the archive, and uses that key to index into the xmap. Sets 'payload' to the address of the payload or else nullptr if the key was not found


void* Insert(const void* key)

Must be called with an exclusive lock. Searches the map for the given key. If no entry is found then inserts an entry using a default constructed payload value. It is permissible to subsequently modify the payload in the same transaction without needing to mark any persistable objects as dirty - because the B+Tree leaf node containing the payload is marked as dirty by this function. Returns a pointer to the payload. Never returns nullptr.


InputArchive DeserialiseAndInsert(InputArchive ar, void*& payload)

Must be called with an exclusive lock Reads a key value from the given archive, then searches the map for that key. If no entry is found then inserts an entry using a default constructed payload value. It is permissible to subsequently modify the payload in the same transaction without needing to mark any persistable objects as dirty - because the B+Tree leaf node containing the payload is marked as dirty by this function. Returns a pointer to the payload. Never returns nullptr.


ssize_t size() const

Total number of elements in the map


ssize_t GetPayloadOffset() const

Get the offset to the payload from the pointer to the key in any given (Key,Payload) pair


ptr<IBiDirIterator> GetIterator() const

Retrieves an IBiDirIterator which is a bi-directional iterator that can be used to iterate through all (Key,Payload) pairs of the map. The returned iterator must be closed after it is no longer required.


ptr<IKeyType> GetKeyType() const

The IKeyType allows for serialisation/deserialisation of the keys of the xmap.