Пример #1
0
 private void SetupContentList()
 {
     _contentList   = _contents.Select(item => new ControlWithMetaData(item, this)).ToList();
     _indexComparer = new IndexComparer(_contents);
     if (_comparison == null)
     {
         _comparison = _indexComparer;
     }
     _contents.ListChanged += ContentsChanged;
 }
 protected void AssertEqual(
     IEnumerable <IIndex> expectedIndexes,
     IEnumerable <IIndex> actualIndexes,
     IndexComparer indexComparer = null)
 {
     indexComparer = indexComparer ?? new IndexComparer();
     Assert.Equal(
         new SortedSet <IIndex>(expectedIndexes, indexComparer),
         new SortedSet <IIndex>(actualIndexes, indexComparer),
         indexComparer);
 }
Пример #3
0
 protected void AssertEqual(
     IEnumerable <IIndex> expectedIndexes,
     IEnumerable <IIndex> actualIndexes,
     IndexComparer indexComparer = null)
 {
     indexComparer ??= new IndexComparer(compareAnnotations: false);
     Assert.Equal(
         new SortedSet <IIndex>(expectedIndexes, indexComparer),
         new SortedSet <IIndex>(actualIndexes, indexComparer),
         indexComparer);
 }
Пример #4
0
 private void SetupContentList()
 {
     _contentList = new List <ControlWithMetaData>();
     foreach (TType objLoopTType in _contents)
     {
         _contentList.Add(new ControlWithMetaData(objLoopTType, this));
     }
     _indexComparer = new IndexComparer(_contents);
     if (_comparison == null)
     {
         _comparison = _indexComparer;
     }
     _contents.ListChanged += ContentsChanged;
 }
        public RuleData Prune(int rulesLength)
        {
            var indexComparer = new IndexComparer();
            var output        = new RuleData();

            PruneAddParents(output.Terms, Terms.Last());
            output.Terms.Sort(indexComparer);
            for (var index = output.Terms.Count - 1; index >= 0; index--)
            {
                var term = output.Terms[index];
                PruneRenumber(output.Terms, term, rulesLength);
            }
            return(output);
        }
Пример #6
0
        private void LongOutput(IEnumerable <ItemInfo> items)
        {
            var attributeColumn = new OutputColumn();
            var nameColumn      = new OutputColumn();
            var sizeColumn      = new OutputColumn();
            var timeColumn      = new OutputColumn();
            var itemList        = new List <ItemInfo>();

            foreach (var item in items)
            {
                nameColumn.Add(item.Name);
                attributeColumn.Add(item.IsDir ? "d---------" : "----------");
                sizeColumn.Add((item.IsDir || !item.Size.HasValue) ? "---" : FormatSize(item.Size.Value));
                timeColumn.Add(item.LastWriteTime.Value.ToString("yyyy-MM-dd HH:mm"));
                itemList.Add(item);
            }

            var indexes  = Enumerable.Range(0, nameColumn.Count).ToList();
            var comparer = new IndexComparer(itemList);

            indexes.Sort(comparer);

            foreach (var id in indexes)
            {
                var sb = new StringBuilder();
                sb.Append(attributeColumn.Items[id]);
                sb.Append(_columnSep);

                if (sizeColumn.Items[id].Length < sizeColumn.MaxWidth)
                {
                    sb.Append(' ', sizeColumn.MaxWidth - sizeColumn.Items[id].Length);
                }
                sb.Append(sizeColumn.Items[id]);
                sb.Append(_columnSep);

                if (timeColumn.Items[id].Length < timeColumn.MaxWidth)
                {
                    sb.Append(' ', timeColumn.MaxWidth - timeColumn.Items[id].Length);
                }
                sb.Append(timeColumn.Items[id]);
                sb.Append(_columnSep);

                sb.Append(nameColumn.Items[id]);

                _config.ItemAction(sb.ToString(), itemList[id]);
                _config.EndOfLineAction();
            }
        }
Пример #7
0
 public BindingListDisplay(BindingList <TType> contents, Func <TType, Control> createFunc, bool loadVisibleOnly = true)
 {
     InitializeComponent();
     _contents        = contents ?? throw new ArgumentNullException(nameof(contents));
     _createFunc      = createFunc;
     _loadVisibleOnly = loadVisibleOnly;
     pnlDisplay.SuspendLayout();
     _contentList = new List <ControlWithMetaData>();
     foreach (TType objLoopTType in _contents)
     {
         _contentList.Add(new ControlWithMetaData(objLoopTType, this));
     }
     _indexComparer         = new IndexComparer(_contents);
     _comparison            = _comparison ?? _indexComparer;
     _contents.ListChanged += ContentsChanged;
     ComptuteDisplayIndex();
     LoadScreenContent();
     BindingListDisplay_SizeChanged(null, null);
     pnlDisplay.ResumeLayout();
 }
Пример #8
0
        public BindingListDisplay(BindingList <TType> contents, Func <TType, Control> funcCreateControl, bool blnLoadVisibleOnly = true)
        {
            InitializeComponent();
            Contents            = contents ?? throw new ArgumentNullException(nameof(contents));
            _funcCreateControl  = funcCreateControl;
            _blnLoadVisibleOnly = blnLoadVisibleOnly;
            DisplayPanel.SuspendLayout();
            try
            {
                int intMaxControlHeight = 0;
                foreach (TType objLoopTType in Contents)
                {
                    ControlWithMetaData objNewControl = new ControlWithMetaData(objLoopTType, this, false);
                    intMaxControlHeight = Math.Max(objNewControl.Control.PreferredSize.Height, intMaxControlHeight);
                    _lstContentList.Add(objNewControl);
                }

                if (intMaxControlHeight > 0)
                {
                    ListItemControlHeight = intMaxControlHeight;
                }

                DisplayPanel.Controls.AddRange(_lstContentList.Select(x => x.Control).ToArray());
                _indexComparer        = new IndexComparer(Contents);
                _comparison           = _comparison ?? _indexComparer;
                Contents.ListChanged += ContentsChanged;
                ComputeDisplayIndex();
                LoadScreenContent();
                BindingListDisplay_SizeChanged(null, null);
            }
            finally
            {
                _blnIsTopmostSuspendLayout = true;
                DisplayPanel.ResumeLayout();
            }
        }
Пример #9
0
        private void DefaultOutput(IEnumerable <ItemInfo> items)
        {
            var nameColumn = new OutputColumn();
            var itemList   = new List <ItemInfo>();

            foreach (var item in items)
            {
                nameColumn.Add(item.Name);
                itemList.Add(item);
            }

            if (nameColumn.Count == 0)
            {
                return;
            }

            var indexes  = Enumerable.Range(0, nameColumn.Count).ToList();
            var comparer = new IndexComparer(itemList, foldersFirst: false);

            indexes.Sort(comparer);

            // Figure out how many columns can fit the output
            var maxWidth   = Console.WindowWidth;
            var numColumns = Math.Min(15, nameColumn.Count);

            var columnWidths = new List <int>();

            var done = false;

            while (numColumns > 1)
            {
                columnWidths.Clear();

                // Compute the window with necessary to display the output in numColumns columns
                var numRows        = (nameColumn.Count + numColumns - 1) / numColumns;
                var numFullColumns = nameColumn.Count - (numRows - 1) * numColumns; // The number of items in the last row, in other words
                var itemId         = 0;
                for (var i = 0; i < numColumns; ++i)
                {
                    var thisColumnNum   = i < numFullColumns ? numRows : (numRows - 1);
                    var thisColumnWidth = 0;
                    for (var j = 0; j < thisColumnNum; ++j)
                    {
                        thisColumnWidth = Math.Max(thisColumnWidth, nameColumn.Items[indexes[itemId]].Length);
                        ++itemId;
                    }
                    columnWidths.Add(thisColumnWidth);
                }

                var width = columnWidths.Sum() + (columnWidths.Count - 1) * _columnSep.Length;
                if (width < maxWidth)
                {
                    var rowsData = new List <int> [numRows];
                    for (var i = 0; i < rowsData.Length; ++i)
                    {
                        rowsData[i] = new List <int>();
                    }
                    itemId = 0;
                    for (var i = 0; i < columnWidths.Count; ++i)
                    {
                        var thisColumnNum = i < numFullColumns ? numRows : (numRows - 1);
                        for (var j = 0; j < thisColumnNum; ++j)
                        {
                            rowsData[j].Add(indexes[itemId]);
                            ++itemId;
                        }
                    }

                    for (var i = 0; i < numRows; ++i)
                    {
                        for (var j = 0; j < rowsData[i].Count; ++j)
                        {
                            if (j > 0)
                            {
                                _config.ItemAction(_columnSep, null);
                            }
                            var str = nameColumn.Items[rowsData[i][j]];
                            _config.ItemAction(str, itemList[rowsData[i][j]]);
                            if (str.Length < columnWidths[j])
                            {
                                for (var k = 0; k < (columnWidths[j] - str.Length); ++k)
                                {
                                    _config.ItemAction(" ", null);
                                }
                            }
                        }
                        _config.EndOfLineAction();
                    }

                    done = true;
                    break;
                }

                --numColumns;
            }

            if (!done)
            {
                // Single column output
                for (var i = 0; i < nameColumn.Count; ++i)
                {
                    _config.ItemAction(nameColumn.Items[indexes[i]], itemList[indexes[i]]);
                    _config.EndOfLineAction();
                }
            }
        }
Пример #10
0
        public IIndex <int> Order(IEnumerable <int> rows)
        {
            var rowSet = rows.ToList();

            // The length of the set to order
            int rowSetLength = rowSet.Count;

            // Trivial cases where sorting is not required:
            // NOTE: We use readOnly objects to save some memory.
            if (rowSetLength == 0)
            {
                return(EmptyList);
            }
            if (rowSetLength == 1)
            {
                return(OneList);
            }

            // This will be 'row set' sorted by its entry lookup.  This must only
            // contain indices to rowSet entries.
            var newSet = new BlockIndex <int>();

            if (rowSetLength <= 250000)
            {
                // If the subset is less than or equal to 250,000 elements, we generate
                // an array in memory that contains all values in the set and we sort
                // it.  This requires use of memory from the heap but is faster than
                // the no heap use method.
                var subsetList = new List <DataObject>(rowSetLength);
                foreach (long row in rowSet)
                {
                    subsetList.Add(GetValue(row));
                }

                // The comparator we use to sort
                var comparer = new SubsetIndexComparer(subsetList.ToArray());

                // Fill new_set with the set { 0, 1, 2, .... , row_set_length }
                for (int i = 0; i < rowSetLength; ++i)
                {
                    var cell = subsetList[i];
                    newSet.InsertSort(cell, i, comparer);
                }
            }
            else
            {
                // This is the no additional heap use method to sorting the sub-set.

                // The comparator we use to sort
                var comparer = new IndexComparer(this, rowSet);

                // Fill new_set with the set { 0, 1, 2, .... , row_set_length }
                for (int i = 0; i < rowSetLength; ++i)
                {
                    var cell = GetValue(rowSet[i]);
                    newSet.InsertSort(cell, i, comparer);
                }
            }

            return(newSet);
        }