using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using BCG; namespace bts { public class CircularBufferTable : IBlueRowCollection { private BlueTable _table; private List _ordered_list = new List(); private int _buffer_sz; public CircularBufferTable(IBlueTableSchema schema, int buffer_sz) { _table = new BlueTable(schema); _buffer_sz = buffer_sz; } // returns the row that might need to be deleted to keep // the circular buffer intact public IBlueRow add_row(IBlueRow row) { _ordered_list.Add(row); _table.addRow(row); if (_ordered_list.Count > _buffer_sz) { IBlueRow rv = _ordered_list.ElementAt(0); _ordered_list.RemoveAt(0); _table.deleteRow(rv); return rv; } return null; } public IBlueRow this[int id] { get { return _table[id]; } } public IBlueTableSchema schema { get { return _table.schema; } } public bool containsID(int id) { return _table.containsID(id); } public void CopyTo(Array array, int index) { _table.CopyTo((IBlueRow[])array, index); } public int Count { get { return _table.Count; } } public bool IsSynchronized { get { return false; } } public object SyncRoot { get { return this; } } public System.Collections.IEnumerator GetEnumerator() { return _table.GetEnumerator(); } } }