Files
spark/src/DataStreamSuite/DataStreamCore/BlueData/IBlueTableIndex.cs
T
2024-05-25 15:37:33 +00:00

253 lines
8.2 KiB
C#

// using System;
// using System.Collections;
// //using BCG.Utilities;
// namespace BCG
// {
// /// <summary>
// /// Provides a multiple indexing mechanism, required to increase the peformance of the streams
// /// </summary>
// 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 ();
// /// <summary>
// /// Builds an index with 2 columns of the table acting as primary index and secondary index
// /// respectively
// /// </summary>
// /// <param name="table">
// /// table to index
// /// </param>
// /// <param name="primaryIndex">
// /// primary key to index upon
// /// </param>
// /// <param name="secondaryIndex">
// /// column serving as the secondary key
// /// </param>
// 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);
// }
// /// <summary>
// /// To add a row to the index
// /// </summary>
// /// <param name="row">
// /// row to be added
// /// </param>
// 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;
// }
// }
// /// <summary>
// /// If index or the primary key has already been deleted appropriate exceptions are thrown
// /// </summary>
// /// <param name="row"></param>
// 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]);
// }
// /// <summary>
// /// Returns an array of DataRow that match the primary key being passed as an argument
// /// </summary>
// /// <param name="o">
// /// Primary Key of the table
// /// </param>
// /// <returns>
// /// Array of rows matching the criteria
// /// </returns>
// 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;
// }
// /// <summary>
// /// returns as array of the primary keys
// /// </summary>
// /// <returns>
// /// object[] of primary keys
// /// </returns>
// public Array getPrimaryKeys()
// {
// object[] retval = new object [myHt.Keys.Count];
// myHt.Keys.CopyTo (retval, 0);
// return retval;
// }
// }
// */
// /// <summary>
// /// Provides a 1-Level indexing structure.
// /// </summary>
// public class BlueTableSingleIndex : IBlueTableIndex
// {
// string myPrimaryKey;
// string mySecondaryKey;
// Hashtable myHt = new Hashtable();
// public BlueTableSingleIndex(string primaryKey, string secondaryKey)
// {
// myPrimaryKey = primaryKey;
// mySecondaryKey = secondaryKey;
// }
// /// <summary>
// /// The primary key is the indexing key, and the secondary key is used as the key for
// /// searching and hence deletion
// /// </summary>
// /// <param name="table"></param>
// /// <param name="primaryKey"></param>
// /// <param name="secondaryKey"></param>
// public BlueTableSingleIndex(IBlueRowCollection table, string primaryKey, string secondaryKey)
// : this(primaryKey, secondaryKey)
// {
// foreach (IBlueRow row in table)
// addRow(row);
// }
// /// <summary>
// /// Adds row to the indexing new structure
// /// </summary>
// /// <param name="row"></param>
// public void addRow(IBlueRow row)
// {
// if (myHt[row[myPrimaryKey]] == null)
// myHt[row[myPrimaryKey]] = new ArrayList();
// ((ArrayList)(myHt[row[myPrimaryKey]])).Add(row);
// }
// /// <summary>
// /// Getts rows based on the Primary Key. Matching of the primary key is the only criteria
// /// </summary>
// /// <param name="row"></param>
// /// <returns></returns>
// 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];
// }
// /// <summary>
// /// Gets rows based on the primary AND the secondary key
// /// </summary>
// /// <param name="row"></param>
// /// <returns></returns>
// 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;
// }
// /// <summary>
// /// Deletes rows based on the primary key only
// /// </summary>
// /// <param name="row"></param>
// 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);
// }
// }
// }