/* The StringZilla subset Louise binds (packages/stringzilla), in the * dialect `louise bindgen` reads: plain C99 types, a string is a * `const char *` followed by its length, offsets are `int64_t` (-1: not * found), and the sort's state is an opaque struct with a finalizer. * StringZilla's own headers are not bindgen input: their declarations * rely on macros (`SZ_DYNAMIC`) and typedefs (`sz_cptr_t`), and `sz_find` * returns a pointer, which bindings cannot convert. * * Implemented by api.c over the vendored StringZilla (vendor/); the * bindings are generated from this file and checked in: * * louise bindgen csrc/api.h --lse src/bindings.lse --c csrc/bindings.c */ #ifndef LOUISE_STRINGZILLA_API_H #define LOUISE_STRINGZILLA_API_H #include #include #include #ifdef __cplusplus extern "C" { #endif /* The byte offset of `needle`'s first occurrence in `haystack`, or -1. * An empty needle matches at 0. */ int64_t szl_find(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len); /* The byte offset of `needle`'s last occurrence in `haystack`, or -1. * An empty needle matches at `haystack_len`. */ int64_t szl_rfind(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len); /* The non-overlapping occurrences of `needle` in `haystack`; an empty * needle matches at every gap: `haystack_len + 1`. */ size_t szl_count(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len); /* The byte offset of the first byte of `s` equal to `byte`, or -1. */ int64_t szl_find_byte(const char *s, size_t len, uint8_t byte); /* The byte offset of the last byte of `s` equal to `byte`, or -1. */ int64_t szl_rfind_byte(const char *s, size_t len, uint8_t byte); /* `a` against `b`, byte-wise: -1, 0 or 1. */ int szl_order(const char *a, size_t a_len, const char *b, size_t b_len); /* The low 63 bits of StringZilla's 64-bit hash of `s` with `seed`. */ int64_t szl_hash(const char *s, size_t len, int64_t seed); /* The low 63 bits of StringZilla's byte-sum sketch of `s`. */ int64_t szl_bytesum(const char *s, size_t len); /* The vendored StringZilla's version: "major.minor.patch". */ const char *szl_version(void); /* The SIMD tiers in use on this machine, e.g. "serial,westmere,haswell". */ const char *szl_capabilities(void); /* Sorting a set of strings by bytes (`sz_sequence_argsort`). The pushed * strings are copied; the copies live until the finalizer. */ typedef struct szl_sort szl_sort; szl_sort *szl_sort_new(void); void szl_sort_free(szl_sort *s); /* Appends a copy of `text`; false if out of memory. */ bool szl_sort_push(szl_sort *s, const char *text, size_t text_len); /* How many strings were pushed. */ size_t szl_sort_count(const szl_sort *s); /* Sorts the pushed strings; false if out of memory. */ bool szl_sort_argsort(szl_sort *s); /* The pushed index of the `i`-th smallest string. Unchecked: `i` must be * below szl_sort_count(s), and szl_sort_argsort must have run. */ int64_t szl_sort_order(const szl_sort *s, size_t i); #ifdef __cplusplus } #endif #endif /* LOUISE_STRINGZILLA_API_H */