コード例 #1
0
 public static IEnumerable <T> GetReindexed <T>(this IIndexTranslator source, IReadOnlyList <T> beforeReindexing)
 {
     for (var dstIndex = 0; dstIndex < beforeReindexing.Count; ++dstIndex)
     {
         yield return(beforeReindexing[source.GetSrcIndex(dstIndex)]);
     }
 }
コード例 #2
0
        public static IEnumerable <KeyValuePair <int, int> > GetDestToSrcIndexPairs(this IIndexTranslator source)
        {
            var count = source.ItemsCount;

            for (var dstIndex = 0; dstIndex < count; dstIndex++)
            {
                yield return(new KeyValuePair <int, int>(source.GetSrcIndex(dstIndex), dstIndex));
            }
        }
コード例 #3
0
        /// <summary>Applies the reindexing specified by the given translator to the given list.</summary>
        /// <seealso cref="GetReindexed{T}"/>
        ///  <remarks>The complexity of this operation is O(N)</remarks>
        /// <typeparam name="T">The type of an item.</typeparam>
        /// <param name="source">The index translation source.</param>
        /// <param name="list">The list to adjust items order.</param>
        public static void ApplyReindexing <T>(this IIndexTranslator source, IList <T> list)
        {
            if (list.Count <= 0)
            {
                return;
            }

            var count       = source.ItemsCount;
            var marked      = new BitArray(list.Count);
            var markedCount = 0;

            for (var idx = 0; idx < count && markedCount < count; idx++)
            {
                var dstIndex = source.GetDestIndex(idx);

                if (dstIndex == idx || marked[dstIndex])
                {
                    // no index change or already copied
                    continue;
                }

                var srcValue = list[idx];

                while (!marked[dstIndex])
                {
                    ++markedCount;
                    marked[dstIndex] = true;

                    var tmp = list[dstIndex];
                    list[dstIndex] = srcValue;
                    srcValue       = tmp;

                    dstIndex = source.GetSrcIndex(dstIndex);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SymbolToIndexConverter{TSymbol}" /> class copying data from the other map corresponding to the items sequence before re-indexing.
        /// It maps the symbols to the new index sequence respecting the specified result of re-indexing operation.
        /// </summary>
        /// <param name="prev">The map before re-indexing.</param>
        /// <param name="reindexingResult">The re-indexing result.</param>
        public SymbolToIndexConverter(ISymbolToIndexReadOnlyConverter <TSymbol> prev, IIndexTranslator reindexingResult)
            : this(reindexingResult.ItemsCount, prev.Comparer)
        {
            var count = reindexingResult.ItemsCount;

            for (var dstIndex = 0; dstIndex < count; dstIndex++)
            {
                AddSymbol(prev.GetSymbolAt(reindexingResult.GetSrcIndex(dstIndex)));
            }
        }
コード例 #5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ReindexedVertexAdjacencyFactoryWrapper{TEdgeData}" /> class.
 /// </summary>
 /// <param name="translator">The index translator used to convert old vertices indexes to new ones.</param>
 /// <param name="wrapped">The wrapped factory.</param>
 public ReindexedVertexAdjacencyFactoryWrapper(IIndexTranslator translator, IVertexAdjacencyFactory <TEdgeData> wrapped)
 {
     _translator = translator;
     _wrapped    = wrapped;
 }
コード例 #6
0
 public static ReindexedDataResult <TData> ToReindexedDataResult <TData>(this IIndexTranslator source, TData sequence)
 {
     return(new ReindexedDataResult <TData>(source, sequence));
 }
コード例 #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SymbolToIndexConverter{TSymbol}" /> class copying data from the other map
        ///     corresponding to the items sequence before re-indexing.
        ///     It maps the symbols to the new index sequence respecting the specified result of re-indexing operation.
        /// </summary>
        /// <param name="prev">The map before re-indexing.</param>
        /// <param name="reindexingResult">The re-indexing result.</param>
        public SymbolToIndexReadOnlyConverter(ISymbolToIndexReadOnlyConverter <TSymbol> prev, IIndexTranslator reindexingResult)
        {
            var count = reindexingResult.ItemsCount;

            _symbolToIndexMap = new Dictionary <TSymbol, int>(count, prev.Comparer);
            _indexToSymbolMap = new TSymbol[count];

            for (var dstIndex = 0; dstIndex < count; dstIndex++)
            {
                var srcIndex = reindexingResult.GetSrcIndex(dstIndex);
                var symbol   = prev.GetSymbolAt(srcIndex);

                _symbolToIndexMap.Add(symbol, dstIndex);
                _indexToSymbolMap[dstIndex] = symbol;
            }
        }