I am confused about how to provide an API where I have several
implementations of a container type, with differing performance
To give the background, I am building an crate for manipulating an
Ontology, which is a set of
Axioms. There are about 30 different
Axiom all represented as a big enum. So far my
Ontology just uses a
BTreeSet to hold everything
That's fine so far, and has worked well for parsing data from one
format that I am working with; but for another format, the performance
is terrible, because I have to do a linear search of earlier part of
the set for new elements that I parse, so I get quadratic performance
(at least, I think it might be worse).
So, I need to have indexes somewhere to make the lookup constant
time. Straight-forward enough, I thought, but I cannot work out the
design. I would like to be able to add the indexes as I need them.
If I was doing this in Java, I might do something like create an
Ontology, then implement with a number of classes,
with different characteristics. Or, I could have a base
OntologyIndex which lets me search, and hook them
together with listeners.
None of this seems right for Rust. Any thoughts or general pointers
would be helpful.