<ply-base.h>
namespace ply
Generic Algorithms

Plywood provides generic algorithms that work with any array-like container. These are template functions that operate on Array, ArrayView, FixedArray, and other compatible types.

s32 find(const AnyArray& arr, const Key& key)
s32 reverse_find(const AnyArray& arr, const Key& key)
void sort(AnyArray& arr)
u32 binary_search(const AnyArray& arr, const Key& key, FindType find_type)
s32 find(const AnyArrayarr,  const Keykey)

Performs a linear search from the beginning of the array. Returns the index of the first matching item, or -1 if not found.

s32 reverse_find(const AnyArrayarr,  const Keykey)

Performs a linear search from the end of the array. Returns the index of the last matching item, or -1 if not found.

void sort(AnyArrayarr)

Sorts the array in ascending order. Items are compared using operator<.

u32 binary_search(const AnyArrayarr,  const Keykey,  FindType find_type)

Performs a binary search on a sorted array. Returns the index of a matching item based on the find_type parameter. The array must already be sorted.

FindGreaterThanReturns the first item strictly greater than key
FindGreaterThanOrEqualReturns the first item greater than or equal to key
Example
Array<int> numbers = {5, 2, 8, 1, 9};
sort(numbers);  // numbers is now {1, 2, 5, 8, 9}

s32 idx = find(numbers, 5);  // idx is 2
u32 pos = binary_search(numbers, 6, FindGreaterThan);  // pos is 3 (points to 8)