Added tests for LRUCache.

Moved core test code to reflect changes in core code.

Removed unused using directives.
This commit is contained in:
2021-04-19 14:40:11 -05:00
parent 35a2765559
commit f5a181d2f2
12 changed files with 137 additions and 17 deletions

View File

@@ -1,9 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace GameServiceWarden.Core.Module
namespace GameServiceWarden.Core.Collection
{
public class LRUCache<K, V>
public class LRUCache<K, V> : IEnumerable<V>
{
private class Node
{
@@ -14,7 +15,7 @@ namespace GameServiceWarden.Core.Module
}
public int Size {get { return size; } }
public int Length {get { return valueDictionary.Count; } }
public int Count {get { return valueDictionary.Count; } }
private readonly int size;
private Node top;
private Node bottom;
@@ -49,7 +50,7 @@ namespace GameServiceWarden.Core.Module
bottom = node;
} else if (valueDictionary.Count == Size) {
valueDictionary.Remove(bottom.key);
cleanupAction(bottom.value);
cleanupAction?.Invoke(bottom.value);
bottom = bottom.front;
}
valueDictionary[key] = node;
@@ -68,10 +69,27 @@ namespace GameServiceWarden.Core.Module
return value.value;
}
public bool IsCached(K key) {
return valueDictionary.ContainsKey(key);
}
public void Clear() {
top = null;
bottom = null;
valueDictionary.Clear();
}
public IEnumerator<V> GetEnumerator()
{
foreach (Node node in valueDictionary.Values)
{
yield return node.value;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
}

View File

@@ -2,14 +2,10 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using GameServiceWarden.API.Games;
using GameServiceWarden.Core.Persistence;
using GameServiceWarden.API.Module;
using System.Text;
using GameServiceWarden.Core.Collection;
namespace GameServiceWarden.Core.Module
{