35 if (comparison ==
null) {
36 throw new ArgumentNullException(nameof(comparison));
57 throw new InvalidOperationException(
"Capacity cannot be made smaller than number of elements.");
71 throw new InvalidOperationException(
"Count cannot be negative.");
77 public T
this[
int index] {
78 get => index >=
m_count ?
throw new IndexOutOfRangeException() :
m_array[index];
81 throw new IndexOutOfRangeException();
112 EqualityComparer<T> @
default = EqualityComparer<T>.Default;
113 for (
int i = 0; i <
m_count; i++) {
114 if (@
default.Equals(item,
m_array[i])) {
132 if (items is IReadOnlyList<T> items3) {
136 if (items is IList<T> items4) {
140 if (items is IReadOnlyCollection<T> items5) {
145 throw new ArgumentNullException(nameof(items));
150 public void AddRange(IReadOnlyCollection<T> items) {
155 if (items is IReadOnlyList<T> items3) {
159 if (items is IList<T> items4) {
164 throw new ArgumentNullException(nameof(items));
175 throw new ArgumentNullException(nameof(items));
186 throw new ArgumentNullException(nameof(items));
193 throw new ArgumentNullException(nameof(items));
216 throw new IndexOutOfRangeException();
225 throw new IndexOutOfRangeException();
229 ArgumentNullException.ThrowIfNull(match);
252 throw new IndexOutOfRangeException();
264 foreach (T t
in items) {
279 throw new IndexOutOfRangeException();
307 public void Sort(
int index,
int count) {
311 throw new ArgumentOutOfRangeException();
313 System.Array.Sort(
m_array, index, count);
320 throw new ArgumentOutOfRangeException();
327 IEnumerator<T> IEnumerable<T>.GetEnumerator() =>
new Enumerator(
this);
329 IEnumerator IEnumerable.GetEnumerator() =>
new Enumerator(
this);
332 EqualityComparer<T> @
default = EqualityComparer<T>.Default;
333 for (
int i = 0; i <
m_count; i++) {
334 if (@
default.Equals(item,
m_array[i])) {
341 public void CopyTo(T[] array,
int arrayIndex) {
345 protected virtual T[]
Allocate(
int capacity) =>
new T[capacity];
347 protected virtual void Free(T[] array) { }
381 foreach (T item
in items) {
388 foreach (T item
in items) {
396 for (
int i = 0; i < items.Count; i++) {
404 for (
int i = 0; i < items.Count; i++) {
void Insert(int index, T item)
void RemoveRange(IEnumerable< T > items)
void AddRangeTyped(IReadOnlyList< T > items)
Enumerator(DynamicArray< T > array)
void AddRangeTyped(IList< T > items)
DynamicArray(int capacity)
Comparer(Comparison< T > comparison)
void AddRangeTyped(DynamicArray< T > items)
void ReallocateNonZero(int capacity)
Comparison< T > Comparison
int RemoveAll(Predicate< T > match)
void CopyTo(T[] array, int arrayIndex)
void AddRange(IEnumerable< T > items)
void AddRange(IReadOnlyCollection< T > items)
void AddRange(IReadOnlyList< T > items)
void RemoveRange(int index, int count)
Enumerator GetEnumerator()
void AddRangeTyped(IReadOnlyCollection< T > items)
DynamicArray(IReadOnlyList< T > items)
void Sort(int index, int count)
virtual T[] Allocate(int capacity)
DynamicArray< T > m_array
void Sort(int index, int count, Comparison< T > comparison)
DynamicArray(IReadOnlyCollection< T > items)
void AddRangeTyped(IEnumerable< T > items)
void Sort(Comparison< T > comparison)
void AddRange(IList< T > items)
void AddRange(DynamicArray< T > items)
void Reallocate(int capacity)
DynamicArray(IEnumerable< T > items)
DynamicArray(DynamicArray< T > items)
void EnsureCapacityExact(int capacity)
void EnsureCapacityForOne()
virtual void Free(T[] array)
static int Max(int x1, int x2)