enhance Cache to allow specializing the key comparer
This commit is contained in:
@@ -15,17 +15,21 @@ using System.Collections.Generic;
|
|||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
public class Cache<T, U> : IEnumerable<KeyValuePair<T, U>>
|
public class Cache<T, U> : IEnumerable<KeyValuePair<T, U>>
|
||||||
{
|
{
|
||||||
Dictionary<T, U> hax = new Dictionary<T, U>();
|
Dictionary<T, U> hax;
|
||||||
Func<T,U> loader;
|
Func<T,U> loader;
|
||||||
|
|
||||||
public Cache(Func<T,U> loader)
|
public Cache(Func<T,U> loader, IEqualityComparer<T> c)
|
||||||
{
|
{
|
||||||
|
hax = new Dictionary<T, U>(c);
|
||||||
if (loader == null)
|
if (loader == null)
|
||||||
throw new ArgumentNullException();
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Cache(Func<T, U> loader)
|
||||||
|
: this(loader, EqualityComparer<T>.Default) { }
|
||||||
|
|
||||||
public U this[T key]
|
public U this[T key]
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user