Sorting and searching module

Contents

Methods for sorting arrays using either Quick/Merge-sort combo or Radix sort. It also contains simple implementation of binary search, as well as an easy to use API to define your own comparators.

Typedefs

using zpl_compare_proc = int(void const*a, void const*b)

Functions

auto zpl_sort(void* base, zpl_isize count, zpl_isize size, zpl_compare_proc compare_proc) -> void
Perform sorting operation on a memory location with a specified item count and size.
auto zpl_radix_sort_u8(zpl_u8* items, zpl_u8* temp, zpl_isize count) -> void
auto zpl_radix_sort_u16(zpl_u16* items, zpl_u16* temp, zpl_isize count) -> void
auto zpl_radix_sort_u32(zpl_u32* items, zpl_u32* temp, zpl_isize count) -> void
auto zpl_radix_sort_u64(zpl_u64* items, zpl_u64* temp, zpl_isize count) -> void
auto zpl_binary_search(void const* base, zpl_isize count, zpl_isize size, void const* key, zpl_compare_proc compare_proc) -> zpl_isize
Performs binary search on a memory location with specified item count and size.
auto zpl_shuffle(void* base, zpl_isize count, zpl_isize size) -> void
Shuffles a memory.
auto zpl_reverse(void* base, zpl_isize count, zpl_isize size) -> void
Reverses memory's contents.

Variables

int(*)(void const*a, void const*b) i16_cmp
int(*)(void const*a, void const*b) u8_cmp
int(*)(void const*a, void const*b) i32_cmp
int(*)(void const*a, void const*b) i64_cmp
int(*)(void const*a, void const*b) isize_cmp
int(*)(void const*a, void const*b) str_cmp
int(*)(void const*a, void const*b) f32_cmp
int(*)(void const*a, void const*b) f64_cmp

Defines

#define ZPL_COMPARE_PROC(name)
#define ZPL_COMPARE_PROC_PTR(def)
#define zpl_sort_array(array, count, compare_proc)
Sorts an array.
#define zpl_radix_sort(Type)
#define ZPL_RADIX_SORT_PROC(Type)
#define zpl_binary_search_array(array, count, key, compare_proc)
Performs binary search on an array.
#define zpl_shuffle_array(array, count)
#define zpl_reverse_array(array, count)

Define documentation

#define zpl_sort_array(array, count, compare_proc)

Sorts an array.

Uses quick sort for large arrays but insertion sort for small ones.

#define zpl_binary_search_array(array, count, key, compare_proc)

Performs binary search on an array.

Returns index or -1 if not found