public IBitset And(IBitset otherSet)
{
RLEBitset otherRLESet = (RLEBitset)otherSet; // cast to an RLEBitset - errors if cannot cast
RLEBitset rtnVal = new RLEBitset(); // instantiate the return value
rtnVal.length = this.length;
List<Run> runsA = this.runArray;
List<Run> runsB = otherRLESet.runArray;
int i = 0;
int j = 0;
while (i < runsA.Count && j < runsB.Count)
{
// check for overlap of the runs.
Run currRun = new Run();
if (TryCreateIntersection(runsA[i], runsB[j], ref currRun))
{
rtnVal.runArray.Add(currRun);
}
// iterate the counters appropriately to compare the next set of runs for overlap.
if (runsA[i].EndIndex > runsB[j].EndIndex + 1)
{
j++;
}
else if (runsA[i].EndIndex < runsB[j].EndIndex - 1)
{
i++;
}
else
{
i++;
j++;
}
}
return rtnVal;
}