/// <summary> /// Remove the specified item from the belt. /// </summary> public void Remove(T item) { if (Empty) { return; } _remove.Add(item); _removeActive = true; }
/// <summary> /// Map the current set of items to the new rig of the defined type. /// Optionally a predicate determines whether the item is mapped. /// </summary> public ArrayRig <V> Map <V>(Func <T, V> mapper, Func <T, bool> predicate = null) { ArrayRig <V> mapped = new ArrayRig <V>(); if (predicate == null) { foreach (T item in this) { mapped.Add(mapper(item)); } } else { foreach (T item in this) { if (predicate(item)) { mapped.Add(mapper(item)); } } } return(mapped); }
public void Add(T _element) { elements.Add(_element); }
/// <summary> /// Gets indexes of the specified key. Returns an empty collection if /// the key isn't found. /// </summary> public ArrayRig <int> AllIndexesOf(IComparable <TKey> key) { // if no items - skip if (Count == 0) { return(new ArrayRig <int>(1)); } int max = Count; int min = 0; int next = min + (max - min >> 1); int median = -1; int compare; ArrayRig <int> collection = new ArrayRig <int>(); // while there are keys between the max and min while (median != next) { median = next; // compare the key at index with the target compare = key.CompareTo(Array[median].ArgA); // if the keys are equal if (compare == 0) { collection.Add(median); for (int i = median - 1; i >= 0; --i) { if (key.CompareTo(Array[i].ArgA) == 0) { collection.Add(i); } else { break; } } for (int i = median + 1; i < Count; ++i) { if (key.CompareTo(Array[i].ArgA) == 0) { collection.Add(i); } else { break; } } return(collection); } // is the key smaller than the current index? yes, move the max down if (compare < 0) { max = median + 1; } // no, move the min up else { min = median - 1; } // set the median of the max and min next = min + (max - min >> 1); } if (median > 0) { var average = _getAverage(Array[median].ArgA, Array[median - 1].ArgA); compare = key.CompareTo(average); if (compare < 0) { --median; } } if (key.CompareTo(Array[median].ArgA) != 0) { collection.Add(median); for (int i = median - 1; i >= 0; --i) { if (key.CompareTo(Array[i].ArgA) == 0) { collection.Add(i); } } for (int i = median + 1; i < Count; ++i) { if (key.CompareTo(Array[i].ArgA) == 0) { collection.Add(i); } } } // if the last median isn't the key, the key doesn't exist return(collection); }