// as long as you don't access the by-numeral-index functions, // you can add and remove elements quickly. // upon accessing the list, it is updated once to fit the new data sclass ProbabilisticList extends AbstractRandomAccessList> { // these are the 2 main data structures we update Map probabilities = hashMap(); MultiSetMap byProbability = multiSetMap_outerDescTreeMap_innerLinkedHashSet(); L> renderedAsList; // this is only updated when requested public WithProbability get(int idx) { if (idx < 0 || idx >= size()) null; makeListUpToIndex(idx); ret renderedAsList.get(idx); } public int size() { ret l(probabilities); } void makeListUpToIndex(int idx) { if (idx < l(renderedAsList)) ret; if (nempty(renderedAsList)) { A last = last(renderedAsList); double probability = probabilites.get(last); Set<> = byProbability.get(probability) while ( <= idx) byProbability.get( } }