/// <summary> /// Creates and returns a sorted view of the source list, using the specified comparison object. /// </summary> /// <typeparam name="T">The type of items in the list.</typeparam> /// <param name="list">The list to be sorted. As long as the returned view is referenced, the source list should not be modified in any way.</param> /// <param name="comparer">The comparison object.</param> /// <param name="others">Other lists to be kept in sync with the sorted view. As the view is sorted, the same relative elements are rearranged in these lists.</param> /// <returns>The sorted view of the source list.</returns> public static ISortedList <T> SortIndirect <T>(this IList <T> list, IComparer <T> comparer, params ListExtensions.ISwappable[] others) { var indirect = new IndirectList <T>(list); indirect.Indices.Sort(indirect.GetComparer(comparer), others); return(indirect.AsSorted(comparer)); }
/// <summary> /// Creates and returns a view of the source list in which the elements are in a random order, using the specified random number generator delegate. /// </summary> /// <typeparam name="T">The type of elements in the source list.</typeparam> /// <param name="list">The source list. As long as the returned view is referenced, the size of the source list should not change.</param> /// <param name="randomNumberGenerator">The random number generator delegate; when invoked with a value <c>n</c>, this delegate must return a random number in the range [0, n).</param> /// <param name="others">Other lists to be kept in sync with the randomized view. As the view is randomized, the same relative elements are rearranged in these lists.</param> /// <returns>The randomized view of the source list.</returns> public static IList <T> RandomShuffleIndirect <T>(this IList <T> list, Func <int, int> randomNumberGenerator, params ISwappable[] others) { var indirect = new IndirectList <T>(list); indirect.Indices.RandomShuffle(randomNumberGenerator, others); return(indirect); }