Hi all,
I often have to get SBase objects via id or metaid from documents.
Currently, there exist the functions
doc.getElementBySId(sid)
doc.getElementByMetaId(metaid)
but they are both at least O(n) (or possibly worse functions) which iterate over all the model elements (over all children in the XML Tree).
I think it would be a great addition to libsbml if there could be O(1) functions to retrieve SBases.
These would require some internal hashMaps which can be calculated in O(n), all subsequential calls to get elements would than be in O(1).
I saw there are some related functions used in flattening, i.e.,
model.populateAllElementIdList()
model.populateAllElementMetaIdList()
model.isPopulatedAllElementIdList()
which create lists of ids and metaids for models. One could have
doc.populateAllElementIdMap()
doc.isPopulatedAllElementIdMap()
doc.getElementBySidMap(sid)
doc.populateAllElementMetaIdMap()
doc.isPopulatedAllElementMetaIdMap()
doc.getElementByMetaIdMap(sid)
I am sure many users are unaware that getElementBySId is O(n).
And at least me forget this again and again and only find out again when I profile my code why it is so slow (and most of the time the getElement functions are the culprit).
I am basically writing code to create HashMaps for lookup in python, but I am sure many users want to acces SBases via Id or metaId in a fast manner.
An example is for instance retrieving objects ports are pointing to in comp.
If there is some way to access SBases in O(1) in the current libsbml please let me know?
Best Matthias