deleting old serializers

This commit is contained in:
Taha Afzal authored and John Colvin committed 2024-05-25 15:37:33 +00:00
1 parent 061481419e
commit 90ec64d25c
74 files changed
+941 -6080

No files matched your search

@@ -221,23 +221,23 @@ namespace BCG {
// these are the only types allowed in schemas
private static IReadOnlyDictionary<TypeCode, Type> _typecode_to_type = new Dictionary<TypeCode, Type>
{
{ TypeCode.Boolean, typeof(bool) },
{ TypeCode.Byte, typeof(byte) },
{ TypeCode.Char, typeof(char) },
{ TypeCode.Boolean, typeof(bool) }, //3
{ TypeCode.Byte, typeof(byte) }, //6
{ TypeCode.Char, typeof(char) }, //4
// TODO
{ TypeCode.DateTime, typeof(DateTime) },
{ TypeCode.Decimal, typeof(decimal) },
{ TypeCode.Double, typeof(double) },
{ TypeCode.DateTime, typeof(DateTime) },//16
{ TypeCode.Decimal, typeof(decimal) }, //15
{ TypeCode.Double, typeof(double) }, //14
//{ TypeCode.Empty, null },
{ TypeCode.Int16, typeof(short) },
{ TypeCode.Int32, typeof(int) },
{ TypeCode.Int64, typeof(long) },
{ TypeCode.SByte, typeof(sbyte) },
{ TypeCode.Single, typeof(Single) },
{ TypeCode.String, typeof(string) },
{ TypeCode.UInt16, typeof(UInt16) },
{ TypeCode.UInt32, typeof(UInt32) },
{ TypeCode.UInt64, typeof(UInt64) }
{ TypeCode.Int16, typeof(short) }, //7
{ TypeCode.Int32, typeof(int) }, //9
{ TypeCode.Int64, typeof(long) }, //11
{ TypeCode.SByte, typeof(sbyte) }, //5
{ TypeCode.Single, typeof(Single) }, //13
{ TypeCode.String, typeof(string) }, //18
{ TypeCode.UInt16, typeof(UInt16) }, //8
{ TypeCode.UInt32, typeof(UInt32) }, //10
{ TypeCode.UInt64, typeof(UInt64) } //12
};
public static IEnumerable<TypeCode> valid_column_typecodes() {
@@ -1139,6 +1139,14 @@ namespace BCG {
return ci.colNo + ";" + ci.colName + ";" + ci.colType;
}
public static string to_string(this IBlueRow r) {
string rv = String.Empty;
foreach (ColumnInfo c in r.schema.columnInfo) {
rv += $"{c.colName}: {r[c.colName]}\n";
}
return rv;
}
public static void compute_differences_fast(IBlueRowCollection new_rows, IBlueRowCollection old_rows,
out IBlueRowCollection out_d_rows, out IBlueRowCollection out_a_rows) {
if (old_rows == null || old_rows.Count == 0) {
@@ -1,252 +1,252 @@
using System;
using System.Collections;
//using BCG.Utilities;
// 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) { }
}
// 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 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);
}
// /*
// public class BlueTableDoubleIndex : IBlueTableIndex
// {
// private IBlueRowCollection myTable;
// private string myPrimaryIndex;
// private string mySecondaryIndex;
// private Hashtable myHt = new Hashtable ();
/// <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>
// /// 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 ();
// }
/// <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]);
}
// private void myInit()
// {
// foreach (IBlueRow row in myTable)
// addRow (row);
// }
/// <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>
// /// 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>
// /// 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();
// /// <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;
}
// 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>
// /// 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>
// /// 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]);
}
// /// <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];
}
// 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]);
}
// /// <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;
}
// 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]);
}
// /// <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 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(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);
}
}
}
// 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);
// }
// }
// }