Ignore:
Timestamp:
01/10/14 10:18:35 (6 years ago)
Author:
gkronber
Message:

#2106: changed methods for sorting in ObservableArray and ObservableList to use a stable sort (via Enumerable.OrderBy()). This is implemented as extension methods in HeuristicLab.Common. This implementation requires additional memory O(n).
The unit tests for tabu search had to be updated as the stable sort changes the results of the sample.
(minor bug fix in TestRandom)

Location:
trunk/sources/HeuristicLab.Collections/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Collections/3.3/HeuristicLab.Collections-3.3.csproj

    r9000 r10324  
    157157  </ItemGroup>
    158158  <ItemGroup>
     159    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
     160      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     161      <Name>HeuristicLab.Common-3.3</Name>
     162    </ProjectReference>
    159163    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
    160164      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableArray.cs

    r9456 r10324  
    2525using System.ComponentModel;
    2626using System.Linq;
     27using HeuristicLab.Common;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    168169        Array.Clear(array, index, length);
    169170        OnPropertyChanged("Item[]");
    170         OnItemsReplaced(GetIndexedItems(index, length), oldItems); 
     171        OnItemsReplaced(GetIndexedItems(index, length), oldItems);
    171172      }
    172173    }
     
    205206      if (array.Length > 1) {
    206207        IndexedItem<T>[] oldItems = GetIndexedItems();
    207         Array.Sort<T>(array);
     208        array.StableSort();
    208209        OnPropertyChanged("Item[]");
    209210        OnItemsMoved(GetIndexedItems(), oldItems);
     
    213214      if (array.Length > 1) {
    214215        IndexedItem<T>[] oldItems = GetIndexedItems();
    215         Array.Sort<T>(array, comparison);
     216        array.StableSort(comparison);
    216217        OnPropertyChanged("Item[]");
    217218        OnItemsMoved(GetIndexedItems(), oldItems);
     
    221222      if (array.Length > 1) {
    222223        IndexedItem<T>[] oldItems = GetIndexedItems();
    223         Array.Sort<T>(array, comparer);
     224        array.StableSort(comparer);
    224225        OnPropertyChanged("Item[]");
    225226        OnItemsMoved(GetIndexedItems(), oldItems);
     
    229230      if (length > 1) {
    230231        IndexedItem<T>[] oldItems = GetIndexedItems(index, length);
    231         Array.Sort<T>(array, index, length);
     232        array.StableSort(index, length);
    232233        OnPropertyChanged("Item[]");
    233234        OnItemsMoved(GetIndexedItems(index, length), oldItems);
     
    237238      if (length > 1) {
    238239        IndexedItem<T>[] oldItems = GetIndexedItems(index, length);
    239         Array.Sort<T>(array, index, length, comparer);
     240        array.StableSort(index, length, comparer);
    240241        OnPropertyChanged("Item[]");
    241242        OnItemsMoved(GetIndexedItems(index, length), oldItems);
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs

    r9456 r10324  
    2525using System.ComponentModel;
    2626using System.Linq;
     27using HeuristicLab.Common;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    320321      if (list.Count > 1) {
    321322        IndexedItem<T>[] oldItems = GetIndexedItems();
    322         list.Sort();
     323        list.StableSort();
    323324        OnItemsMoved(GetIndexedItems(), oldItems);
    324325        OnPropertyChanged("Item[]");
     
    328329      if (list.Count > 1) {
    329330        IndexedItem<T>[] oldItems = GetIndexedItems();
    330         list.Sort(comparison);
     331        list.StableSort(comparison);
    331332        OnItemsMoved(GetIndexedItems(), oldItems);
    332333        OnPropertyChanged("Item[]");
     
    336337      if (list.Count > 1) {
    337338        IndexedItem<T>[] oldItems = GetIndexedItems();
    338         list.Sort(comparer);
     339        list.StableSort(comparer);
    339340        OnItemsMoved(GetIndexedItems(), oldItems);
    340341        OnPropertyChanged("Item[]");
     
    344345      if (count > 1) {
    345346        IndexedItem<T>[] oldItems = GetIndexedItems(index, count);
    346         list.Sort(index, count, comparer);
     347        list.StableSort(index, count, comparer);
    347348        OnItemsMoved(GetIndexedItems(index, count), oldItems);
    348349        OnPropertyChanged("Item[]");
  • trunk/sources/HeuristicLab.Collections/3.3/Plugin.cs.frame

    r10037 r10324  
    2929  [PluginFile("HeuristicLab.Collections-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     31  [PluginDependency("HeuristicLab.Common", "3.3")]
    3132  public class HeuristicLabCollectionsPlugin : PluginBase {
    3233  }
Note: See TracChangeset for help on using the changeset viewer.