Skip to content

Commit

Permalink
Changed FullNode to no longer inherit BaseNode; removed BaseNode
Browse files Browse the repository at this point in the history
  • Loading branch information
greymistcube committed Dec 27, 2023
1 parent faa7b7f commit d3e0e0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
21 changes: 0 additions & 21 deletions Libplanet.Store/Trie/Nodes/BaseNode.cs

This file was deleted.

15 changes: 7 additions & 8 deletions Libplanet.Store/Trie/Nodes/FullNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

namespace Libplanet.Store.Trie.Nodes
{
public sealed class FullNode : BaseNode, IEquatable<FullNode>
public sealed class FullNode : INode, IEquatable<FullNode>
{
// Children 0x10 + Value 0x1
// Children 0x10 + Value 0x01
public const byte ChildrenCount = 0x11;

public static readonly FullNode Empty =
new FullNode(new INode?[ChildrenCount].ToImmutableArray());

public FullNode(ImmutableArray<INode?> children)
: base(children[ChildrenCount - 1])
{
if (children.Length != ChildrenCount)
{
Expand All @@ -23,10 +22,13 @@ public FullNode(ImmutableArray<INode?> children)
}

Children = children;
Value = children[ChildrenCount - 1];
}

public ImmutableArray<INode?> Children { get; }

public INode? Value { get; }

public FullNode SetChild(int index, INode childNode)
{
return new FullNode(Children.SetItem(index, childNode));
Expand All @@ -48,13 +50,10 @@ public bool Equals(FullNode? other)
public override bool Equals(object? obj) =>
obj is FullNode other && Equals(other);

public override int GetHashCode()
{
return Children.GetHashCode();
}
public override int GetHashCode() => Children.GetHashCode();

/// <inheritdoc cref="INode.ToBencodex()"/>
public override IValue ToBencodex() =>
public IValue ToBencodex() =>
new List(Children.Select(child => child?.ToBencodex() ?? Null.Value));
}
}

0 comments on commit d3e0e0c

Please sign in to comment.