Dear Rustaceans,
I am working on a statistical model M. M contains different sub-models: patterns P_i and distributions D_j. I am using patterns and distributions by combining them. For this post, let us assume that I use pairs of the form (P, D). In reality, the situation is slightly more complex, but this is the essence it boils down to.
I have to mutate my model many times. The mutations I do boil down to changing, adding, or removing patterns and distributions. Each mutation only affects a small portion of the model.
Because I have to mutate M so many times, I have implemented repositories for both patterns and for distributions. The repositories track the learned elements, and the elements are referenced via index structs of the form PatternReference(usize) or DistributionReference(usize). Let us call them ref P and ref D for short.
This means that my pairs are of the form (ref P, ref D). They are completely opaque and I e.g. cannot Display them in a meaningful way. I also have no safety regarding whether referenced elements actually exist. I do not like this. However, I don't know how to do this better. I would like to use references, but then I think I cannot mutate my model that easily any more – since every mutation only affects a small fraction of the patterns and distributions, having to drop and thus later re-instate all references seems like a terrible overhead to me.
Do any of you have any advice?
Thanks in advance!
TL;DR: I am not sure how to handle references to items that I feel should be mutable and thus I get a lot of dependencies between parts of my model that I feel shouldn't be that dependent on each other.