private int ResolveInsertPosition(JobPriorityRecord newJob) { if (this.mSize == 0) return 0; int pos = this.mSize - 1; try { if (externalComparer == null) { while (pos > 0 && (Compare(newJob, mItems[pos]) < 0)) { pos--; } } else { while (pos > 0 && (externalComparer.Compare(newJob, mItems[pos]) < 0)) { pos--; } } } catch (IndexOutOfRangeException) { throw new ArgumentException("Bad IComparer result"); } catch (Exception exception1) { throw new InvalidOperationException("IComparer failed", exception1); } return pos; }
/// <sumary> /// This method pushes a new item onto the queue. /// </sumary> /// <param name="newJob">The job to be inserted in to the queue</param> /// <returns>The job position.</returns> public void Push(JobPriorityRecord newJob) { int position = ResolveInsertPosition(newJob); Insert(position, newJob); }
/// <sumary> /// This method pushes a new item onto the queue. /// </summary> /// <param name="jobID">The job id</param> /// <param name="priority">The job priority</param> /// <param name="jobTTL">The job Time To Live</param> /// <returns>The job position.</returns> public void Push(Guid jobID, JobPriority priority, TimeSpan jobTTL) { JobPriorityRecord newJob = new JobPriorityRecord(priority, jobID, jobTTL); Push(newJob); }
private int Compare(JobPriorityRecord x, JobPriorityRecord y) { return (int)x.Priority - (int)y.Priority; }
private void DeepSort(JobPriorityRecord[] mItems, int left, int right) { while (true) { int num1 = left; int num2 = right; JobPriorityRecord obj1 = mItems[(num1 + num2) >> 1]; do { try { if (externalComparer == null) { while (Compare(mItems[num1], obj1) < 0) { num1++; } while (Compare(obj1, mItems[num2]) < 0) { num2--; } } else { while (externalComparer.Compare(mItems[num1], obj1) < 0) { num1++; } while (externalComparer.Compare(obj1, mItems[num2]) < 0) { num2--; } } } catch (IndexOutOfRangeException) { throw new ArgumentException("Bad IComparer result"); } catch (Exception exception1) { throw new InvalidOperationException("IComparer failed", exception1); } if (num1 > num2) { break; } if (num1 < num2) { JobPriorityRecord obj2 = mItems[num1]; mItems[num1] = mItems[num2]; mItems[num2] = obj2; } num1++; num2--; } while (num1 <= num2); if ((num2 - left) <= (right - num1)) { if (left < num2) { DeepSort(mItems, left, num2); } left = num1; } else { if (num1 < right) { DeepSort(mItems, num1, right); } right = num2; } if (left >= right) { return; } } }
private void Insert(int index, JobPriorityRecord value) { if ((index < 0) || (index > mSize)) { throw new ArgumentOutOfRangeException("index", "Index is out of range."); } if (mSize == mItems.Length) { this.EnsureCapacity(mSize + 1); } if (index < mSize) { Array.Copy(mItems, index, mItems, (int)(index + 1), (int)(mSize - index)); } mItems[index] = value; mSize++; }