Rose: use a multibit for the exhaustion vector

Previously, the exhaustion vector was a standard bitvector, which
required an expensive memset() call at init for databases with a large
number of exhaustion keys.
This commit is contained in:
Justin Viiret
2016-04-04 16:04:28 +10:00
committed by Matthew Barr
parent 1fcd3cfb2c
commit f2c0a66b6f
5 changed files with 27 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -34,8 +34,8 @@
#define EXHAUST_H
#include "rose/rose_internal.h"
#include "util/multibit.h"
#include "ue2common.h"
#include <string.h>
/** \brief Sentinel value meaning no further exhaustion keys. */
#define END_EXHAUST (~(u32)0)
@@ -43,56 +43,36 @@
/** \brief Test whether the given key (\a eoff) is set in the exhaustion vector
* \a evec. */
static really_inline
int isExhausted(const char *evec, u32 eoff) {
int isExhausted(const struct RoseEngine *t, const char *evec, u32 eoff) {
DEBUG_PRINTF("checking exhaustion %p %u\n", evec, eoff);
return eoff != END_EXHAUST && (evec[eoff >> 3] & (1 << (eoff % 8)));
return eoff != END_EXHAUST &&
mmbit_isset((const u8 *)evec, t->ekeyCount, eoff);
}
/** \brief Returns 1 if all exhaustion keys in the bitvector are on. */
static really_inline
int isAllExhausted(const struct RoseEngine *t, const char *evec_in) {
int isAllExhausted(const struct RoseEngine *t, const char *evec) {
if (!t->canExhaust) {
return 0; /* pattern set is inexhaustible */
}
const u8 *evec = (const u8 *)evec_in;
u32 whole_bytes = t->ekeyCount / 8;
for (u32 i = 0; i < whole_bytes; i++) {
if (evec[i] != 0xff) {
DEBUG_PRINTF("unexhausted pattern in byte %u\n", i);
return 0;
}
}
u32 rem = t->ekeyCount % 8;
if (t->ekeyCount % 8) {
u8 mask = (1 << rem) - 1;
if (evec[whole_bytes] != (char)mask) {
DEBUG_PRINTF("unexhausted pattern (%hhu) in final byte\n", mask);
return 0;
}
}
DEBUG_PRINTF("pattern set is exhausted\n");
return 1;
return mmbit_all((const u8 *)evec, t->ekeyCount);
}
/** \brief Mark key \a eoff on in the exhaustion vector. */
static really_inline
void markAsMatched(char *evec, u32 eoff) {
void markAsMatched(const struct RoseEngine *t, char *evec, u32 eoff) {
if (eoff != END_EXHAUST) {
DEBUG_PRINTF("marking as exhausted key %u\n", eoff);
evec[eoff >> 3] |= 1 << (eoff % 8);
mmbit_set((u8 *)evec, t->ekeyCount, eoff);
}
}
/** \brief Clear all keys in the exhaustion vector. */
static really_inline
void clearEvec(char *ev, const struct RoseEngine *t) {
size_t size = (t->ekeyCount + 7) / 8;
DEBUG_PRINTF("clearing evec %p %zu\n", ev, size);
memset(ev, 0, size);
void clearEvec(char *evec, const struct RoseEngine *t) {
DEBUG_PRINTF("clearing evec %p %u\n", evec, t->ekeyCount);
mmbit_clear((u8 *)evec, t->ekeyCount);
}
#endif