Skip to content

Commit

Permalink
Vitor suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Jan 7, 2020
1 parent 625f7a8 commit 1aaafbc
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/neo/IO/Caching/HashSetCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HashSetCache<T> : IReadOnlyCollection<T> where T : IEquatable<T>
/// <summary>
/// Cached count
/// </summary>
private int _count = -1;
private int _count = 0;

/// <summary>
/// Sets where the Hashes are stored
Expand All @@ -26,20 +26,8 @@ public class HashSetCache<T> : IReadOnlyCollection<T> where T : IEquatable<T>
/// </summary>
private readonly int maxBucketCount;

public int Count
{
get
{
if (_count != -1) return _count;
_count = 0;
foreach (var set in sets)
{
_count += set.Count;
}
return _count;
}
}

public int Count => _count;

public HashSetCache(int bucketCapacity, int maxBucketCount = 10)
{
if (bucketCapacity <= 0) throw new ArgumentOutOfRangeException($"{nameof(bucketCapacity)} should be greater than 0");
Expand All @@ -53,7 +41,7 @@ public HashSetCache(int bucketCapacity, int maxBucketCount = 10)
public bool Add(T item)
{
if (Contains(item)) return false;
_count = -1;
_count++;
if (sets.First.Value.Count < bucketCapacity) return sets.First.Value.Add(item);
var newSet = new HashSet<T>
{
Expand Down Expand Up @@ -81,7 +69,7 @@ public void ExceptWith(IEnumerable<T> items)
{
if (set.Remove(item))
{
_count = -1;
_count--;
break;
}
}
Expand Down

1 comment on commit 1aaafbc

@vncoelho
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like to be enough. Good @shargon.

Please sign in to comment.