diff --git a/Libplanet.Store/Trie/Nodes/BaseNode.cs b/Libplanet.Store/Trie/Nodes/BaseNode.cs deleted file mode 100644 index bdd9bb223b4..00000000000 --- a/Libplanet.Store/Trie/Nodes/BaseNode.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Bencodex.Types; - -namespace Libplanet.Store.Trie.Nodes -{ - /// - /// Represents a node in MPT that can have a value. - /// - public abstract class BaseNode : INode - { - protected BaseNode(INode? value) - { - Value = value; - } - - // It will not support embedded node. - public INode? Value { get; } - - /// - public abstract IValue ToBencodex(); - } -} diff --git a/Libplanet.Store/Trie/Nodes/FullNode.cs b/Libplanet.Store/Trie/Nodes/FullNode.cs index 4557af7c1df..9f3abe6de6a 100644 --- a/Libplanet.Store/Trie/Nodes/FullNode.cs +++ b/Libplanet.Store/Trie/Nodes/FullNode.cs @@ -5,16 +5,15 @@ namespace Libplanet.Store.Trie.Nodes { - public sealed class FullNode : BaseNode, IEquatable + public sealed class FullNode : INode, IEquatable { - // 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 children) - : base(children[ChildrenCount - 1]) { if (children.Length != ChildrenCount) { @@ -23,10 +22,13 @@ public FullNode(ImmutableArray children) } Children = children; + Value = children[ChildrenCount - 1]; } public ImmutableArray Children { get; } + public INode? Value { get; } + public FullNode SetChild(int index, INode childNode) { return new FullNode(Children.SetItem(index, childNode)); @@ -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(); /// - public override IValue ToBencodex() => + public IValue ToBencodex() => new List(Children.Select(child => child?.ToBencodex() ?? Null.Value)); } }