Fix setting hash size in the config for b3g. Part of fix for bug #222.

remotes/origin/master-1.1.x
Victor Julien 15 years ago
parent e47a9b59e9
commit b8a709cbe7

@ -49,8 +49,12 @@
static uint32_t b3g_hash_size = 0;
static uint32_t b3g_bloom_size = 0;
static uint8_t b3g_hash_shift = 0;
static uint8_t b3g_hash_shift2 = 0;
static void *b3g_func;
#define B3G_HASH(a,b,c) (((a) << b3g_hash_shift) | (b) << (b3g_hash_shift2) |(c))
void B3gInitCtx (MpmCtx *, int);
void B3gThreadInitCtx(MpmCtx *, MpmThreadCtx *, uint32_t);
void B3gDestroyCtx(MpmCtx *);
@ -419,7 +423,7 @@ static void B3gPrepareHash(MpmCtx *mpm_ctx) {
}
ctx->pat_1_cnt++;
} else if(ctx->parray[i]->len == 2) {
idx = (uint16_t)(ctx->parray[i]->ci[0] << B3G_HASHSHIFT | ctx->parray[i]->ci[1]);
idx = (uint16_t)(ctx->parray[i]->ci[0] << b3g_hash_shift | ctx->parray[i]->ci[1]);
if (ctx->hash2[idx] == NULL) {
B3gHashItem *hi = B3gAllocHashItem(mpm_ctx);
if (hi == NULL)
@ -676,8 +680,35 @@ void B3gGetConfig()
}
}
if (hash_val != NULL)
if (hash_val != NULL) {
b3g_hash_size = MpmGetHashSize(hash_val);
switch (b3g_hash_size) {
case HASHSIZE_LOWEST:
b3g_hash_shift = B3G_HASHSHIFT_LOWEST;
b3g_hash_shift2 = B3G_HASHSHIFT_LOWEST2;
break;
case HASHSIZE_LOW:
b3g_hash_shift = B3G_HASHSHIFT_LOW;
b3g_hash_shift2 = B3G_HASHSHIFT_LOW2;
break;
case HASHSIZE_MEDIUM:
b3g_hash_shift = B3G_HASHSHIFT_MEDIUM;
b3g_hash_shift2 = B3G_HASHSHIFT_MEDIUM2;
break;
case HASHSIZE_HIGH:
b3g_hash_shift = B3G_HASHSHIFT_HIGH;
b3g_hash_shift2 = B3G_HASHSHIFT_HIGH2;
break;
case HASHSIZE_HIGHEST:
b3g_hash_shift = B3G_HASHSHIFT_HIGHEST;
b3g_hash_shift2 = B3G_HASHSHIFT_HIGHEST2;
break;
case HASHSIZE_MAX:
b3g_hash_shift = B3G_HASHSHIFT_MAX;
b3g_hash_shift2 = B3G_HASHSHIFT_MAX2;
break;
}
}
if (bloom_val != NULL)
b3g_bloom_size = MpmGetBloomSize(bloom_val);
@ -1061,7 +1092,7 @@ uint32_t B3gSearch12(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatch
if (buf != bufend) {
/* save one conversion by reusing h8 */
uint16_t h16 = (uint16_t)(h8 << B3G_HASHSHIFT | u8_tolower(*(buf+1)));
uint16_t h16 = (uint16_t)(h8 << b3g_hash_shift | u8_tolower(*(buf+1)));
hi = ctx->hash2[h16];
for (thi = hi; thi != NULL; thi = thi->nxt) {
@ -1105,7 +1136,7 @@ uint32_t B3gSearch2(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatche
//printf("BUF "); prt(buf,buflen); printf("\n");
while (buf <= bufend) {
uint16_t h = u8_tolower(*buf) << B3G_HASHSHIFT | u8_tolower(*(buf+1));
uint16_t h = u8_tolower(*buf) << b3g_hash_shift | u8_tolower(*(buf+1));
hi = ctx->hash2[h];
if (hi != NULL) {

@ -27,11 +27,18 @@
#include "util-mpm.h"
#include "util-bloomfilter.h"
//#define B3G_HASHSHIFT 8
//#define B3G_HASHSHIFT 7
//#define B3G_HASHSHIFT 6
//#define B3G_HASHSHIFT 5
#define B3G_HASHSHIFT 4
#define B3G_HASHSHIFT_MAX 8
#define B3G_HASHSHIFT_MAX2 5
#define B3G_HASHSHIFT_HIGHEST 7
#define B3G_HASHSHIFT_HIGHEST2 4
#define B3G_HASHSHIFT_HIGH 6
#define B3G_HASHSHIFT_HIGH2 3
#define B3G_HASHSHIFT_MEDIUM 5
#define B3G_HASHSHIFT_MEDIUM2 2
#define B3G_HASHSHIFT_LOW 4
#define B3G_HASHSHIFT_LOW2 1
#define B3G_HASHSHIFT_LOWEST 3
#define B3G_HASHSHIFT_LOWEST2 1
#define B3G_TYPE uint32_t
//#define B3G_TYPE uint16_t
@ -40,7 +47,6 @@
//#define B3G_WORD_SIZE 8
#define B3G_WORD_SIZE 32
#define B3G_HASH(a,b,c) (((a)<<B3G_HASHSHIFT) | (b)<<(B3G_HASHSHIFT-3) |(c))
#define B3G_Q 3
//#define B3G_SEARCHFUNC B3gSearch

Loading…
Cancel
Save