Given is a generic datatype whick looks like this: HashMap<EdgeTuple, Double> edgeList
where tuple is a class EdgeTuple and Double is a weight which is not important for the task:
class EdgeTuple{
int label1;
int label2;
public EdgeTuple(int label1, int label2){
int min = Math.min(label1, label2);
int max = Math.max(label1, label2);
this.label1 = min;
this.label2 = max;
}
}
So as you can see the tuples are already having the smaller value on first position. What I want to do is to sort the list which final entry order should look like this:
entry 0: [(0,something);some_weight]
entry 1: [(1,something);some_weight]
...
entry n-1: [(last_value,something);some_weight]
So basically what i need to do is to sort the tuples ascending on their first value. I have red the most liked existing answers on this topic but still could not find anything satisfying.
One possible solution is to lean on a comparator, something like this:
Comparator<Tuple> myComparator = new Comparator<Tuple>() {
public int compare(Tuple t1, Tuple t2) {
//the comparison rules go here
}
};
Collections.sort(tupleList, myComparator);
The comparison of each pair of tuples does not seem quiet efficient. So my question is, do You know any other ways to sort? Maybe some new datatypes which provide a suitable more performant interface for the given task?
Thanks