8 instantiations of Node
System.Collections.Immutable (8)
System\Collections\Immutable\ImmutableList_1.Node.cs (8)
22
internal static readonly Node EmptyNode = new
Node
();
258
return new
Node
(items[start + leftCount], left, right, true);
277
return new
Node
(items[leftCount], left, right, frozen: true);
1450
return new
Node
(_key, left, right);
1475
return new
Node
(_key, left, _right!);
1499
return new
Node
(_key, _left!, right);
1539
return new
Node
(key, _left!, _right!);
1570
private static Node CreateLeaf(T key) => new
Node
(key, left: EmptyNode, right: EmptyNode);
132 references to Node
System.Collections.Immutable (132)
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
191
this.Root = ImmutableList<T>.
Node
.EmptyNode;
329
return ImmutableList<T>.WrapNode(
Node
.NodeTreeFromList(this, index, count));
System\Collections\Immutable\ImmutableList_1.cs (15)
29
private readonly
Node
_root;
34
internal ImmutableList() => _root =
Node
.EmptyNode;
40
private ImmutableList(
Node
root)
207
ImmutableList<T>.
Node
result = _root.Add(value);
224
ImmutableList<T>.
Node
result = _root.AddRange(items);
241
return new ImmutableList<T>(
Node
.NodeTreeFromList(items));
271
ImmutableList<T>.
Node
result = _root.InsertRange(index, items);
301
ImmutableList<T>.
Node
result = _root;
343
ImmutableList<T>.
Node
result = _root;
362
ImmutableList<T>.
Node
result = _root.RemoveAt(index);
557
return this.Wrap(
Node
.NodeTreeFromList(this, index, count));
1096
private static ImmutableList<T> WrapNode(
Node
root)
1147
private ImmutableList<T> Wrap(
Node
root)
1186
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;
126
public
Node
? Right => _right;
243
internal static
Node
NodeTreeFromList(IReadOnlyList<T> items, int start, int length)
256
Node
left = NodeTreeFromList(items, start, leftCount);
257
Node
right = NodeTreeFromList(items, start + leftCount + 1, rightCount);
266
internal static
Node
NodeTreeFromList(ReadOnlySpan<T> items)
275
Node
left = NodeTreeFromList(items.Slice(0, leftCount));
276
Node
right = NodeTreeFromList(items.Slice(leftCount + 1));
285
internal
Node
Add(T key)
292
Node
newRight = _right!.Add(key);
293
Node
result = this.MutateRight(newRight);
303
internal
Node
Insert(int index, T key)
314
Node
newLeft = _left.Insert(index, key);
315
Node
result = this.MutateLeft(newLeft);
320
Node
newRight = _right!.Insert(index - _left._count - 1, key);
321
Node
result = this.MutateRight(newRight);
331
internal
Node
AddRange(IEnumerable<T> keys)
340
Node
newRight = _right!.AddRange(keys);
341
Node
result = this.MutateRight(newRight);
350
internal
Node
AddRange(ReadOnlySpan<T> keys)
357
Node
newRight = _right!.AddRange(keys);
358
Node
result = this.MutateRight(newRight);
368
internal
Node
InsertRange(int index, IEnumerable<T> keys)
378
Node
result;
381
Node
newLeft = _left.InsertRange(index, keys);
386
Node
newRight = _right!.InsertRange(index - _left._count - 1, keys);
398
internal
Node
RemoveAt(int index)
403
Node
result;
425
ImmutableList<T>.
Node
successor = _right;
431
ImmutableList<T>.
Node
newRight = _right.RemoveAt(0);
437
ImmutableList<T>.
Node
newLeft = _left.RemoveAt(index);
442
ImmutableList<T>.
Node
newRight = _right.RemoveAt(index - _left._count - 1);
460
internal
Node
RemoveAll(Predicate<T> match)
464
ImmutableList<T>.
Node
result = this;
498
internal
Node
ReplaceAt(int index, T value)
503
Node
result;
511
ImmutableList<T>.
Node
newLeft = _left.ReplaceAt(index, value);
516
ImmutableList<T>.
Node
newRight = _right!.ReplaceAt(index - _left._count - 1, value);
527
internal
Node
Reverse() => this.Reverse(0, this.Count);
535
internal
Node
Reverse(int index, int count)
541
Node
result = this;
562
internal
Node
Sort() => this.Sort(Comparer<T>.Default);
572
internal
Node
Sort(Comparison<T> comparison)
592
internal
Node
Sort(IComparer<T>? comparer) => this.Sort(0, this.Count, comparer);
609
internal
Node
Sort(int index, int count, IComparer<T>? comparer)
935
internal ImmutableList<TOutput>.
Node
ConvertAll<TOutput>(Func<T, TOutput> converter)
937
ImmutableList<TOutput>.
Node
root = ImmutableList<TOutput>.
Node
.EmptyNode;
1277
private
Node
RotateLeft()
1289
private
Node
RotateRight()
1301
private
Node
DoubleLeft()
1308
Node
right = _right;
1309
Node
rightLeft = right._left;
1319
private
Node
DoubleRight()
1326
Node
left = _left;
1327
Node
leftRight = left._right;
1376
private
Node
Balance() => this.IsLeftHeavy ? this.BalanceLeft() : this.BalanceRight();
1382
private
Node
BalanceLeft()
1394
private
Node
BalanceRight()
1410
private
Node
BalanceMany()
1412
Node
tree = this;
1442
private
Node
MutateBoth(
Node
left,
Node
right)
1468
private
Node
MutateLeft(
Node
left)
1492
private
Node
MutateRight(
Node
right)
1517
private static byte ParentHeight(
Node
left,
Node
right) => checked((byte)(1 + Math.Max(left._height, right._height)));
1525
private static int ParentCount(
Node
left,
Node
right) => 1 + left._count + right._count;
1533
private
Node
MutateKey(T key)
1553
private static
Node
CreateRange(IEnumerable<T> keys)
1570
private static
Node
CreateLeaf(T key) => new Node(key, left: EmptyNode, right: EmptyNode);
1586
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));