SplitState filterCellByUnorderedFunction(PartitionStack* ps, int cell, F f)
{
    // First, gather up counts.
    std::map<int, int> m;

    int cellBegin = ps->cellStartPos(cell);
    int cellEnd = ps->cellEndPos(cell);

    for(int pos = cellBegin; pos < cellEnd; ++pos)
    {
        m[ps->val(pos)]++;
    }

    abort();

    PartitionStack::cellit cellPtrBegin = ps->cellStartPtr(cell);
    PartitionStack::cellit cellPtrEnd = ps->cellEndPtr(cell);
    std::sort(cellPtrBegin, cellPtrEnd, IndirectSorter(f));
    ps->fixCellInverses(cell);


    // Start at the end, because then the cell we pass to
    // split remains the same.


    for(int pos = cellEnd - 2; pos >= cellBegin; --pos)
    {
        if(f(ps->val(pos)) != f(ps->val(pos+1)))
        {
            if(ps->split(cell, pos+1).hasFailed())
                return SplitState(false);
        }
    }
    return SplitState(true);
}
SortEvent filterCellByFunction_noSortData(PartitionStack* ps, int cell, F f)
{
    // Start at the end, because then the cell we pass to
    // split remains the same.

    int cellBegin = ps->cellStartPos(cell);
    int cellEnd = ps->cellEndPos(cell);


    // Cheap pass to check if all cells have the same value
    HashType first_val = f(ps->val(cellBegin));

    bool allequal = true;

    for(int pos = cellBegin + 1; pos < cellEnd && allequal; ++pos)
    {
        if(first_val != (HashType)f(ps->val(pos)))
            allequal = false;
    }

    if(allequal)
    {
        SortEvent se(cellBegin, cellEnd);
        debug_out(3, "filter", "all hashes equal: " + toString(first_val));
        se.addHashStart(f(ps->val(cellBegin)), cellBegin);
        se.finalise();
        return se;
    }

    std::sort(ps->cellStartPtr(cell), ps->cellEndPtr(cell), IndirectSorter(f));
    ps->fixCellInverses(cell);


    int cellsplits = 0;

    SortEvent se(cellBegin, cellEnd);

    for(int pos = cellEnd - 2; pos >= cellBegin; --pos)
    {
        if(f(ps->val(pos)) != f(ps->val(pos+1)))
        {
            se.addHashStart(f(ps->val(pos+1)),pos+1);
            cellsplits++;
            if(ps->split(cell, pos+1).hasFailed())
                abort();
        }
    }

    // Have to have information about the first cell too!
    se.addHashStart(f(ps->val(cellBegin)), cellBegin);

    se.finalise();

    D_ASSERT(cellsplits > 0);
    debug_out(3, "filter",  "Succeeded at: " << cell << ", " << cellsplits << " ( " << (cellEnd - cellBegin) << ", " << cellBegin << ", " << cellEnd << ", " << ps->cellCount() << ")\n");
    return se;
}
Beispiel #3
0
void orderCell(It begin, It end, SearchHeuristic sh, RBase* rbase)
{
    switch(sh)
    {
        case SearchBranch_RBase:
             std::sort(begin, end,
                IndirectSorter(SquareBrackToFunction(&rbase->inv_value_ordering)));
            return;
        case SearchBranch_InvRBase:
             std::sort(begin, end,
                ReverseSorter(IndirectSorter(SquareBrackToFunction(&rbase->inv_value_ordering))));
            return;
        case SearchBranch_Random:
            std::random_shuffle(begin, end);
            return;
        case SearchBranch_Sorted:
            std::sort(begin, end);
            return;
        case SearchBranch_Nosort:
            return;
        default:
            abort();
    }
}
Beispiel #4
0
 // This is here to allow different functions
 // later.
 bool comparison(int i, int j) const
 { return IndirectSorter([&](auto i) -> auto& { return (rb->inv_value_ordering)[i]; })(i, j); }