-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make getElementBySId
and getElementByMetaId
O(1) lookups
#187
Comments
LibSBML already provides a way to return alternative structures. So if you'd rather have a hashmap, you could get one as follows:
I would be against changing the return type of the existing functions (ids might not be unique across all sbase objects / plugins) |
I like Frank's solution better than anything else, because libsbml documents can be edited, which could invalidate any internal hashmap any time any object is added or removed, and when setId or setMetaId is called. You also have to somehow deal with invalid SBML document objects where there are multiple objects with the same SId or MetaId. But if you do what Frank suggests, you have control of the SBML document object, and know when it's been edited. |
@fbergmann and @luciansmith Thanks for the feedback. This sounds like the solution I was looking for. Perhaps the documentation/doc strings of the functions Currently the python doc string only reads the following without indicating the O(n) runtime:
Alternatively a solution could be to provide two new helper functions getElementBySIdMap and getElementByMetaIdMap. These would use the lists generated by getAllElementIdList with the same limitations, i.e., a call to populateAllElementIdList would be necessary to update the hashmap. |
Hi all,
Two of the key functions to write algorithms and utilities based on libsbml are the
getElementBySId
andgetElementByMetaId
functions. This functions run in O(n) with n being the number of elements in the SBML model.Many people assume that this is a very fast lookup of O(1), which it should be. Consequently, many code and algorithm is substantially slowed down by this functions.
The correct/fast way is to create a HashMap in your algorithm from
getListOfAllElements
and then use the HashMap without ever touchinggetElementBySId
.There should be an internal HashMap which provides O(1) lookups by SId and MetaId. As far as I remember this is how JSBML is implementing this functions. Creating the HashMap costs O(n) which is as much as a single call got the
getElementBy*
functionsAs a consequence a lot of code using libsbml would see major speedups, probably even core algorithms such as comp flattening.
Best Matthias
The text was updated successfully, but these errors were encountered: