Files
spark/src/DataStreamSuite/DataStreamCore/BlueData/ColumnKeyedData.cs
T
2023-09-04 16:25:40 -04:00

74 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BCG
{
public class ColumnKeyedData
{
private int[] _key_col_indices = null;
private string[] _key_col_names;
private BlueRowHasher _row_hasher;
private Dictionary<int, IBlueRow> _row_map = new Dictionary<int, IBlueRow>();
public ColumnKeyedData(params string[] key_col_names)
{
_key_col_names = key_col_names;
_row_hasher = new BlueRowHasher(key_col_names.Length);
}
public void delete_rows(IBlueRowCollection rows)
{
if (rows != null)
{
_init_schema(rows.schema);
foreach (IBlueRow r in rows)
{
int row_hash = _row_hasher.get_hash(r, _key_col_indices);
if (_row_map.ContainsKey(row_hash))
_row_map.Remove(row_hash);
}
}
}
public void add_rows(IBlueRowCollection rows)
{
if (rows != null)
{
_init_schema(rows.schema);
foreach (IBlueRow r in rows)
{
int row_hash = _row_hasher.get_hash(r, _key_col_indices);
_row_map[row_hash] = r;
}
}
}
public void reset_state (IBlueRowCollection rows)
{
_row_map.Clear();
add_rows(rows);
}
public IEnumerable<IBlueRow> get_all_rows() { return _row_map.Values; }
private void _init_schema(IBlueTableSchema schema)
{
if (_key_col_indices == null)
_key_col_indices = BlueDataUtility.get_column_indices(schema, _key_col_names);
}
public IBlueRow get_row(params object[] key_vals)
{
int row_hash = _row_hasher.get_hash(key_vals);
IBlueRow rv = null;
_row_map.TryGetValue(row_hash, out rv);
return rv;
}
}
}