Skip to content

Commit 3612048

Browse files
author
Oren (electricessence)
committed
API Cleanup
1 parent 4d7c068 commit 3612048

4 files changed

Lines changed: 21 additions & 22 deletions

File tree

Node.Clone.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed partial class Node<T>
1717
/// <param name="onNodeCloned">A function that recieves the old node and its clone.</param>
1818
/// <returns>The copy of the tree/branch.</returns>
1919
public Node<T> Clone(
20-
Node<T> newParentForClone,
20+
Node<T> newParentForClone = null,
2121
Action<Node<T>, Node<T>> onNodeCloned = null)
2222
{
2323
if (newParentForClone != null && newParentForClone._factory != _factory)
@@ -33,7 +33,7 @@ public Node<T> Clone(
3333
foreach (var child in _children)
3434
clone.Add(child.Clone(clone, onNodeCloned));
3535

36-
clone.UnMapped = UnMapped;
36+
clone.Unmapped = Unmapped;
3737

3838
onNodeCloned?.Invoke(this, clone);
3939

@@ -54,12 +54,13 @@ public Node<T> Clone(
5454
/// Create's a clone of the entire tree but only returns the clone of this node.
5555
/// </summary>
5656
/// <returns>A clone of this node as part of a newly cloned tree.</returns>
57-
public Node<T> CloneTree(Node<T> target)
57+
public Node<T> CloneTree()
5858
{
5959
Node<T> node = null;
60-
target.Root.Clone((n, clone) =>
60+
Root.Clone((original, clone) =>
6161
{
62-
if (n == target) node = clone;
62+
if (original == this)
63+
node = clone;
6364
});
6465
return node;
6566
}

Node.Factory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Node<T> Map<TRoot>(TRoot root)
9292

9393
// Mapping is deferred and occurs on demand.
9494
// If values or children change in the node, mapping is disregarded.
95-
current.UnMapped = true;
95+
current.Unmapped = true;
9696

9797

9898
return current;

Node.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public T Value
3838
set
3939
{
4040
AssertNotRecycled();
41-
UnMapped = false;
41+
Unmapped = false;
4242
_value = value;
4343
}
4444
}
@@ -50,23 +50,23 @@ public T Value
5050
/// Will be false if not created by calling Factory.Map or if the value has been mapped.
5151
/// Since querying the chidren of this node will cause the value to be mapped, it can be useful to query this value before attempting traversal.
5252
/// </summary>
53-
public bool UnMapped { get; private set; }
53+
public bool Unmapped { get; private set; }
5454

5555
IReadOnlyList<Node<T>> EnsureChildrenMapped()
5656
{
57-
if (!UnMapped)
57+
if (!Unmapped)
5858
return _childrenReadOnly;
5959

6060
// Need to avoid double mapping and this method is primarily called when 'reading' from the node and contention will only occur if mapping is needed.
6161
lock (_children)
6262
{
63-
if (!UnMapped) return _childrenReadOnly;
63+
if (!Unmapped) return _childrenReadOnly;
6464
if (_value is IParent<T> p)
6565
{
6666
foreach (var child in p.Children)
6767
_children.Add(_factory.Map(child));
6868
}
69-
UnMapped = false;
69+
Unmapped = false;
7070
}
7171

7272
return _childrenReadOnly;
@@ -103,7 +103,7 @@ public bool Remove(Node<T> node)
103103
if (!_children.Remove(node)) return false;
104104

105105
AssertNotRecycled();
106-
UnMapped = false;
106+
Unmapped = false;
107107
node.Parent = null; // Need to be very careful about retaining parent references as it may cause a 'leak' per-se.
108108
return true;
109109
}
@@ -133,7 +133,7 @@ public void Clear()
133133
if (_children.Count == 0) return;
134134

135135
AssertNotRecycled();
136-
UnMapped = false;
136+
Unmapped = false;
137137
foreach (var c in _children)
138138
c.Parent = null;
139139
_children.Clear();
@@ -177,7 +177,7 @@ public void Replace(Node<T> node, Node<T> replacement)
177177
throw new InvalidOperationException("Node being replaced does not belong to this parent.");
178178

179179
AssertNotRecycled();
180-
UnMapped = false;
180+
Unmapped = false;
181181
_children[i] = replacement;
182182
node.Parent = null;
183183
replacement.Parent = this;
@@ -215,7 +215,7 @@ public Node<T> Root
215215
/// </summary>
216216
public void Teardown()
217217
{
218-
UnMapped = false;
218+
Unmapped = false;
219219
Value = default;
220220
Detatch(); // If no parent then this does nothing...
221221
TeardownChildren();
@@ -229,7 +229,7 @@ public void TeardownChildren()
229229
if (_children.Count == 0) return;
230230

231231
AssertNotRecycled();
232-
UnMapped = false;
232+
Unmapped = false;
233233
foreach (var c in _children)
234234
{
235235
c.Parent = null; // Don't initiate a 'Detach' (which does a lookup) since we are clearing here;
@@ -245,7 +245,7 @@ public void TeardownChildren()
245245
public T Recycle()
246246
{
247247
AssertNotRecycled(); // Avoid double entry in the pool.
248-
UnMapped = false;
248+
Unmapped = false;
249249
var value = Value;
250250
Value = default;
251251
Detatch(); // If no parent then this does nothing...
@@ -260,7 +260,7 @@ public void RecycleChildren()
260260
{
261261
if (_children.Count == 0) return;
262262

263-
UnMapped = false;
263+
Unmapped = false;
264264
foreach (var c in _children)
265265
{
266266
c.Parent = null; // Don't initiate a 'Detach' (which does a lookup) since we are clearing here;

Open.Hierarchy.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ Part of the "Open" set of libraries.</Description>
1414
<RepositoryUrl>https://github.com/electricessence/Open.Hierarchy/</RepositoryUrl>
1515
<RepositoryType>git</RepositoryType>
1616
<PackageTags>dotnet, dotnetcore, cs, tree, node, hierarchy, parent, child, root</PackageTags>
17-
<Version>1.4.1</Version>
18-
<PackageReleaseNotes>Deferred unidirectional to bidirectional tree mapping.
19-
Improved assertions and added recycled node validation.
20-
Simplified factory and recycling usage: nodes now have a referene to their source factory.</PackageReleaseNotes>
17+
<Version>1.4.3</Version>
18+
<PackageReleaseNotes>API simplification and improvments to deferred mapping.</PackageReleaseNotes>
2119
</PropertyGroup>
2220

2321
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

0 commit comments

Comments
 (0)