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, isize count, 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(u8* items, u8* temp, isize count) -> void
auto zpl_radix_sort_u16(u16* items, u16* temp, isize count) -> void
auto zpl_radix_sort_u32(u32* items, u32* temp, isize count) -> void
auto zpl_radix_sort_u64(u64* items, u64* temp, isize count) -> void
auto zpl_binary_search(void const* base, isize count, isize size, void const* key, zpl_compare_proc compare_proc) -> isize
Performs binary search on a memory location with specified item count and size.
auto zpl_shuffle(void* base, isize count, isize size) -> void
Shuffles a memory.
auto zpl_reverse(void* base, isize count, isize size) -> void
Reverses memory's contents.

Variables

int(*)(void const*a, void const*b) zpl_i16_cmp
int(*)(void const*a, void const*b) zpl_u8_cmp
int(*)(void const*a, void const*b) zpl_i32_cmp
int(*)(void const*a, void const*b) zpl_i64_cmp
int(*)(void const*a, void const*b) zpl_isize_cmp
int(*)(void const*a, void const*b) zpl_str_cmp
int(*)(void const*a, void const*b) zpl_f32_cmp
int(*)(void const*a, void const*b) zpl_f64_cmp
int(*)(void const*a, void const*b) zpl_char_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