57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
namespace Bts.DataStream;
|
|
|
|
using BCG;
|
|
|
|
using Bts.DataStreamCore;
|
|
|
|
using mbts.utils;
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class BlueIndexedColumnTable : IBlueRowCollection {
|
|
readonly IBlueTableSchema schema;
|
|
readonly IList<object?>[] columnValues;
|
|
readonly Dictionary<int, int> rowIdToIndex;
|
|
|
|
public BlueIndexedColumnTable(IBlueTableSchema schema, IList<object?>[] columnValues) {
|
|
this.schema = schema;
|
|
this.columnValues = columnValues;
|
|
int idColumnIndex = schema.ResolveIndices("id");
|
|
rowIdToIndex = columnValues[idColumnIndex]
|
|
.Select((idObj, idx) => new KeyValuePair<int, int>(ExceptionAssert.Argument.Is<int>(idObj), idx))
|
|
.ToDictionary();
|
|
}
|
|
|
|
public IBlueRow this[int id] =>
|
|
rowIdToIndex.TryGetValue(id, out var idx)
|
|
? GetRow(idx)
|
|
: throw new KeyNotFoundException();
|
|
|
|
IBlueTableSchema IBlueRowCollection.schema => schema;
|
|
|
|
public int Count => rowIdToIndex.Count;
|
|
|
|
public bool containsID(int id) =>
|
|
rowIdToIndex.ContainsKey(id);
|
|
|
|
public IEnumerator<IBlueRow> GetEnumerator() {
|
|
int count = Count;
|
|
for (int i = 0; i < count; i++) {
|
|
yield return GetRow(i);
|
|
}
|
|
}
|
|
|
|
public IBlueRow GetRow(int index) =>
|
|
new BlueRowColumnWrapper(schema, index, columnValues);
|
|
|
|
public int IndexOf(IBlueRow item) =>
|
|
rowIdToIndex.TryGetValue(item.Id(), out var idx) && BlueRowEqualityComparer.Equals(GetRow(idx), item)
|
|
? idx
|
|
: -1;
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() =>
|
|
GetEnumerator();
|
|
}
|