• Create Account

### #ActualAlanSmithee

Posted 25 April 2012 - 12:32 PM

Hi Red Ant, thanks for your respons.

See, that was what I thought as well, as you can see from what I said in my original post:

So, as you can see the compare function gets called with valid memory adresses (i think?) but the get_f() (method used for comparison) gets caleld by 0x0 (NULL pointer?)

But then why does it work when I change nothing but the sort to stable_sort? Since the operands are still the same..

I got everything to work just fine though.. And now, after some optimization I am no longer using any sorting method at all, but rather putting objects in the vector in order already on insertion, with this bit of code:

void Logic::push_searchCell(std::vector<std::shared_ptr<SearchCell> > &v, std::shared_ptr<SearchCell> &a)
{
if (v.size() == 0)
{
v.push_back(a);
return;
}

v.insert(v.begin() + sort_searchCells(v, 0, v.size() - 1, a->get_f()), a);
}

//Find an element in vector v by a chosen value via binary search
const short int Logic::sort_searchCells(std::vector<std::shared_ptr<SearchCell> > &v, int start, int stop, int numb)
{
if (start > stop)
{
return start;
}

int mid = (start + stop)/2;

if (numb < v.at(mid)->get_f())
{
return sort_searchCells(v, start, mid-1, numb);
}
else
{
return sort_searchCells(v, mid+1, stop, numb);
}
}

Saved me a few ms on each call to find path and solved any future ?-marks regarding the sorting =)

### #1AlanSmithee

Posted 25 April 2012 - 12:31 PM

Hi Red Ant, thanks for your respons.

See, that was what I thought as well, as you can see from what I said in my original thread:

So, as you can see the compare function gets called with valid memory adresses (i think?) but the get_f() (method used for comparison) gets caleld by 0x0 (NULL pointer?)

But then why does it work when I change nothing but the sort to stable_sort? Since the operands are still the same..

I got everything to work just fine though.. And now, after some optimization I am no longer using any sorting method at all, but rather putting objects in the vector in order already on insertion, with this bit of code:

void Logic::push_searchCell(std::vector<std::shared_ptr<SearchCell> > &v, std::shared_ptr<SearchCell> &a)
{
if (v.size() == 0)
{
v.push_back(a);
return;
}

v.insert(v.begin() + sort_searchCells(v, 0, v.size() - 1, a->get_f()), a);
}

//Find an element in vector v by a chosen value via binary search
const short int Logic::sort_searchCells(std::vector<std::shared_ptr<SearchCell> > &v, int start, int stop, int numb)
{
if (start > stop)
{
return start;
}

int mid = (start + stop)/2;

if (numb < v.at(mid)->get_f())
{
return sort_searchCells(v, start, mid-1, numb);
}
else
{
return sort_searchCells(v, mid+1, stop, numb);
}
}

Saved me a few ms on each call to find path and solved any future ?-marks regarding the sorting =)

PARTNERS