/// <summary> /// Initializes a new instance of priority queue with specified initial capacity and default priority comparer /// </summary> /// <param name="data">data to initialise the queue with</param> /// <param name="order">priority order of the queue (min or max)</param> public PriorityQueue(IEnumerable <T> data, PriorityOrder order) { _baseHeap = new List <T>(); _order = order; foreach (var d in data) { Enqueue(d); } }
private void Init(int initialCapacity, Comparison <TPriority> comparison, PriorityOrder priorityOrder) { _numItems = 0; _compareFunc = comparison; SetCapacity(initialCapacity); // multiplier to apply to result of compareFunc // 1 for high priority first, -1 for low priority first _prioritySign = (priorityOrder == PriorityOrder.HighFirst) ? 1 : -1; }
public PriorityQueue(PriorityOrder order = PriorityOrder.Ascending) { PriorityOrder = order; base.RaiseListChangedEvents = false; // We will raise these events manually when Enqueue and Dequeue are complete. #if DEBUG Diagnostics = Diagnostics.On; #else Diagnostics = Diagnostics.Off; #endif }
/// <summary> /// Initializes a new instance of the <see cref="PriorityQueue{T}"/> class. /// </summary> /// /// <param name="capacity">The initial capacity for the queue.</param> /// <param name="order">The sort order for the queue. If set to <see cref="PriorityOrder.Minimum"/>, /// items that have a smaller priority number are the next to be dequeued. If set to /// <see cref="PriorityOrder.Maximum"/>, items with larger priority numbers are the ones /// with higher priority and will be the next to be dequeued. Default is <see cref="PriorityOrder.Minimum"/>.</param> /// /// <exception cref="System.InvalidOperationException">New queue size cannot be smaller than 1.</exception> /// public PriorityQueue(int capacity = 10, PriorityOrder order = PriorityOrder.Minimum) { #if DEBUG if (capacity <= 0) { throw new InvalidOperationException("New queue size cannot be smaller than 1."); } #endif this.numberOfNodes = 0; this.nodes = new PriorityQueueNode <T> [capacity + 1]; this.counter = 0; this.order = order; }
public IndexPriorityQueue(Func <T, T, float> compare, PriorityOrder order) { this.order = order; this.compare = compare; indexs = new int[100]; qp = new int[100]; count = 0; this.size = 100; this.values = new T[100]; }
public IndexPriorityQueue(int size, Func <T, T, float> compare, PriorityOrder order) { this.order = order; indexs = new int[size]; values = new T[size]; qp = new int[size]; this.size = size; count = 0; this.compare = compare; }
public PQueue(T[] values, Func <T, T, float> compare, PriorityOrder order = PriorityOrder.MaxFirst) { this.values = new T[values.Length]; this.compare = compare; this.order = order; this.count = 0; size = this.count; for (int i = 0; i < values.Length; i++) { Enqueue(values[i]); } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (PriorityOrder != null) { hashCode = hashCode * 59 + PriorityOrder.GetHashCode(); } if (ReplyEmailPatterns != null) { hashCode = hashCode * 59 + ReplyEmailPatterns.GetHashCode(); } return(hashCode); } }
public PriorityQueue(IEnumerable <T> data, PriorityOrder order) { _data = data as IList <T>; if (_data == null) { _data = new List <T>(data); } _order = order; _heapSize = _data.Count; if (_order == PriorityOrder.Max) { Heap.BuildMaxHeap(_data); } else { Heap.BuildMinHeap(_data); } }
public PriorityQueue(IEnumerable <T> data, PriorityOrder order) { this.data = data as IList <T>; if (this.data == null) { this.data = new List <T>(data); } this.order = order; this.Count = this.data.Count; if (this.order == PriorityOrder.Max) { Heap.BuildMaxHeap(this.data); } else { Heap.BuildMinHeap(this.data); } }
public IndexPriorityQueue(T[] _values, Func <T, T, float> compare, PriorityOrder order) { this.size = _values.Length + 1; values = new T[size]; indexs = new int[size]; qp = new int[size]; this.order = order; this.compare = compare; count = 0; for (int i = 0; i < _values.Length; i++) { Enqueue(_values[i]); } }
/// <summary> /// Returns true if ComAdobeCqSocialCommonsEmailreplyImplMacmailEmailClientProviderProperties instances are equal /// </summary> /// <param name="other">Instance of ComAdobeCqSocialCommonsEmailreplyImplMacmailEmailClientProviderProperties to be compared</param> /// <returns>Boolean</returns> public bool Equals(ComAdobeCqSocialCommonsEmailreplyImplMacmailEmailClientProviderProperties other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( PriorityOrder == other.PriorityOrder || PriorityOrder != null && PriorityOrder.Equals(other.PriorityOrder) ) && ( ReplyEmailPatterns == other.ReplyEmailPatterns || ReplyEmailPatterns != null && ReplyEmailPatterns.Equals(other.ReplyEmailPatterns) )); }
public void MergeChanges_Should_Set_TrackingState_To_Unchanged_For_Added_Order_With_Null_Customer() { // Arrange var database = new MockNorthwind(); var origOrder = new PriorityOrder { PriorityPlan = "Silver", OrderDate = DateTime.Parse("1996-07-04"), CustomerId = "ALFKI" }; var changeTracker = new ChangeTrackingCollection <Order>(true) { origOrder }; var addedOrder = AddOrders(database, origOrder)[0]; // Act changeTracker.MergeChanges(addedOrder); // Assert Assert.Equal(addedOrder.CustomerId, origOrder.CustomerId); Assert.Equal(addedOrder.Customer.CustomerId, origOrder.Customer.CustomerId); Assert.Equal(addedOrder.OrderDate, origOrder.OrderDate); }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the given initial capacity, and uses the default comparer and /// has the given priority order. /// </summary> public PriorityQueue(int initialCapacity, PriorityOrder priorityOrder) : this(initialCapacity, Comparer <TPriority> .Default, priorityOrder) { }
public PriorityQueue(PriorityOrder priorityOrder = PriorityOrder.Ascending) { PriorityOrder = priorityOrder; Keys = new List <PriorityT>(); Values = new List <ItemT>(); }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the default initial capacity, and uses the given comparison and /// has the given priority order. /// </summary> public PriorityQueue(Comparison <TPriority> comparison, PriorityOrder priorityOrder) : this(_DEFAULT_CAPACITY, comparison, priorityOrder) { }
public PriorityQueue(PriorityOrder order) { _data = new List <T>(); _order = order; }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the default initial capacity, and uses the default comparer and /// is ordered as specified. /// <see cref="IComparer" />. /// </summary> /// <param name="priorityOrder"> /// The priority order. /// </param> public PriorityQueue(PriorityOrder priorityOrder) : this(_DEFAULT_CAPACITY, Comparer <TPriority> .Default, priorityOrder) { }
public PQueue(Func <T, T, float> compare, PriorityOrder order = PriorityOrder.MaxFirst) : this(100, compare) { this.order = order; }
public Heap(int n, PriorityOrder <T> P) { items = new List <T>(n); isGreaterThan = P; }
public PriorityQueue(int initialCapacity, PriorityOrder order) { this.data = new List <T>(initialCapacity); this.order = order; }
public PriorityQueue(PriorityOrder order) { this.data = new List <T>(); this.order = order; }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the default initial capacity, and uses the given comparison and /// has the given priority order. /// </summary> public PriorityQueue(Comparison <TPriority> comparison, PriorityOrder priorityOrder) : this(DefaultCapacity, comparison, priorityOrder) { }
public PQueue(int size, Func <T, T, float> compare, PriorityOrder order = PriorityOrder.MaxFirst) : this(size, compare) { this.order = order; }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the default initial capacity, and uses the given comparer and /// has the given priority order. /// </summary> public PriorityQueue(IComparer <TPriority> comparer, PriorityOrder priorityOrder) : this(DefaultCapacity, comparer, priorityOrder) { }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the default initial capacity, and uses the given comparer and /// has the given priority order. /// </summary> public PriorityQueue(IComparer <TPriority> comparer, PriorityOrder priorityOrder) : this(_DEFAULT_CAPACITY, comparer, priorityOrder) { }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the given initial capacity, and uses the given comparer and /// has the given priority order. /// </summary> public PriorityQueue(int initialCapacity, IComparer <TPriority> comparer, PriorityOrder priorityOrder) { Init(initialCapacity, comparer.Compare, priorityOrder); }
public SortedDict(PriorityOrder priorityOrder = PriorityOrder.Ascending) { PriorityOrder = priorityOrder; Keys = new List <keyT>(); Values = new List <valueT>(); }
/// <summary> /// Initializes a new instance of the PriorityQueue class that is empty, /// has the given initial capacity, and uses the given comparison and /// has the given priority order. /// </summary> public PriorityQueue(int initialCapacity, Comparison <TPriority> comparison, PriorityOrder priorityOrder) { Init(initialCapacity, comparison, priorityOrder); }
/// <summary> /// Initializes a new instance of priority queue with default initial capacity and default priority comparer /// </summary> public PriorityQueue(PriorityOrder order) { _baseHeap = new List <T>(); _order = order; }