Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/container/seadObjArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ObjArray : public PtrArrayImpl
void sort() { sort(compareT); }
void sort(CompareCallback cmp) { PtrArrayImpl::sort<T>(cmp); }
void heapSort() { heapSort(compareT); }
void heapSort(CompareCallback cmp) { PtrArrayImpl::heapSort_<T>(cmp); }
void heapSort(CompareCallback cmp) { PtrArrayImpl::heapSort<T>(cmp); }

bool equal(const ObjArray& other, CompareCallback cmp) const
{
Expand Down
18 changes: 8 additions & 10 deletions include/container/seadPtrArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,15 @@ class PtrArrayImpl

void sort(CompareCallbackImpl cmp);

template <typename T, typename Compare>
void heapSort_(Compare cmp)
template <typename T>
void heapSort(s32 (*cmpT)(const T* a, const T* b))
{
// Note: Nintendo did not use <algorithm>
const auto less_cmp = [&](const void* a, const void* b) {
return cmp(static_cast<const T*>(a), static_cast<const T*>(b)) < 0;
};
std::make_heap(mPtrs, mPtrs + size(), less_cmp);
std::sort_heap(mPtrs, mPtrs + size(), less_cmp);
// Symbols show that `sort()` accepts a `void*` comparer, but needs to receive a `T*`
// comparer in order to match SMO. This overload exists to safely accept a `T*` comparer.
// This cast is UB, but we know that `cmpT` and `cmpVoid` have the same representation.
auto cmpVoid = reinterpret_cast<s32 (*)(const void*, const void*)>(cmpT);
heapSort(cmpVoid);
}

void heapSort(CompareCallbackImpl cmp);

s32 compare(const PtrArrayImpl& other, CompareCallbackImpl cmp) const;
Expand Down Expand Up @@ -256,7 +254,7 @@ class PtrArray : public PtrArrayImpl
void sort() { sort(compareT); }
void sort(CompareCallback cmp) { PtrArrayImpl::sort<T>(cmp); }
void heapSort() { heapSort(compareT); }
void heapSort(CompareCallback cmp) { PtrArrayImpl::heapSort_<T>(cmp); }
void heapSort(CompareCallback cmp) { PtrArrayImpl::heapSort<T>(cmp); }

bool equal(const PtrArray& other, CompareCallback cmp) const
{
Expand Down