Skip to content

Commit

Permalink
Use SortedSet instead of list
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Apr 4, 2024
1 parent 307023c commit 3fc752b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .Lib9c.Tests/Model/State/CollectionStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ namespace Lib9c.Tests.Model.State
{
using System.Collections.Generic;
using Bencodex.Types;
using Libplanet.Crypto;
using Nekoyume.Action;
using Nekoyume.Model.State;
using Xunit;

Expand All @@ -14,7 +12,7 @@ public void Bencoded()
{
var state = new CollectionState
{
Ids = new List<int>
Ids = new SortedSet<int>
{
1,
2,
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Module/CollectionModuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void CollectionState()

var state = new CollectionState
{
Ids = new List<int>
Ids = new SortedSet<int>
{
1,
},
Expand All @@ -47,7 +47,7 @@ public void CollectionStates()

var state = new CollectionState
{
Ids = new List<int>
Ids = new SortedSet<int>
{
1,
},
Expand Down
7 changes: 2 additions & 5 deletions Lib9c/Model/State/CollectionState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Bencodex;
using Bencodex.Types;
using Nekoyume.Model.Stat;
Expand All @@ -12,7 +11,7 @@ namespace Nekoyume.Model.State
/// </summary>
public class CollectionState : IBencodable
{
public List<int> Ids = new();
public SortedSet<int> Ids = new();

public CollectionState()
{
Expand All @@ -25,15 +24,13 @@ public CollectionState(List serialized)
{
Ids.Add((Integer)value);
}

Ids = Ids.Distinct().ToList();
}

public CollectionState(IValue bencoded) : this((List)bencoded)
{
}

public IValue Bencoded => List.Empty.Add(new List(Ids.Distinct()));
public IValue Bencoded => List.Empty.Add(new List(Ids));

public List<StatModifier> GetModifiers(CollectionSheet collectionSheet)
{
Expand Down

0 comments on commit 3fc752b

Please sign in to comment.