Added main TODOs in main(), regarding setting up threadpool, dispatches, consolidation, process return value on match fails, etc. Fortune for naka's current commit: Small blessing − 小吉master
parent
b694d73167
commit
254d9fbadc
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef _COMP_H
|
||||||
|
#define _COMP_H
|
||||||
|
|
||||||
|
#include <macros.h>
|
||||||
|
#include <ints.h>
|
||||||
|
|
||||||
|
/// Find `needle` in `haystack`, sets the start of `needle`'s `origin` in `haystack`'s to `pos` and returns `true` if a match is found, otherwise returns false.
|
||||||
|
bool cmp_find(const map_t *pIN needle, const map_t *pIN haystack, usize *pOUT pos);
|
||||||
|
/// Check `needle` against `nhaystacks` number of haystack maps, store the offset in `sizes[n]` where `n` is the haystack number.
|
||||||
|
/// `sizes` must be at least `nhaystacks` long. The haystacks themselves are expected to be of type `const map_t* pIN`
|
||||||
|
/// Returns `-1` if all haystacks passed match, otherwise returns the index of the haystack that failed.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
/// Will `FATAL` if any of the haystack pointers are `NULL`
|
||||||
|
int cmp_find_many(usize nhaystacks; const map_t *pIN needle, usize sizes[pOUT nhaystacks], usize nhaystacks, ...);
|
||||||
|
|
||||||
|
#endif /* _COMP_H */
|
@ -0,0 +1,38 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <macros.h>
|
||||||
|
#include <ints.h>
|
||||||
|
#include <map.h>
|
||||||
|
|
||||||
|
|
||||||
|
bool cmp_find(const map_t *pIN needle, const map_t *pIN haystack, usize *pOUT pos)
|
||||||
|
{
|
||||||
|
u8* start;
|
||||||
|
u8* substr = memmem(start = haystack->origin, haystack->len,
|
||||||
|
needle->origin, needle->len);
|
||||||
|
if(!substr) return false;
|
||||||
|
debug_assert(substr > start);
|
||||||
|
*pos = (usize) (substr - start);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmp_find_many(usize nhaystacks; const map_t *pIN needle, usize sizes[pOUT nhaystacks], usize nhaystacks, ...)
|
||||||
|
{
|
||||||
|
va_list v_haystacks;
|
||||||
|
va_start(v_haystacks, nhaystacks);
|
||||||
|
|
||||||
|
const map_t* pINOUT haystack;
|
||||||
|
for(usize i=0;i<nhaystacks;i++)
|
||||||
|
{
|
||||||
|
usize *pOUT size = sizes + i;
|
||||||
|
haystack = va_arg(v_haystacks, const map_t* pIN);
|
||||||
|
if(!haystack || !haystack->origin) FATAL("haystack %lu was null or its origin was null", i);
|
||||||
|
if(!cmp_find(needle, haystack, size)) return (int)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(v_haystacks);
|
||||||
|
return -1;
|
||||||
|
}
|
Loading…
Reference in new issue