forked from Violet-CLM/MLLE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrayMap.cs
51 lines (41 loc) · 1.06 KB
/
ArrayMap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Extra.Collections
{
class ArrayMap<T>
{
private readonly T[,] array;
private int count;
public ArrayMap(long width, long height)
{
this.array = new T[width, height];
}
public T this[long x, long y]
{
get { return array[x, y]; }
set
{
count += (IsSet(value) ? 1 : 0) - (IsSet(array[x, y]) ? 1 : 0);
array[x, y] = value;
}
}
public int Count
{
get { return count; }
}
public int GetLength(int dimension)
{
return this.array.GetLength(dimension);
}
public IEnumerator<T> GetEnumerator()
{
return this.array.Cast<T>().Where(IsSet).GetEnumerator();
}
private static bool IsSet(T value)
{
return !EqualityComparer<T>.Default.Equals(value, default(T));
}
}
}