Files
spark/src/DataStreamSuite/DataStream/Primitives/Join/JoinOperandRowIndex.cs
T
2023-09-04 16:25:40 -04:00

67 lines
1.9 KiB
C#

using System;
using System.Collections;
using BCG.Utilities;
namespace BCG
{
/// <summary>
/// Datastructure used to mantain the join rows, there would be 2 of those, for right and left operands
/// respectivly. Objective of this data structure is to get all rows belonging to a joinCol value and to
/// delete rows provided their id's.
/// </summary>
internal class JoinOperandRowIndex
{
private IDictionary myJoinColDict = new Hashtable (), myIdDict = new Hashtable ();
private int myJoinColOrdinal, myIdColOrdinal;
/// <summary>
///
/// </summary>
/// <param name="joinColIndex">index of the joinCol</param>
/// <param name="idColindex">index of the id</param>
public JoinOperandRowIndex (int joinColIndex, int idColindex)
{
myJoinColOrdinal = joinColIndex;
myIdColOrdinal = idColindex;
}
public JoinOperandRowIndex(IBlueRowCollection rows, int joinColIndex, int idColIndex) :
this(joinColIndex, idColIndex)
{
foreach (IBlueRow row in rows)
add (row);
}
public void add (IBlueRow row)
{
RowList list;
if (myJoinColDict[row[myJoinColOrdinal]] == null)
myJoinColDict[row[myJoinColOrdinal]] = list = new RowList ();
else
list = (RowList)myJoinColDict[row[myJoinColOrdinal]];
myIdDict[row[myIdColOrdinal]] = list.add (row);
}
public void remove (IBlueRow row)
{
RowNode node = (RowNode)myIdDict[row[myIdColOrdinal]];
((RowList)myJoinColDict[row[myJoinColOrdinal]]).remove (node);
myIdDict.Remove (row[myIdColOrdinal]);
}
public RowList getMatchingRows (object key)
{
RowList retVal = (RowList)myJoinColDict[key];
if (retVal == null)
return new RowList ();
return retVal;
}
public void clear ()
{
myJoinColDict.Clear ();
myIdDict.Clear ();
}
}
}