internal class RepTable<T> {
private List<object> list = new List<object>();
private int? firstVacant = null;
private class Vacant {
internal int? next;
internal Vacant(int? next) {
this.next = next;
}
}
internal int Add(T v) {
int rep;
if (firstVacant.HasValue) {
rep = firstVacant.Value;
firstVacant = ((Vacant) list[rep]).next;
list[rep] = v!;
} else {
rep = list.Count;
list.Add(v!);
}
return rep;
}
internal T Get(nint rep) {
if (list[(int)rep] is Vacant) {
throw new global::System.ArgumentException("invalid rep");
}
return (T) list[(int)rep];
}
internal T Remove(nint rep) {
var val = Get(rep);
list[(int)rep] = new Vacant(firstVacant);
firstVacant = (int)rep;
return (T) val;
}
}