cgul_heap_sort_cxx Class Reference

C++ bindings for cgul_heap_sort More...

#include <cgul_heap_sort_cxx.h>

Collaboration diagram for cgul_heap_sort_cxx:
Collaboration graph

Static Public Member Functions

static void sort (void *v, size_t v_count, size_t element_size, cgul_heap_primitives_cxx::compare_t cf)
 
static void sort_pointers (void **v, size_t v_count, cgul_heap_primitives_cxx::compare_t cf)
 

Detailed Description

This class provides the C++ bindings for cgul_heap_sort. The main purpose of this class is to convert the C-style function calls and exception handling into C++-style function calls and exception handling.

Member Function Documentation

§ sort()

static void cgul_heap_sort_cxx::sort ( void *  v,
size_t  v_count,
size_t  element_size,
cgul_heap_primitives_cxx::compare_t  cf 
)
inlinestatic

Generic in-place sort with the same parameter signature as stdlib's qsort(). v is a pointer to the top of your array. v_count is the number of elements in v. element_size is the number of contiguous bytes that comprise each element. cf is the comparison function. It will be passed pointers to two elements. It must return less than zero, zero, or greater than zero if the first element is less than, equal to, or greater than the second element. As explained in the next paragraph, this function has to internally allocate memory to perform its task. If out-of-memory occurs, an exception is thrown.

One of the main reasons for using heap sort is that it requires no extra space, but this function creates an extra copy of v and another array of pointers that gets passed to cgul_heap_sort_pointers(). So, if the reason for using heap sort is to conserve space, client code should be organized around arrays of pointers that can be passed directly to cgul_heap_sort_pointers().

If you need to constantly maintain a sorted list, cgul_rbtree or cgul_multimap are usually better solutions.

Parameters
[in]varray of elements to sort
[in]v_countnumber of elements in v
[in]element_sizesize of each element in v (in bytes)
[in]cfcomparison function

References cgul_heap_sort().

§ sort_pointers()

static void cgul_heap_sort_cxx::sort_pointers ( void **  v,
size_t  v_count,
cgul_heap_primitives_cxx::compare_t  cf 
)
inlinestatic

If your array is already composed of pointers, you can directly call this function. v will be sorted using cf the same as described for cgul_heap_sort() except this function operates without require any extra space (other than O(log n) stack consumption).

If you need to constantly maintain a sorted list, cgul_rbtree or cgul_multimap are usually better solutions.

Parameters
[in]varray of pointers to elements to sort
[in]v_countnumber of elements in v
[in]cfcomparison function

References cgul_heap_sort_pointers().


The documentation for this class was generated from the following file: