Ejemplo n.º 1
0
// copy constructor
DoublyLinkedList::DoublyLinkedList(DoublyLinkedList& dll)
{
  // Initialize the list
  header.next = &trailer; trailer.prev = &header;
  if (!dll.isEmpty()){
  DListNode* node;
  node=dll.getFirst();
  while (node!=dll.getAfterLast()){
    insertLast(node->getElem());//insert new element
    node=node->getNext();//set node to next node
 }
}
}
Ejemplo n.º 2
0
void CopiedSpace::doneCopying()
{
    {
        MutexLocker locker(m_loanedBlocksLock);
        while (m_numberOfLoanedBlocks > 0)
            m_loanedBlocksCondition.wait(m_loanedBlocksLock);
    }

    ASSERT(m_inCopyingPhase == m_shouldDoCopyPhase);
    m_inCopyingPhase = false;

    DoublyLinkedList<CopiedBlock>* toSpace;
    DoublyLinkedList<CopiedBlock>* fromSpace;
    TinyBloomFilter* blockFilter;
    if (heap()->operationInProgress() == FullCollection) {
        toSpace = m_oldGen.toSpace;
        fromSpace = m_oldGen.fromSpace;
        blockFilter = &m_oldGen.blockFilter;
    } else {
        toSpace = m_newGen.toSpace;
        fromSpace = m_newGen.fromSpace;
        blockFilter = &m_newGen.blockFilter;
    }

    while (!fromSpace->isEmpty()) {
        CopiedBlock* block = fromSpace->removeHead();
        // We don't add the block to the blockSet because it was never removed.
        ASSERT(m_blockSet.contains(block));
        blockFilter->add(reinterpret_cast<Bits>(block));
        toSpace->push(block);
    }

    if (heap()->operationInProgress() == EdenCollection) {
        m_oldGen.toSpace->append(*m_newGen.toSpace);
        m_oldGen.oversizeBlocks.append(m_newGen.oversizeBlocks);
        m_oldGen.blockFilter.add(m_newGen.blockFilter);
        m_newGen.blockFilter.reset();
    }

    ASSERT(m_newGen.toSpace->isEmpty());
    ASSERT(m_newGen.fromSpace->isEmpty());
    ASSERT(m_newGen.oversizeBlocks.isEmpty());

    allocateBlock();

    m_shouldDoCopyPhase = false;
}
Ejemplo n.º 3
0
void MarkedSpace::shrink()
{
    // We record a temporary list of empties to avoid modifying m_blocks while iterating it.
    DoublyLinkedList<MarkedBlock> empties;

    BlockIterator end = m_blocks.end();
    for (BlockIterator it = m_blocks.begin(); it != end; ++it) {
        MarkedBlock* block = *it;
        if (block->isEmpty()) {
            SizeClass& sizeClass = sizeClassFor(block->cellSize());
            sizeClass.blockList.remove(block);
            sizeClass.nextBlock = sizeClass.blockList.head();
            empties.append(block);
        }
    }
    
    freeBlocks(empties);
    ASSERT(empties.isEmpty());
}
Ejemplo n.º 4
0
int main()
{
	DoublyLinkedList *ls = new DoublyLinkedList();
	ls->push_back(*(new ListNode("100")));
	ListNode *n1 = new ListNode("5");
	ls->push_front(*n1);
	ls->push_front(*(new ListNode("1")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("0")));
	ls->push_back(*(new ListNode("1sdsd")));
	ls->print();
	cout << "\n";
	ls->print_bkw();
	cout << "\nLink list size is equal to " << ls->size() << endl;
	cout << "\n";
	cout << "Lets delete first and last nodes from list\n";
	ls->pop_back();
	ls->pop_front();
	ls->print();
	cout << "\nNow lets erase 4, 1 and 100: \n";
	ls->erase("4");
	ls->erase("1");
	ls->erase("100");
	ls->print();
	cout << "\nLets insert '6' after '3' and '7' after '5': \n";
	ls->insert_after("3", *(new ListNode("6")));
	ls->insert_after("5", *(new ListNode("7")));
	ls->print();
	cout << "\nLets clear linked list (check this with 'isEmpty' method): \n";
	ls->clear();
	if (ls->isEmpty())
		cout << "Our list is empty! \n";
	cout << "\nLets get new list: \n";
	ls->push_front(*(new ListNode("6")));
	ls->push_front(*(new ListNode("31")));
	ls->push_front(*(new ListNode("55")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("1")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("8"))); 
	ls->push_front(*(new ListNode("5")));
	ls->push_front(*(new ListNode("0")));
	ls->print();
	cout << "\nOur new sorted list: \n";
	ls->sort();
	ls->print();
	cout << "\nLets delete unique elements: \n";
	ls->unique();
	ls->print();
	cout << "\nLets insert '0', '2', '7' and '9' preserving list ordering: \n";
	ls->insert_ord(*(new ListNode("0")));
	ls->insert_ord(*(new ListNode("2")));
	ls->insert_ord(*(new ListNode("7")));
	ls->insert_ord(*(new ListNode("9")));
	ls->print();

	cout << "\nLets get new list 'temp_ls': \n";
	DoublyLinkedList *temp_ls = new DoublyLinkedList();
	temp_ls->push_front(*(new ListNode("b")));
	temp_ls->push_front(*(new ListNode("v")));
	temp_ls->push_front(*(new ListNode("a")));
	temp_ls->push_front(*(new ListNode("d")));
	temp_ls->print();
	cout << "\nLets 'merge' our lists (temp_ls in ls): \n";
	ls->merge(*temp_ls);
	ls->print();
	if (temp_ls->isEmpty())
		cout << "Our 'temp_ls' list is empty! \n";
	cout << "\nLets get new lists: \n";
	ls->clear();
	ls->push_front(*(new ListNode("6")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("5")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("1")));
	cout << "New 'ls': ";
	ls->print();
	temp_ls->push_front(*(new ListNode("b")));
	temp_ls->push_front(*(new ListNode("v")));
	temp_ls->push_front(*(new ListNode("a")));
	temp_ls->push_front(*(new ListNode("d")));
	cout << "New 'temp_ls': ";
	temp_ls->print();
	cout << "\nLets assign 'ls' to 'temp_ls' from 1 to 3: \n";
	ls->assign(*temp_ls, 1, 3);
	cout << "New 'ls': ";
	ls->print();
	cout << "New 'temp_ls': ";
	temp_ls->print();
	cout << "\nLets splice 'temp_ls' in 'ls' from index 3 with all list:\n ";
	ls->splice(3, *temp_ls);
	ls->print();
	ls->clear();
	temp_ls->clear();
	ls->push_front(*(new ListNode("6")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("5")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("1")));
	cout << "\nlets get new lists: \nNew 'ls': ";
	ls->print();
	temp_ls->push_front(*(new ListNode("b")));
	temp_ls->push_front(*(new ListNode("v")));
	temp_ls->push_front(*(new ListNode("b")));
	temp_ls->push_front(*(new ListNode("d")));
	cout << "New 'temp_ls': ";
	temp_ls->print();
	cout << "\nLets splice 'temp_ls' in 'ls' from index 2 from 1 to 2: ";
	ls->splice(2, *temp_ls, 1, 2);
	ls->print();
	
	return 0;
}