// using System; // using System.Collections; // //using BCG.Utilities; // namespace BCG // { // /// // /// Provides a multiple indexing mechanism, required to increase the peformance of the streams // /// // public class BlueTableIndexException : Exception // { // public BlueTableIndexException(string msg) : base(msg) { } // } // public interface IBlueTableIndex // { // void addRow(IBlueRow row); // void deleteRowOnPrimaryKey(object pkValue); // void deleteRowOnPrimaryKey(IBlueRow row); // void deleteRowOnBothKeys(object pkValue, object skValue); // void deleteRowOnBothKeys(IBlueRow row); // ArrayList searchRowOnPrimaryKey(object pkValue); // ArrayList searchRowOnPrimaryKey(IBlueRow row); // ArrayList searchRowOnBothKeys(object pkValue, object skValue); // ArrayList searchRowOnBothKeys(IBlueRow row); // } // /* // public class BlueTableDoubleIndex : IBlueTableIndex // { // private IBlueRowCollection myTable; // private string myPrimaryIndex; // private string mySecondaryIndex; // private Hashtable myHt = new Hashtable (); // /// // /// Builds an index with 2 columns of the table acting as primary index and secondary index // /// respectively // /// // /// // /// table to index // /// // /// // /// primary key to index upon // /// // /// // /// column serving as the secondary key // /// // public BlueTableDoubleIndex (IBlueRowCollection table, string primaryIndex, string secondaryIndex) // { // myTable = table; // myPrimaryIndex = primaryIndex; // mySecondaryIndex = secondaryIndex; // myInit (); // } // private void myInit() // { // foreach (IBlueRow row in myTable) // addRow (row); // } // /// // /// To add a row to the index // /// // /// // /// row to be added // /// // public void addRow (IBlueRow row) // { // if (myHt[row[myPrimaryIndex]] != null) // ((Hashtable)(myHt[row[myPrimaryIndex]]))[row[mySecondaryIndex]] = row; // else // { // TimeManager.start (); // Hashtable ht = new Hashtable(); // TimeManager.stop (); // ht[row[mySecondaryIndex]] = row; // myHt[row[myPrimaryIndex]] = ht; // } // } // /// // /// If index or the primary key has already been deleted appropriate exceptions are thrown // /// // /// // public void deleteRow (IBlueRow row) // { // if (myHt[row[myPrimaryIndex]] == null) // { // throw new BlueTableIndexException ("Theres no index (primary hash table key) for this index value"); // } // ((Hashtable)(myHt[row[myPrimaryIndex]])).Remove(row[mySecondaryIndex]); // if (((Hashtable)(myHt[row[myPrimaryIndex]])).Keys.Count == 0) // myHt.Remove(row[myPrimaryIndex]); // } // /// // /// Returns an array of DataRow that match the primary key being passed as an argument // /// // /// // /// Primary Key of the table // /// // /// // /// Array of rows matching the criteria // /// // public IBlueRow[] findValueFromPrimaryKey (object o) // { // object oht = myHt[o]; // if (oht == null) // return new IBlueRow[0]; // Hashtable ht = (Hashtable)oht; // IBlueRow[] rows = new IBlueRow[ht.Keys.Count]; // ht.Values.CopyTo(rows, 0); // return rows; // } // /// // /// returns as array of the primary keys // /// // /// // /// object[] of primary keys // /// // public Array getPrimaryKeys() // { // object[] retval = new object [myHt.Keys.Count]; // myHt.Keys.CopyTo (retval, 0); // return retval; // } // } // */ // /// // /// Provides a 1-Level indexing structure. // /// // public class BlueTableSingleIndex : IBlueTableIndex // { // string myPrimaryKey; // string mySecondaryKey; // Hashtable myHt = new Hashtable(); // public BlueTableSingleIndex(string primaryKey, string secondaryKey) // { // myPrimaryKey = primaryKey; // mySecondaryKey = secondaryKey; // } // /// // /// The primary key is the indexing key, and the secondary key is used as the key for // /// searching and hence deletion // /// // /// // /// // /// // public BlueTableSingleIndex(IBlueRowCollection table, string primaryKey, string secondaryKey) // : this(primaryKey, secondaryKey) // { // foreach (IBlueRow row in table) // addRow(row); // } // /// // /// Adds row to the indexing new structure // /// // /// // public void addRow(IBlueRow row) // { // if (myHt[row[myPrimaryKey]] == null) // myHt[row[myPrimaryKey]] = new ArrayList(); // ((ArrayList)(myHt[row[myPrimaryKey]])).Add(row); // } // /// // /// Getts rows based on the Primary Key. Matching of the primary key is the only criteria // /// // /// // /// // public ArrayList searchRowOnPrimaryKey(IBlueRow row) // { // return searchRowOnPrimaryKey(row[myPrimaryKey]); // } // public ArrayList searchRowOnPrimaryKey(object pkValue) // { // if (myHt[pkValue] == null) // return new ArrayList(); // return (ArrayList)myHt[pkValue]; // } // /// // /// Gets rows based on the primary AND the secondary key // /// // /// // /// // public ArrayList searchRowOnBothKeys(IBlueRow row) // { // return searchRowOnBothKeys(row[myPrimaryKey], row[mySecondaryKey]); // } // public ArrayList searchRowOnBothKeys(object pkValue, object skValue) // { // if (myHt[pkValue] == null) // return new ArrayList(); // ArrayList matchingList = (ArrayList)myHt[pkValue]; // ArrayList retVal = new ArrayList(); // foreach (IBlueRow r in matchingList) // if (r[mySecondaryKey].Equals(skValue)) // retVal.Add(r); // return retVal; // } // /// // /// Deletes rows based on the primary key only // /// // /// // public void deleteRowOnPrimaryKey(IBlueRow row) // { // deleteRowOnPrimaryKey(row[myPrimaryKey]); // } // public void deleteRowOnPrimaryKey(object pkValue) // { // if (myHt[pkValue] == null) // throw new BlueTableIndexException("Key to be deleted was not found in the index"); // myHt.Remove(pkValue); // } // public void deleteRowOnBothKeys(IBlueRow row) // { // deleteRowOnBothKeys(row[myPrimaryKey], row[mySecondaryKey]); // } // public void deleteRowOnBothKeys(object pkValue, object skValue) // { // if (myHt[pkValue] == null) // throw new BlueTableIndexException("Key to be deleted was not found in the index"); // ArrayList matchingList = (ArrayList)myHt[pkValue]; // ArrayList aux = new ArrayList(); // foreach (IBlueRow r in matchingList) // if (r[mySecondaryKey].Equals(skValue)) // aux.Add(r); // foreach (IBlueRow r in aux) // matchingList.Remove(r); // } // } // }