Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/14 10:10:29 (10 years ago)
Author:
abeham
Message:

#2106: merged r10324, r10477, r10787 to stable

Location:
stable
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Common/3.3/ListExtensions.cs

    r10324 r10864  
    2626namespace HeuristicLab.Common {
    2727  public static class ListExtensions {
    28     public static void StableSort<T>(this List<T> values) {
    29       values.StableSort(0, values.Count);
     28
     29    public static void StableSort<T>(this List<T> values, Comparison<T> comparison) {
     30      values.StableSort(new StableSortComparer<T>(comparison));
    3031    }
    3132
    32     public static void StableSort<T>(this List<T> values, int index, int count) {
    33       var orderedList = values.Skip(index).Take(count).OrderBy(x => x).ToList();
    34       values.Clear();
    35       values.AddRange(orderedList);
    36     }
    37 
    38     public static void StableSort<T>(this List<T> values, IComparer<T> comparer) {
    39       values.StableSort(0, values.Count, comparer);
    40     }
    41 
    42     public static void StableSort<T>(this List<T> values, int index, int count, IComparer<T> comparer) {
    43       var orderedList = values.OrderBy(x => x, comparer).ToList();
    44       values.Clear();
    45       values.AddRange(orderedList);
    46     }
    47 
    48     public static void StableSort<T>(this List<T> values, Comparison<T> comparison) {
    49       values.StableSort(0, values.Count, comparison);
     33    public static void StableSort<T>(this List<T> values, IComparer<T> comparer = null) {
     34      int i = 0;
     35      foreach (var e in values.OrderBy(x => x, comparer ?? Comparer<T>.Default))
     36        values[i++] = e;
    5037    }
    5138
    5239    public static void StableSort<T>(this List<T> values, int index, int count, Comparison<T> comparison) {
    53       var orderedList = values.OrderBy(x => x, new StableSortComparer<T>(comparison)).ToList();
    54       values.Clear();
    55       values.AddRange(orderedList);
     40      values.StableSort(index, count, new StableSortComparer<T>(comparison));
    5641    }
    5742
    58     public class StableSortComparer<T> : IComparer<T> {
     43    public static void StableSort<T>(this List<T> values, int index, int count, IComparer<T> comparer = null) {
     44      if (index < 0) throw new ArgumentOutOfRangeException("index is less than zero.");
     45      if (count < 0) throw new ArgumentOutOfRangeException("count is less than zero.");
     46      if (index + count > values.Count) throw new ArgumentException("index and count do not specify a valid range in the List<T>.");
     47      var orderedList = values.Skip(index).Take(count).OrderBy(x => x, comparer ?? Comparer<T>.Default);
     48      int i = index;
     49      foreach (var e in orderedList)
     50        values[i++] = e;
     51    }
     52
     53    private class StableSortComparer<T> : IComparer<T> {
    5954      public StableSortComparer(Comparison<T> comparison) {
    6055        this.comparison = comparison;
Note: See TracChangeset for help on using the changeset viewer.