mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-02-02 22:07:05 -03:00
option to use big-endian sorting for intfilter binsearch case
This commit is contained in:
parent
5bc2b09504
commit
39b173aa3d
2 changed files with 55 additions and 14 deletions
10
configure.ac
10
configure.ac
|
@ -215,6 +215,16 @@ then
|
||||||
MYDEFS="$MYDEFS -DBINSEARCH"
|
MYDEFS="$MYDEFS -DBINSEARCH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE([besort],
|
||||||
|
[AS_HELP_STRING([--enable-besort],
|
||||||
|
[force intfilter binsearch case to use big endian sorting and not omit masks from filters; useful if your filters aren't of same length @<:@default=no@:>@])],
|
||||||
|
[], [enable_besort=no]
|
||||||
|
)
|
||||||
|
if test "x$enable_besort" = "xyes"
|
||||||
|
then
|
||||||
|
MYDEFS="$MYDEFS -DBESORT"
|
||||||
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE([statistics],
|
AC_ARG_ENABLE([statistics],
|
||||||
[AS_HELP_STRING([--enable-statistics],
|
[AS_HELP_STRING([--enable-statistics],
|
||||||
[collect statistics @<:@default=yes@:>@])],
|
[collect statistics @<:@default=yes@:>@])],
|
||||||
|
|
59
main.c
59
main.c
|
@ -66,6 +66,15 @@ static void termhandler(int sig)
|
||||||
|
|
||||||
// filters stuff
|
// filters stuff
|
||||||
|
|
||||||
|
#ifdef INTFILTER
|
||||||
|
#ifdef BINSEARCH
|
||||||
|
#ifndef BESORT
|
||||||
|
#define OMITMASK
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef BINFILTERLEN
|
#ifndef BINFILTERLEN
|
||||||
#define BINFILTERLEN PUBLIC_LEN
|
#define BINFILTERLEN PUBLIC_LEN
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,14 +87,14 @@ struct binfilter {
|
||||||
#ifdef INTFILTER
|
#ifdef INTFILTER
|
||||||
struct intfilter {
|
struct intfilter {
|
||||||
IFT f;
|
IFT f;
|
||||||
#ifndef BINSEARCH
|
# ifndef OMITMASK
|
||||||
IFT m;
|
IFT m;
|
||||||
#endif
|
# endif
|
||||||
} ;
|
} ;
|
||||||
VEC_STRUCT(ifiltervec,struct intfilter) ifilters;
|
VEC_STRUCT(ifiltervec,struct intfilter) ifilters;
|
||||||
#ifdef BINSEARCH
|
# ifdef OMITMASK
|
||||||
IFT ifiltermask;
|
IFT ifiltermask;
|
||||||
#endif // BINSEARCH
|
# endif // BINSEARCH
|
||||||
#else // INTFILTER
|
#else // INTFILTER
|
||||||
VEC_STRUCT(bfiltervec,struct binfilter) bfilters;
|
VEC_STRUCT(bfiltervec,struct binfilter) bfilters;
|
||||||
#endif // INTFILTER
|
#endif // INTFILTER
|
||||||
|
@ -106,7 +115,7 @@ static void filter_sort(int (*compf)(const void *,const void *))
|
||||||
qsort(&VEC_BUF(ifilters,0),VEC_LENGTH(ifilters),sizeof(struct intfilter),compf);
|
qsort(&VEC_BUF(ifilters,0),VEC_LENGTH(ifilters),sizeof(struct intfilter),compf);
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef BINSEARCH
|
# ifdef OMITMASK
|
||||||
|
|
||||||
static int filter_compare(const void *p1,const void *p2)
|
static int filter_compare(const void *p1,const void *p2)
|
||||||
{
|
{
|
||||||
|
@ -236,7 +245,7 @@ static inline void ifilter_addflatten(struct intfilter *ifltr,IFT mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# else // BINSEARCH
|
# else // OMITMASK
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* struct intfilter layout: filter,mask
|
* struct intfilter layout: filter,mask
|
||||||
|
@ -251,7 +260,7 @@ static int filter_compare(const void *p1,const void *p2)
|
||||||
return memcmp(p1,p2,sizeof(struct intfilter));
|
return memcmp(p1,p2,sizeof(struct intfilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
# endif // BINSEARCH
|
# endif // OMITMASK
|
||||||
#else // INTFILTER
|
#else // INTFILTER
|
||||||
|
|
||||||
static void filter_sort(int (*compf)(const void *,const void *))
|
static void filter_sort(int (*compf)(const void *,const void *))
|
||||||
|
@ -324,15 +333,15 @@ static void filters_add(const char *filter)
|
||||||
fc.i &= mc.i;
|
fc.i &= mc.i;
|
||||||
struct intfilter ifltr = {
|
struct intfilter ifltr = {
|
||||||
.f = fc.i,
|
.f = fc.i,
|
||||||
# ifndef BINSEARCH
|
# ifndef OMITMASK
|
||||||
.m = mc.i,
|
.m = mc.i,
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
# ifdef BINSEARCH
|
# ifdef OMITMASK
|
||||||
ifilter_addflatten(&ifltr,mc.i);
|
ifilter_addflatten(&ifltr,mc.i);
|
||||||
# else // BINSEARCH
|
# else // OMITMASK
|
||||||
VEC_ADD(ifilters,ifltr);
|
VEC_ADD(ifilters,ifltr);
|
||||||
# endif // BINSEARCH
|
# endif // OMITMASK
|
||||||
#else // INTFILTER
|
#else // INTFILTER
|
||||||
VEC_ADD(bfilters,bf);
|
VEC_ADD(bfilters,bf);
|
||||||
#endif // INTFILTER
|
#endif // INTFILTER
|
||||||
|
@ -390,6 +399,8 @@ static size_t filters_count()
|
||||||
|
|
||||||
# else // BINSEARCH
|
# else // BINSEARCH
|
||||||
|
|
||||||
|
# ifdef OMITMASK
|
||||||
|
|
||||||
#define DOFILTER(it,pk,code) { \
|
#define DOFILTER(it,pk,code) { \
|
||||||
register IFT maskedpk = *(IFT *)(pk) & ifiltermask; \
|
register IFT maskedpk = *(IFT *)(pk) & ifiltermask; \
|
||||||
for (size_t down = 0,up = VEC_LENGTH(ifilters);down < up;) { \
|
for (size_t down = 0,up = VEC_LENGTH(ifilters);down < up;) { \
|
||||||
|
@ -405,6 +416,26 @@ static size_t filters_count()
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# else // OMITMASK
|
||||||
|
|
||||||
|
#define DOFILTER(it,pk,code) { \
|
||||||
|
for (size_t down = 0,up = VEC_LENGTH(ifilters);down < up;) { \
|
||||||
|
it = (up + down) / 2; \
|
||||||
|
IFT maskedpk = *(IFT *)(pk) & VEC_BUF(ifilters,it).m; \
|
||||||
|
register int cmp = memcmp(&maskedpk,&VEC_BUF(ifilters,it).f,sizeof(IFT)); \
|
||||||
|
if (cmp < 0) \
|
||||||
|
up = it; \
|
||||||
|
else if (cmp > 0) \
|
||||||
|
down = it + 1; \
|
||||||
|
else { \
|
||||||
|
code; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
# endif // OMITMASK
|
||||||
|
|
||||||
# endif // BINSEARCH
|
# endif // BINSEARCH
|
||||||
|
|
||||||
#else // INTFILTER
|
#else // INTFILTER
|
||||||
|
@ -507,11 +538,11 @@ static void filters_print()
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
u8 *imraw;
|
u8 *imraw;
|
||||||
|
|
||||||
#ifndef BINSEARCH
|
# ifndef OMITMASK
|
||||||
imraw = (u8 *)&VEC_BUF(ifilters,i).m;
|
imraw = (u8 *)&VEC_BUF(ifilters,i).m;
|
||||||
#else
|
# else
|
||||||
imraw = (u8 *)&ifiltermask;
|
imraw = (u8 *)&ifiltermask;
|
||||||
#endif
|
# endif
|
||||||
while (len < sizeof(IFT) && imraw[len] != 0x00) ++len;
|
while (len < sizeof(IFT) && imraw[len] != 0x00) ++len;
|
||||||
u8 mask = imraw[len-1];
|
u8 mask = imraw[len-1];
|
||||||
u8 *ifraw = (u8 *)&VEC_BUF(ifilters,i).f;
|
u8 *ifraw = (u8 *)&VEC_BUF(ifilters,i).f;
|
||||||
|
|
Loading…
Add table
Reference in a new issue