------------------------------------------------------------------------------
MC logo
Composite Number Eliminator Implementation
[^] Code Examples
------------------------------------------------------------------------------
<<Composite Number Eliminator Class elim.cc Fast Primes Generator>>
#include "elim.h"
#include <algorithm>

void EliminatorCollection::insert(Integer i)
{
        heap.push_back(Eliminator(i));
        push_heap(heap.begin(), heap.end());
}

void EliminatorCollection::advance()
{
        // Get the current eliminee.
        Integer you_die = eliminates();

        // Get rid of all the nodes which eliminate this same number.
        vector<Eliminator>::iterator heap_end = heap.end();
        while(heap_end != heap.begin() && heap.front().eliminates() == you_die)
        {
                pop_heap(heap.begin(), heap_end);
                --heap_end;
                heap_end->advance();
        }

        // Return them, now advanced, to the heap.
        do
        {
                ++heap_end;
                push_heap(heap.begin(), heap_end);
        }
        while(heap_end != heap.end());
}
void EliminatorCollection::dump()
{
        vector<Eliminator>::iterator scan = heap.begin();
        while(scan != heap.end())
        {
                scan->print();
                cout << endl;
                ++scan;
        }
}
<<Composite Number Eliminator Class Fast Primes Generator>>