The first byte at or after start, or -1.
#import "Extensions/Byte_Search";
Fast searches for bytes and substrings, with vector instructions. A jaic extension, not official Jai: other Jai compilers have no such module, and it may change between jaic releases. See docs/extensions/byte-search.md.
Byte_Search :: #import "Extensions/Byte_Search";
text := "id,name;note\nneedle in a/haystack";
at := Byte_Search.find(text, #char "\n"); // the first newline, or -1
at = Byte_Search.find_any(text, #char ",", #char ";");
at = Byte_Search.find(text, "needle"); // the first "needle", or -1
at = Byte_Search.find_last(text, #char "/");
// A needle searched for many times: its analysis is done once.
finder := Byte_Search.make_finder("needle");
at = Byte_Search.find(*finder, text, start = at + 1);Show moreShow less
Every search takes start and returns a position in the whole text, or -1. Every search is
linear in the text, including substring search with a needle built to defeat it.
Procedures#
The first of either byte at or after start, or -1.
The last byte before end (-1: the end of the text), or -1.
The last of either byte before end, or -1.
How many times byte occurs in the text.
The first i at or after start where text[i] is in first and text[i + gap] is in second,
or -1. Two rare-ish bytes at a fixed distance pick out far fewer places than either alone.
The same with three sets: text[i] in first, text[i + gap_2] in second, text[i + gap_3] in
third, with gap_3 the largest gap.
Types#
A set of bytes to search for, any number of them. Make it once with make_byte_set.
A needle prepared for searching. It points into the needle, which must outlive it.