return true;
}
+ /**
+ * Sorts items by comparing with the specified compare function.
+ *
+ * WARNING: This method has only been added as hack and will not
+ * exist after the next odd minor version bump (>= 0.7.x).
+ *
+ * @param compare_func compare function to use to compare items
+ */
+ public void sort_with_data (CompareDataFunc compare) {
+ TimSort.sort_with_data<G> (this, compare);
+ }
+
private void shift (int start, int delta) {
assert (start >= 0);
assert (start <= _size);
}
}
- private static void sort_list<G> (List<G> list, CompareFunc compare) {
+ public static void sort_with_data<G> (List<G> list, CompareDataFunc compare_data) {
+ if (list is ArrayList) {
+ TimSort.sort_arraylist<G> ((ArrayList<G>) list, null, compare_data);
+ } else {
+ TimSort.sort_list<G> (list, null, compare_data);
+ }
+ }
+
+ private static void sort_list<G> (List<G> list, CompareFunc? compare, CompareDataFunc? compare_data = null) {
+ assert (compare != null || compare_data != null);
+
TimSort<G> helper = new TimSort<G> ();
helper.list_collection = list;
helper.index = 0;
helper.size = list.size;
helper.compare = compare;
+ helper.compare_data = compare_data;
helper.do_sort ();
}
}
- private static void sort_arraylist<G> (ArrayList<G> list, CompareFunc compare) {
+ private static void sort_arraylist<G> (ArrayList<G> list, CompareFunc? compare, CompareDataFunc? compare_data = null) {
+ assert (compare != null || compare_data != null);
+
TimSort<G> helper = new TimSort<G> ();
helper.list_collection = list;
helper.index = 0;
helper.size = list._size;
helper.compare = compare;
+ helper.compare_data = compare_data;
helper.do_sort ();
}
private Slice<G>*[] pending;
private int minimum_gallop;
private CompareFunc compare;
+ private CompareDataFunc compare_data;
private void do_sort () {
if (size < 2) {
private delegate bool LowerFunc (G left, G right);
private inline bool lower_than (G left, G right) {
- return compare (left, right) < 0;
+ if (compare != null) {
+ return compare (left, right) < 0;
+ } else {
+ return compare_data (left, right) < 0;
+ }
}
private inline bool lower_than_or_equal_to (G left, G right) {
- return compare (left, right) <= 0;
+ if (compare != null) {
+ return compare (left, right) <= 0;
+ } else {
+ return compare_data (left, right) <= 0;
+ }
}
private int compute_minimum_run_length (int length) {