-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringTracker.cs
53 lines (43 loc) · 1.07 KB
/
StringTracker.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
51
52
53
using System.Collections.Generic;
namespace LCS
{
class StringTracker
{
public List this[int i] => Lists[i];
readonly List[] Lists = new List[2] { new List(), new List() };
public class List : List<int>
{
public void Keep(int i) => Add(i);
public void Free(int _) { }
}
}
class StringTrackerHashSet : HashSet<int>
{
public StringTrackerHashSet this[int i] => this;
readonly HashSet<int> Removed = new HashSet<int>();
public void Keep(int _) { }
public void Free(int i) => Removed.Add(i);
public new void Clear()
{
ExceptWith(Removed);
Removed.Clear();
}
}
class StringTrackerSortedSet : SortedSet<int>
{
public StringTrackerSortedSet this[int i] => this;
readonly HashSet<int> Removed = new HashSet<int>();
public void Keep(int _) { }
public void Free(int i) => Removed.Add(i);
public new void Clear()
{
ExceptWith(Removed);
Removed.Clear();
}
}
static class StringTrackerExtensions
{
public static void Keep(this List<int> t, int i) => t.Add(i);
public static void Free(this List<int> _1, int _2) { }
}
}