67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using Spark.Core.Diagnostics;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
namespace BCG
|
|
{
|
|
/// <summary>
|
|
/// Hashtable of DoubleyLinkedList tailored for the Join deletions
|
|
/// </summary>
|
|
internal class JoinDeletionIndex
|
|
{
|
|
Dictionary<object, RowList> myIndex = new();
|
|
private string myOpIdName ;
|
|
private bool myIsLeft;
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="opIdName">opIdName represents the name of the column corresponding to id of the operand table</param>
|
|
/// <param name="isLeft">Indicator for left or right operand table</param>
|
|
public JoinDeletionIndex(string opIdName, bool isLeft)
|
|
{
|
|
myOpIdName = opIdName;
|
|
myIsLeft = isLeft;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a joinRow to the hashtable; in addition the joinRow is made to point to the node added
|
|
/// </summary>
|
|
/// <param name="row">JoinRow to add</param>
|
|
public void add (JoinRow row)
|
|
{
|
|
object o = ExceptionAssert.NotNull(row[myOpIdName]);
|
|
RowNode nodeAdded = myIndex.GetOrAdd(o, _ => new()).add(row);
|
|
if (myIsLeft)
|
|
row.leftNode = nodeAdded;
|
|
else
|
|
row.rightNode = nodeAdded;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// To remove a node, if node does not exist exception is thrown
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
public void remove (RowNode node) {
|
|
var nodeId = ExceptionAssert.NotNull(node.row?[myOpIdName]);
|
|
myIndex[nodeId].remove(node);
|
|
}
|
|
|
|
public RowList getMatchingRows (object key) {
|
|
RowList retVal = (RowList)myIndex[key];
|
|
if (retVal == null)
|
|
return new RowList ();
|
|
return retVal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Empties the entry for the key provided
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void removeAll (object obj) {myIndex.Remove(obj);}
|
|
|
|
public void clear () {myIndex.Clear ();}
|
|
|
|
}
|
|
}
|