# ifndef _COMP_H
# define _COMP_H
# include <macros.h>
# include <ints.h>
# include <slice.h>
typedef struct comp_aggregate {
bool all_matched ;
int idx_first_failure ;
usize num_results ;
struct comp_single_result {
const map_t * _shared mapping ;
bool matched ;
usize slice_start ;
} aggr [ ] ;
} comp_multires_t ;
// Create a `slice_t` from a successful match against `needle`.
_mixin bool comp_slice_of ( const map_t * pIN needle , const struct comp_single_result * pIN match , slice_t * pOUT slice )
{
ifL ( match - > matched ) {
* slice = SLICE ( AS ( match - > mapping - > origin , u8 * ) + match - > slice_start , needle - > len ) ;
return true ;
} else return false ;
}
/// 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 ( const map_t * pIN needle , usize nhaystacks , usize sizes [ pOUT nhaystacks ] , . . . ) ;
// The return value of this function must be `free()`d after use
comp_multires_t * comp_match_all ( map_t * pIN needle , usize nh , map_t hs [ pIN nh ] , bool abort_on_fail ) ;
# endif /* _COMP_H */