pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize T: typehaystack: []const Tstart_index: usizeneedle: []const T1465
1466
1467
1468
1469
1470
1471
1472
1473pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
if (needle.len > haystack.len) return null;
var i: usize = start_index;
const end = haystack.len - needle.len;
while (i <= end) : (i += 1) {
if (eql(T, haystack[i..][0..needle.len], needle)) return i;
}
return null;
}
Consider using
findPosinstead of this, which will automatically use a more sophisticated algorithm on larger inputs.