I'm looking for a data structure that has the following properties.
- Stores a list of
tuple<Double,Integer,Integer>. Order is only ondouble. Two tuples with the same double value are consider the same. - Supports duplicates.
- Needs to be able to traverse in ascending order. If there are duplicates, the one added later should have higher order.
- Find/Insert fast
- Remove fast, note that remove always follows this pattern
Method contains remove:
for(int i=list.size()-1;i>=0;i--){// assume list is in ascending order
if(list[j:i] can be merged){
remove list[j:i-1];
update list[i]'s two integers;
i = j-1;
}
}
I currently use ArrayList and keep it sorted. Finding is fast with binary search. However insertion and deletion will involve lots of copy in memory, e.g. insertion in the front of the list shifts all the elements.
jcoming from in the above?j<isuch thatlist[j:i]can be mergedjis in an outer loop (around the one shown) like this:for(int j = 0; j < list.size(); j++)? Also, bylist[j:i]are you using python-like syntax to indicate a range? When can they be merged? The overarching problem might lead me to suggest an alternative structure.