/// <summary> /// Creates a set from elements of given collection that uses given comparer object. /// </summary> public Set(System.Collections.IComparer comparer, System.Collections.ICollection collection) : this(comparer) { foreach (object obj in collection) { Add(obj); } }
public TransientSortedMap(AtomicReference <Thread> edit, System.Collections.IComparer comp, RedBlackNode tree, int count) { this._edit = edit; this._comp = comp; this._tree = tree; this._count = count; }
/// <summary> Find an item in the tree. /// </summary> /// <param name="x">the item to search for.</param> /// <param name="comparer">The ICompararer used to compare when finding the given node.</param> /// <returns> the matching item or null if not found.</returns> public virtual IComparable Find(IComparable x, System.Collections.IComparer comparer) { // TODO: why is this line here? nullNode.element = x; current = header.right; for (; ;) { if (comparer.Compare(x, current.element) < 0) { current = current.left; } else if (comparer.Compare(x, current.element) > 0) { current = current.right; } else if (current != nullNode) { return(current.element); } else { return(null); } } }
/// <summary> /// The actual implementation /// </summary> /// <param name="primary"></param> /// <param name="left"></param> /// <param name="right"></param> /// <param name="compare"></param> protected void InternalSort( ref Array primary, int left, int right, System.Collections.IComparer compare) { if (secondary == null || secondary.Length != primary.Length) { secondary = (Array)primary.Clone(); } if (right > left) { int middle = (left + right) / 2; InternalSort(ref primary, left, middle, compare); InternalSort(ref primary, middle + 1, right, compare); int i, j, k; for (i = middle + 1; i > left; i--) { secondary.SetValue(primary.GetValue(i - 1), i - 1); } for (j = middle; j < right; j++) { secondary.SetValue(primary.GetValue(j + 1), right + middle - j); } for (k = left; k <= right; k++) { primary.SetValue( (compare.Compare(secondary.GetValue(i), secondary.GetValue(j)) < 0) ? secondary.GetValue(i++) : secondary.GetValue(j--), k); } } }
/// <summary> /// Compares the specified values using specified relational operator. /// </summary> /// <param name="leftValue">The first value.</param> /// <param name="rightValue">The second value.</param> /// <param name="relationalOperator">The relational operator.</param> /// <returns>Result of the given relational operator.</returns> private static bool Compare(object leftValue, object rightValue, ConditionRelationalOperator relationalOperator) { #if !NETSTANDARD1_0 System.Collections.IComparer comparer = StringComparer.InvariantCulture; #else System.Collections.IComparer comparer = StringComparer.Ordinal; #endif PromoteTypes(ref leftValue, ref rightValue); switch (relationalOperator) { case ConditionRelationalOperator.Equal: return(comparer.Compare(leftValue, rightValue) == 0); case ConditionRelationalOperator.NotEqual: return(comparer.Compare(leftValue, rightValue) != 0); case ConditionRelationalOperator.Greater: return(comparer.Compare(leftValue, rightValue) > 0); case ConditionRelationalOperator.GreaterOrEqual: return(comparer.Compare(leftValue, rightValue) >= 0); case ConditionRelationalOperator.LessOrEqual: return(comparer.Compare(leftValue, rightValue) <= 0); case ConditionRelationalOperator.Less: return(comparer.Compare(leftValue, rightValue) < 0); default: throw new NotSupportedException($"Relational operator {relationalOperator} is not supported."); } }
public override void Sort(System.Collections.IComparer comparer) { if (this.table != null && this.SupportsSorting) { this.table.Sort(comparer); } }
public MetaIndex(IReadOnlyList <PropertyInfo> indexProperties, bool isPrimaryIndex, bool isUnique, System.Collections.IComparer comparer) { IndexProperties = indexProperties; IsPrimaryIndex = isPrimaryIndex; IsUnique = isUnique; Comparer = comparer; }
/// <summary> /// Sorts an IList collections /// </summary> /// <param name="list">The System.Collections.IList instance that will be sorted</param> /// <param name="Comparator">The Comparator criteria, null to use natural comparator.</param> public static void Sort(System.Collections.IList list, System.Collections.IComparer Comparator) { if (((System.Collections.ArrayList)list).IsReadOnly) { throw new NotSupportedException(); } if ((Comparator == null) || (Comparator is System.Collections.Comparer)) { try { ((System.Collections.ArrayList)list).Sort(); } catch (InvalidOperationException e) { throw new InvalidCastException(e.Message); } } else { try { ((System.Collections.ArrayList)list).Sort(Comparator); } catch (InvalidOperationException e) { throw new InvalidCastException(e.Message); } } }
/// <summary> Create a Heap with the given initial capacity and comparator</summary> /// <exception cref="ArgumentException "> if capacity less or equal to zero /// /// </exception> public Heap(int capacity, System.Collections.IComparer cmp) { if (capacity <= 0) throw new System.ArgumentOutOfRangeException("capacity", capacity, "Only positive values"); nodes_ = new System.Object[capacity]; cmp_ = cmp; }
/// <summary> /// The actual implementation /// </summary> /// <param name="primary"></param> /// <param name="left"></param> /// <param name="right"></param> /// <param name="compare"></param> protected void InternalSort( ref System.Collections.ArrayList primary, int left, int right, System.Collections.IComparer compare) { if (secondaryList == null || secondaryList.Count != primary.Count) { secondaryList = (System.Collections.ArrayList)primary.Clone(); } if (right > left) { int middle = (left + right) / 2; InternalSort(ref primary, left, middle, compare); InternalSort(ref primary, middle + 1, right, compare); int i, j, k; for (i = middle + 1; i > left; i--) { secondaryList[i - 1] = primary[i - 1]; } for (j = middle; j < right; j++) { secondaryList[right + middle - j] = primary[j + 1]; } for (k = left; k <= right; k++) { primary[k] = (compare.Compare(secondaryList[i], secondaryList[j]) < 0) ? secondaryList[i++] : secondaryList[j--]; } } }
/// <summary> /// Sort an ArrayList using the specified comparer /// </summary> /// <param name="array">ArrayList to sort</param> /// <param name="compare">Comparer to used for sorting</param> public static void Sort(ref System.Collections.ArrayList array, System.Collections.IComparer compare) { using (MergeSort mergeSort = new MergeSort()) { mergeSort.InternalSort(ref array, 0, array.Count - 1, compare); } }
internal static RedBlackNode Remove(System.Collections.IComparer comp, RedBlackNode t, object key, Box found) { if (t is null) { return(null); } int c = comp.Compare(key, t.Key); if (c == 0) { found.Value = t; return(Append(t.Left, t.Right)); } var delete = c < 0 ? Remove(comp, t.Left, key, found) : Remove(comp, t.Right, key, found); if (delete is null && found.Value is null) { return(null); } if (c < 0) { return((t.Left is BlackNode) ? BalanceLeftDelete(t.Key, t.Value, delete, t.Right) : MakeRed(t.Key, t.Value, delete, t.Right)); } return((t.Right is BlackNode) ? BalanceRightDelete(t.Key, t.Value, t.Left, delete) : MakeRed(t.Key, t.Value, t.Left, delete)); }
// private modified binary search that facilitates Search of a key and if duplicates were found, // positions the current record pointer to the 1st key instance. private static int BinarySearch(System.Array array, int index, int length, object value, System.Collections.IComparer comparer) { int r; if (comparer != null && index != -1 && length != -1) { r = Array.BinarySearch(array, index, length, value, comparer); } #if !DEVICE else if (index != -1 && length != -1) { r = Array.BinarySearch(array, index, length, value); } #endif else { r = Array.BinarySearch(array, value); } if (r >= 0) { if (r >= 1) { int rr = BinarySearch(array, 0, r, value, comparer); if (rr >= 0) { return(rr); } } } return(r); }
public static void Sort(Array keys, Array items, System.Collections.IComparer comparer) { Contract.Requires(keys != null); // Contract.Requires(keys.Rank == 1); // Contract.Requires(items == null || items.Rank == 1); Contract.Requires(items == null || keys.GetLowerBound(0) == items.GetLowerBound(0)); }
public static void Sort(Array array, int index, int length, System.Collections.IComparer comparer) { Contract.Requires(array != null); // Contract.Requires(array.Rank == 1); Contract.Requires(index >= array.GetLowerBound(0)); Contract.Requires(length >= 0); Contract.Requires(array.GetLowerBound(0) + index + length <= array.Length); }
public ConcurrentBTreeAlgorithm(File.IFile file, System.Collections.IComparer comparer = null, string name = null, DataBlock.IDataBlockDriver dataBlockDriver = null, bool isDataInKeySegment = true) { Collection = new Algorithm.BTree.BTreeAlgorithm(file, comparer, name, dataBlockDriver, isDataInKeySegment); }
// Constructor. public ComparerWrapper(System.Collections.IComparer cmp) { if (cmp == null) { throw new ArgumentNullException("cmp"); } this.cmp = cmp; }
public IObjectSet Query(Predicate match, System.Collections.IComparer comparer) { if (null == match) { throw new ArgumentNullException("match"); } return(Query(null, match, new ComparerAdaptor(comparer))); }
public static int BinarySearch(Array array, object value, System.Collections.IComparer comparer) { Contract.Requires(array != null); // Contract.Requires(array.Rank == 1); Contract.Ensures(array.GetLowerBound(0) - 1 <= Contract.Result <int>()); Contract.Ensures(Contract.Result <int>() <= array.GetUpperBound(0)); return(default(int)); }
internal static RedBlackNode Replace(System.Collections.IComparer comp, RedBlackNode t, object key, object val) { int c = comp.Compare(key, t.Key); return(t.Replace(t.Key, c == 0 ? val : t.Value, c < 0 ? Replace(comp, t.Left, key, val) : t.Left, c > 0 ? Replace(comp, t.Right, key, val) : t.Right)); }
/// <summary> /// Sort the current column /// </summary> /// <param name="e"></param> /// <param name="p_bAscending"></param> /// <param name="p_Comparer"></param> public void SortColumn(PositionEventArgs e, bool p_bAscending, System.Collections.IComparer p_Comparer) { //verifico che il sort sia abilitato e che ci sia almeno una riga da ordinare oltra a quella corrente if (IsSortEnable(e) && e.Position.Row < (e.Grid.RowsCount) && e.Grid.ColumnsCount > 0) { Range l_RangeToSort; Range l_RangeHeader; if (m_RangeToSort != null) { l_RangeToSort = m_RangeToSort.GetRange(e.Grid); } else { //the range to sort is all the grid range without the rows < of the current row l_RangeToSort = new Range(e.Position.Row + 1, 0, e.Grid.RowsCount - 1, e.Grid.ColumnsCount - 1); } if (m_HeaderRange != null) { l_RangeHeader = m_HeaderRange.GetRange(e.Grid); } else { //the range header is all the grid range with the rows <= of the current row l_RangeHeader = new Range(0, 0, e.Position.Row, e.Grid.ColumnsCount - 1); } ICellSortableHeader l_CellSortable = (ICellSortableHeader)e.Cell; if (e.Grid.RowsCount > (e.Position.Row + 1) && e.Grid.ColumnsCount > e.Grid.FixedColumns) { e.Grid.SortRangeRows(l_RangeToSort, e.Position.Column, p_bAscending, p_Comparer); if (p_bAscending) { l_CellSortable.SetSortMode(e.Position, GridSortMode.Ascending); } else { l_CellSortable.SetSortMode(e.Position, GridSortMode.Descending); } //Remove the image from others ColHeaderSort for (int r = l_RangeHeader.Start.Row; r <= l_RangeHeader.End.Row; r++) { for (int c = l_RangeHeader.Start.Column; c <= l_RangeHeader.End.Column; c++) { Cells.ICellVirtual l_tmp = e.Grid.GetCell(r, c); if (l_tmp != l_CellSortable && l_tmp != null && l_tmp is ICellSortableHeader) { ((ICellSortableHeader)l_tmp).SetSortMode(new Position(r, c), GridSortMode.None); } } } } } }
/// <summary> Create a Heap with the given initial capacity and comparator</summary> /// <exception cref="ArgumentException "> if capacity less or equal to zero /// /// </exception> public Heap(int capacity, System.Collections.IComparer cmp) { if (capacity <= 0) { throw new System.ArgumentOutOfRangeException("capacity", capacity, "Only positive values"); } nodes_ = new System.Object[capacity]; cmp_ = cmp; }
public CSVDumper(IResourceTracker irt, System.Collections.IComparer comparer) { m_comparer = comparer; m_arer = new System.Collections.ArrayList(); foreach (ResourceEventRecord rer in irt) { m_arer.Add(rer); } }
public FormDataFinder() { InitializeComponent(); // Create a sorter. textComparer = new MixedListSorter(); // Set minimum size of window. this.MinimumSize = this.Size; }
public bool Equals(object other, System.Collections.IComparer comparer) { if (comparer.Compare(other, this) == 0) { return(true); } else { return(false); } }
public static SortedSet Create(System.Collections.IComparer comp, System.Collections.IEnumerable init) { ICollection ret = new SortedSet(new SortedMap(comp)); foreach (var item in init) { ret = ret.Cons(item); } return(ret as SortedSet); }
public static ValidateTarget <TValue> NotInRange <TValue>([ValidatedNotNull] this ValidateTarget <TValue> target, object minValue, object maxValue, Func <string> getErrorMessage = null, System.Collections.IComparer customComparer = null) where TValue : IComparable { System.Collections.IComparer comparer = customComparer ?? Comparer <TValue> .Default; if (comparer.Compare(target.Value, minValue) >= 0 && comparer.Compare(target.Value, maxValue) <= 0) { ExceptionFactory.ThrowException(target.Traits.OutOfRangeExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldNotBeInRange(target, minValue, maxValue)); } return(target); }
public static void Sort(Array keys, Array items, int index, int length, System.Collections.IComparer comparer) { Contract.Requires(keys != null); // Contract.Requires(keys.Rank == 1); // Contract.Requires(items == null || items.Rank == 1); Contract.Requires(items == null || keys.GetLowerBound(0) == items.GetLowerBound(0)); Contract.Requires(index >= keys.GetLowerBound(0)); Contract.Requires(length >= 0); Contract.Requires(keys.GetLowerBound(0) + index + length <= keys.Length); Contract.Requires(items == null || index + length <= items.Length); }
static int BinarySearch(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(System.Array), typeof(object))) { System.Array arg0 = (System.Array)ToLua.ToObject(L, 1); object arg1 = ToLua.ToVarObject(L, 2); int o = System.Array.BinarySearch(arg0, arg1); LuaDLL.lua_pushinteger(L, o); return(1); } else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(System.Array), typeof(object), typeof(System.Collections.IComparer))) { System.Array arg0 = (System.Array)ToLua.ToObject(L, 1); object arg1 = ToLua.ToVarObject(L, 2); System.Collections.IComparer arg2 = (System.Collections.IComparer)ToLua.ToObject(L, 3); int o = System.Array.BinarySearch(arg0, arg1, arg2); LuaDLL.lua_pushinteger(L, o); return(1); } else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(System.Array), typeof(int), typeof(int), typeof(object))) { System.Array arg0 = (System.Array)ToLua.ToObject(L, 1); int arg1 = (int)LuaDLL.lua_tonumber(L, 2); int arg2 = (int)LuaDLL.lua_tonumber(L, 3); object arg3 = ToLua.ToVarObject(L, 4); int o = System.Array.BinarySearch(arg0, arg1, arg2, arg3); LuaDLL.lua_pushinteger(L, o); return(1); } else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(System.Array), typeof(int), typeof(int), typeof(object), typeof(System.Collections.IComparer))) { System.Array arg0 = (System.Array)ToLua.ToObject(L, 1); int arg1 = (int)LuaDLL.lua_tonumber(L, 2); int arg2 = (int)LuaDLL.lua_tonumber(L, 3); object arg3 = ToLua.ToVarObject(L, 4); System.Collections.IComparer arg4 = (System.Collections.IComparer)ToLua.ToObject(L, 5); int o = System.Array.BinarySearch(arg0, arg1, arg2, arg3, arg4); LuaDLL.lua_pushinteger(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: System.Array.BinarySearch")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public static Type ComparedType(System.Collections.IComparer comparer) { var genericComparerInterface = comparer.GetType().GetInterfaces().FirstOrDefault( x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IComparer <>)); if (genericComparerInterface == null) { throw new InvalidOperationException($"Unable to determine comparer type for {comparer.GetType().Name}"); } return(genericComparerInterface.GenericTypeArguments[0]); }
public static ValidateTarget <TValue> IsGreaterOrEqualThan <TValue>([ValidatedNotNull] this ValidateTarget <TValue> target, object valueToCompare, Func <string> getErrorMessage = null, System.Collections.IComparer customComparer = null) where TValue : IComparable { System.Collections.IComparer comparer = customComparer ?? Comparer <TValue> .Default; if (comparer.Compare(target.Value, valueToCompare) < 0) { ExceptionFactory.ThrowException(target.Traits.OutOfRangeExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldBeGreaterOrEqualThan(target, valueToCompare)); } return(target); }
/// <summary>Creates <code>MimeHeaders</code> using the default content type /// <code>DEFAULT_CONTENT_TYPE</code> and default content transfre encoding /// <code>DEFAULT_CONTENT_TRANSFER_ENCODING</code>.</summary> public MimeHeaders() { lenHeaders = HEADER_SUFFIX.Length; comparer = System.Collections.CaseInsensitiveComparer.DefaultInvariant; // most messages will have around 2 headers... no need to waste // time and memory on a Hashtable mimeHeadersTable = new System.Collections.Specialized.ListDictionary(comparer); //mimeHeadersTable = new System.Collections.Hashtable(DEFAULT_HEADER_TABLE_SIZE, // System.Collections.CaseInsensitiveHashCodeProvider.DefaultInvariant, // comparer); }
public ComparerAdaptor(System.Collections.IComparer comparer) { _comparer = comparer; }
/// <summary> /// Initializes a new instance of the <see cref="SortStatus"/> class. /// </summary> /// <param name="p_Mode">Status of current sort.</param> /// <param name="p_EnableSort">True to enable sort otherwise false</param> /// <param name="p_Comparer">Comparer used to sort the column. The comparer will take 2 Cell. /// If null the default ValueCellComparer is used.</param> public SortStatus(GridSortMode p_Mode, bool p_EnableSort, System.Collections.IComparer p_Comparer) : this(p_Mode, p_EnableSort) { comparer = p_Comparer; }
/// <summary> /// Initializes a new instance of the <see cref="SortStatus"/> class. /// </summary> /// <param name="p_Mode">Status of current sort.</param> /// <param name="p_EnableSort">True to enable sort otherwise false</param> public SortStatus(GridSortMode p_Mode, bool p_EnableSort) { mode = p_Mode; enableSort = p_EnableSort; comparer = null; }
private void InitBlock() { spanDocComparator = new AnonymousClassComparator(this); }
static TestStressIndexing2() { fieldNameComparator = new AnonymousClassComparator(); }
protected void OnCmbSortChanged(object sender, System.EventArgs e) { if (!disableSettingsEvents) { // sort the list if (chkSort.Active) { // choose the sorting order switch (cmbSort.Active) { case 1: // Coordinate sort sorter = new MapPoint.ComparerCoord (); break; case 2: // Distance sort sorter = new MapPoint.ComparerDist (); break; default: // Alphabetic sort if (cmbSort.Active != 0) { cmbSort.Active = 0; } sorter = new MapPoint.ComparerAlpha (); break; } } // save settings writeSettings (); // sort the list, if filter is running if (enabled) { sortNeeded = true; // force the filter of the logs (arguments probably have the wrong values, but they aren't used by the code) this.OnTimedEvent (sender, null); } } }
/// <summary> /// Constructor /// </summary> /// <param name="p_Style">Status of current sort.</param> public SortStatus(DevAge.Drawing.HeaderSortStyle p_Style) { Style = p_Style; Comparer = null; }
/// <summary> /// Constructor /// </summary> /// <param name="p_Style">Status of current sort.</param> /// <param name="p_Comparer">Comparer used to sort the column. The comparer will take 2 Cell. If null the default ValueCellComparer is used.</param> public SortStatus(DevAge.Drawing.HeaderSortStyle p_Style, System.Collections.IComparer p_Comparer) : this(p_Style) { Comparer = p_Comparer; }
/// <summary> /// Creates an instance of SetBase. /// </summary> /// <param name="comparer">Comparer that specifies sort order of the elements.</param> /// <param name="allowDuplicates">Whether multiple duplicate (equivalent) elements are allowed.</param> public SetBase(System.Collections.IComparer comparer, bool allowDuplicates) { _comparer = comparer; _allowDuplicates = allowDuplicates; _tree = new RbTree(_comparer); }
/// <summary> /// Specifies the IList and Comparer /// </summary> /// <param name="array">The array to sort.</param> /// <param name="comparer">The comparer to use.</param> public ChannelSorter(System.Collections.IList array, System.Collections.IComparer comparer) { this.comparer = comparer; Sort(array, 0, array.Count - 1); }
public TreeSetSupport(System.Collections.IComparer c) : base() { this.comparator = c; }