/// <summary> /// {@inheritDoc} /// /// <para>This implementation first gets a list iterator that points to the end /// of the list (with {@code listIterator(size())}). Then, it iterates /// backwards over the list until the specified element is found, or the /// beginning of the list is reached. /// /// </para> /// </summary> /// <exception cref="ClassCastException"> {@inheritDoc} </exception> /// <exception cref="NullPointerException"> {@inheritDoc} </exception> public virtual int LastIndexOf(Object o) { ListIterator <E> it = ListIterator(Size()); if (o == null) { while (it.HasPrevious()) { if (it.Previous() == null) { return(it.NextIndex()); } } } else { while (it.HasPrevious()) { if (o.Equals(it.Previous())) { return(it.NextIndex()); } } } return(-1); }
/// <summary>Merges items from buffer into the samples array in one pass.</summary> /// <remarks> /// Merges items from buffer into the samples array in one pass. /// This is more efficient than doing an insert on every item. /// </remarks> private void InsertBatch() { if (bufferCount == 0) { return; } Arrays.Sort(buffer, 0, bufferCount); // Base case: no samples int start = 0; if (samples.Count == 0) { SampleQuantiles.SampleItem newItem = new SampleQuantiles.SampleItem(buffer[0], 1, 0); samples.AddItem(newItem); start++; } ListIterator <SampleQuantiles.SampleItem> it = samples.ListIterator(); SampleQuantiles.SampleItem item = it.Next(); for (int i = start; i < bufferCount; i++) { long v = buffer[i]; while (it.NextIndex() < samples.Count && item.value < v) { item = it.Next(); } // If we found that bigger item, back up so we insert ourselves before it if (item.value > v) { it.Previous(); } // We use different indexes for the edge comparisons, because of the above // if statement that adjusts the iterator int delta; if (it.PreviousIndex() == 0 || it.NextIndex() == samples.Count) { delta = 0; } else { delta = ((int)Math.Floor(AllowableError(it.NextIndex()))) - 1; } SampleQuantiles.SampleItem newItem = new SampleQuantiles.SampleItem(v, 1, delta); it.Add(newItem); item = newItem; } bufferCount = 0; }