Ejemplo n.º 1
0
//joins contigious spans together
void coalescing(vector <Spans*> spansVector)
{
    int firstBeginning = 0;
    int firstEnding = 0;
    int secondBeginning = 0;
    int secondEnding = 0;

    Spans* current = NULL;
    Spans* next = NULL;
    for(int i = 0; i < spansVector.size();i++)
    {
        current = spansVector[i];
        next = spansVector[i+1];
        firstBeginning = current->getBeginning();
        firstEnding = current->getEnding();
        secondBeginning = next->getBeginning();
        secondEnding = next->getEnding();

        if(firstEnding+1 == secondBeginning)
        {
            spansVector[i] = NULL;
            spansVector[i+1] = NULL;

            Spans* newSpan = new Spans(firstBeginning,firstEnding,true);
            newSpan->setBeginning(firstBeginning);
            newSpan->setEnding(secondEnding);

            spansVector[i] = newSpan;
            removeNULLsFromVector(spansVector);
        }
    }

}
Ejemplo n.º 2
0
//joins all contiguious spans together at end of table
void condensing(vector <Spans*> spanVector, vector <string> memoryTable)
{
    coalescing(spanVector);
    int totalFreeSpaces = 0;
    int difference = 0;

    Spans* current = NULL;
    for(int i = 0; i < spanVector.size(); i++)
    {
        current = spanVector[i];
        difference = current->getEnding() - current->getBeginning() + 1;
        totalFreeSpaces = totalFreeSpaces + difference;
    }

    //move everything in memory table up if the address above it is free
    for(int a = 1; a < memoryTable.size();a++)
    {
        if(memoryTable[a-1] == "free")
        {
            memoryTable[a -1] = memoryTable[a];
            memoryTable[a] = "free";
        }
    }

    for(int b = memoryTable.size()-totalFreeSpaces; b < totalFreeSpaces; b++)
    {
        memoryTable[b] = "free";
    }

    Spans* newSpan = new Spans(memoryTable.size()-totalFreeSpaces,totalFreeSpaces,free);

    newSpan->setBeginning(memoryTable.size()-totalFreeSpaces);
    newSpan->setEnding(totalFreeSpaces);

    resetSpanVector(spanVector);

    spanVector.push_back(newSpan);
}