Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixill committed Jan 3, 2025
2 parents 300731e + 2e9b465 commit fd167a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public AVLTreeDictionary(IEnumerable<KeyValuePair<K, V>> elems, IComparer<K> com
public AVLTreeDictionary(IEnumerable<KeyValuePair<K, V>> elems, Comparison<K> comparer)
{
this.KeyComparer = comparer;
BackingSet = new AVLTreeSet<KeyValuePair<K, V>>((left, right) => KeyComparer(left.Key, right.Key));
BackingSet = new AVLTreeSet<KeyValuePair<K, V>>(elems, (left, right) => KeyComparer(left.Key, right.Key));
}
#endregion

Expand Down
12 changes: 12 additions & 0 deletions CSharp.Nixill/src/Utils/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ public static V GetOrSet<K, V>(this IDictionary<K, V> dictionary, K key, Func<V>
return returnValue;
}

/// <summary>
/// Returns an int enumerable over the indices of a collection (from
/// 0, inclusive, to the collection's size, exclusive).
/// </summary>
/// <typeparam name="T">
/// The type of elements in the collection.
/// </typeparam>
/// <param name="input">The collection.</param>
/// <returns>The enumerable.</returns>
public static IEnumerable<int> Indices<T>(this ICollection<T> input)
=> Enumerable.Range(0, input.Count);

/// <summary>
/// Removes the first item from an <see cref="IList{T}"/> and returns it.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions CSharp.Nixill/src/Utils/Extensions/SetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,23 @@ public static IEnumerable<TResult> Product<TLeft, TRight, TResult>(this IEnumera
public static IEnumerable<(TLeft, TRight)> Product<TLeft, TRight>(this IEnumerable<TLeft> left, IEnumerable<TRight> right) =>
left.Join(right, x => 1, y => 1, (left, right) => (left, right));

/// <summary>
/// For each element in a sequence, returns that element paired with
/// the remainder of the sequence after it.
/// </summary>
/// <typeparam name="T">
/// The type of elements in the sequence.
/// </typeparam>
/// <param name="input">The sequence.</param>
/// <returns>The elements and remainders.</returns>
public static IEnumerable<(T, IEnumerable<T>)> Remainders<T>(this IEnumerable<T> input)
{
T[] array = input.ToArray();

foreach (int index in array.Indices())
yield return (array[index], array[(index + 1)..]);
}

/// <summary>
/// Returns all elements in one sequence or the other, but not both.
/// </summary>
Expand Down

0 comments on commit fd167a2

Please sign in to comment.