8 instantiations of Node
System.Collections.Immutable (8)
System\Collections\Immutable\ImmutableList_1.Node.cs (8)
22
internal static readonly Node EmptyNode = new
Node
();
278
return new
Node
(items[start + leftCount], left, right, true);
297
return new
Node
(items[leftCount], left, right, frozen: true);
1470
return new
Node
(_key, left, right);
1495
return new
Node
(_key, left, _right!);
1519
return new
Node
(_key, _left!, right);
1559
return new
Node
(key, _left!, _right!);
1590
private static Node CreateLeaf(T key) => new
Node
(key, left: EmptyNode, right: EmptyNode);
134 references to Node
System.Collections.Immutable (134)
System\Collections\Immutable\ImmutableDictionary_2.HashBucket.cs (4)
34
private readonly ImmutableList<KeyValuePair<TKey, TValue>>.
Node
_additionalElements;
41
private HashBucket(KeyValuePair<TKey, TValue> firstElement, ImmutableList<KeyValuePair<TKey, TValue>>.
Node
? additionalElements = null)
44
_additionalElements = additionalElements ?? ImmutableList<KeyValuePair<TKey, TValue>>.
Node
.EmptyNode;
77
internal ImmutableList<KeyValuePair<TKey, TValue>>.
Node
AdditionalElements
System\Collections\Immutable\ImmutableHashSet_1.HashBucket.cs (3)
49
private readonly ImmutableList<T>.
Node
_additionalElements;
56
private HashBucket(T firstElement, ImmutableList<T>.
Node
? additionalElements = null)
59
_additionalElements = additionalElements ?? ImmutableList<T>.
Node
.EmptyNode;
System\Collections\Immutable\ImmutableList_1.Builder.cs (5)
36
private
Node
_root =
Node
.EmptyNode;
97
internal
Node
Root
202
this.Root = ImmutableList<T>.
Node
.EmptyNode;
340
return ImmutableList<T>.WrapNode(
Node
.NodeTreeFromList(this, index, count));
System\Collections\Immutable\ImmutableList_1.cs (17)
29
private readonly
Node
_root;
34
internal ImmutableList() => _root =
Node
.EmptyNode;
40
private ImmutableList(
Node
root)
216
ImmutableList<T>.
Node
result = _root.Add(value);
233
ImmutableList<T>.
Node
result = _root.AddRange(items);
250
return new ImmutableList<T>(
Node
.NodeTreeFromList(items));
280
ImmutableList<T>.
Node
result = _root.InsertRange(index, items);
310
ImmutableList<T>.
Node
result = _root;
352
ImmutableList<T>.
Node
result = _root;
371
ImmutableList<T>.
Node
result = _root.RemoveAt(index);
566
return this.Wrap(
Node
.NodeTreeFromList(this, index, count));
1101
/// Returns the root <see cref="
Node
"/> of the list
1103
internal
Node
Root => _root;
1110
private static ImmutableList<T> WrapNode(
Node
root)
1161
private ImmutableList<T> Wrap(
Node
root)
1200
Node
root =
Node
.NodeTreeFromList(list, 0, list.Count);
System\Collections\Immutable\ImmutableList_1.Enumerator.cs (22)
62
private
Node
_root;
67
private SecurePooledObject<Stack<RefAsValueType<
Node
>>>? _stack;
72
private
Node
? _current;
87
internal Enumerator(
Node
root, Builder? builder = null, int startIndex = -1, int count = -1, bool reversed = false)
107
if (!SecureObjectPool<Stack<RefAsValueType<
Node
>>, Enumerator>.TryTake(this, out _stack))
109
_stack = SecureObjectPool<Stack<RefAsValueType<
Node
>>, Enumerator>.PrepNew(this, new Stack<RefAsValueType<
Node
>>(root.Height));
148
if (_stack != null && _stack.TryUse(ref this, out Stack<RefAsValueType<
Node
>>? stack))
151
SecureObjectPool<Stack<RefAsValueType<
Node
>>, Enumerator>.TryAdd(this, _stack!);
168
Stack<RefAsValueType<ImmutableList<T>.
Node
>> stack = _stack.Use(ref this);
171
Node
n = stack.Pop().Value;
202
Stack<RefAsValueType<ImmutableList<T>.
Node
>> stack = _stack.Use(ref this);
205
ImmutableList<T>.
Node
node = _root;
211
stack.Push(new RefAsValueType<
Node
>(node));
223
stack.Push(new RefAsValueType<
Node
>(node));
230
private
Node
? NextBranch(
Node
node) => _reversed ? node.Left : node.Right;
235
private
Node
? PreviousBranch(
Node
node) => _reversed ? node.Right : node.Left;
270
private void PushNext(
Node
node)
276
Stack<RefAsValueType<ImmutableList<T>.
Node
>> stack = _stack.Use(ref this);
279
stack.Push(new RefAsValueType<
Node
>(node));
System\Collections\Immutable\ImmutableList_1.Node.cs (83)
22
internal static readonly
Node
EmptyNode = new Node();
57
private
Node
? _left;
62
private
Node
? _right;
65
/// Initializes a new instance of the <see cref="ImmutableList{T}.
Node
"/> class
75
/// Initializes a new instance of the <see cref="ImmutableList{T}.
Node
"/> class
82
private Node(T key,
Node
left,
Node
right, bool frozen = false)
121
public
Node
? Left => _left;
131
public
Node
? Right => _right;
263
internal static
Node
NodeTreeFromList(IOrderedCollection<T> items, int start, int length)
276
Node
left = NodeTreeFromList(items, start, leftCount);
277
Node
right = NodeTreeFromList(items, start + leftCount + 1, rightCount);
286
internal static
Node
NodeTreeFromList(ReadOnlySpan<T> items)
295
Node
left = NodeTreeFromList(items.Slice(0, leftCount));
296
Node
right = NodeTreeFromList(items.Slice(leftCount + 1));
305
internal
Node
Add(T key)
312
Node
newRight = _right!.Add(key);
313
Node
result = this.MutateRight(newRight);
323
internal
Node
Insert(int index, T key)
334
Node
newLeft = _left.Insert(index, key);
335
Node
result = this.MutateLeft(newLeft);
340
Node
newRight = _right!.Insert(index - _left._count - 1, key);
341
Node
result = this.MutateRight(newRight);
351
internal
Node
AddRange(IEnumerable<T> keys)
360
Node
newRight = _right!.AddRange(keys);
361
Node
result = this.MutateRight(newRight);
370
internal
Node
AddRange(ReadOnlySpan<T> keys)
377
Node
newRight = _right!.AddRange(keys);
378
Node
result = this.MutateRight(newRight);
388
internal
Node
InsertRange(int index, IEnumerable<T> keys)
398
Node
result;
401
Node
newLeft = _left.InsertRange(index, keys);
406
Node
newRight = _right!.InsertRange(index - _left._count - 1, keys);
418
internal
Node
RemoveAt(int index)
423
Node
result;
445
ImmutableList<T>.
Node
successor = _right;
451
ImmutableList<T>.
Node
newRight = _right.RemoveAt(0);
457
ImmutableList<T>.
Node
newLeft = _left.RemoveAt(index);
462
ImmutableList<T>.
Node
newRight = _right.RemoveAt(index - _left._count - 1);
480
internal
Node
RemoveAll(Predicate<T> match)
484
ImmutableList<T>.
Node
result = this;
518
internal
Node
ReplaceAt(int index, T value)
523
Node
result;
531
ImmutableList<T>.
Node
newLeft = _left.ReplaceAt(index, value);
536
ImmutableList<T>.
Node
newRight = _right!.ReplaceAt(index - _left._count - 1, value);
547
internal
Node
Reverse() => this.Reverse(0, this.Count);
555
internal
Node
Reverse(int index, int count)
561
Node
result = this;
582
internal
Node
Sort() => this.Sort(Comparer<T>.Default);
592
internal
Node
Sort(Comparison<T> comparison)
612
internal
Node
Sort(IComparer<T>? comparer) => this.Sort(0, this.Count, comparer);
629
internal
Node
Sort(int index, int count, IComparer<T>? comparer)
955
internal ImmutableList<TOutput>.
Node
ConvertAll<TOutput>(Func<T, TOutput> converter)
957
ImmutableList<TOutput>.
Node
root = ImmutableList<TOutput>.
Node
.EmptyNode;
1297
private
Node
RotateLeft()
1309
private
Node
RotateRight()
1321
private
Node
DoubleLeft()
1328
Node
right = _right;
1329
Node
rightLeft = right._left;
1339
private
Node
DoubleRight()
1346
Node
left = _left;
1347
Node
leftRight = left._right;
1396
private
Node
Balance() => this.IsLeftHeavy ? this.BalanceLeft() : this.BalanceRight();
1402
private
Node
BalanceLeft()
1414
private
Node
BalanceRight()
1430
private
Node
BalanceMany()
1432
Node
tree = this;
1462
private
Node
MutateBoth(
Node
left,
Node
right)
1488
private
Node
MutateLeft(
Node
left)
1512
private
Node
MutateRight(
Node
right)
1537
private static byte ParentHeight(
Node
left,
Node
right) => checked((byte)(1 + Math.Max(left._height, right._height)));
1545
private static int ParentCount(
Node
left,
Node
right) => 1 + left._count + right._count;
1553
private
Node
MutateKey(T key)
1573
private static
Node
CreateRange(IEnumerable<T> keys)
1590
private static
Node
CreateLeaf(T key) => new Node(key, left: EmptyNode, right: EmptyNode);
1606
private static bool Contains(
Node
node, T value, IEqualityComparer<T> equalityComparer) => !node.IsEmpty && (equalityComparer.Equals(value, node._key) || Contains(node._left!, value, equalityComparer) || Contains(node._right!, value, equalityComparer));