projects
/
rrq
/
rrqmisc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added IP aging
[rrq/rrqmisc.git]
/
htable
/
htable.c
diff --git
a/htable/htable.c
b/htable/htable.c
index c35355da8f1082a9967adec6bec719bcb2d4f602..ce8c8384c35f9e14c479fa92a5fba2259f308300 100644
(file)
--- a/
htable/htable.c
+++ b/
htable/htable.c
@@
-2,8
+2,6
@@
#include <string.h>
#include "htable.h"
#include <string.h>
#include "htable.h"
-#define HOLE ((unsigned char *)1)
-
//// Generic hash table implementation
// Determine the index for a key. On match, it returns the index into
//// Generic hash table implementation
// Determine the index for a key. On match, it returns the index into
@@
-14,21
+12,23
@@
static int htindex(htable *table,unsigned char *key) {
table->data = calloc( 256, sizeof( unsigned char* ) );
table->size = 256;
}
table->data = calloc( 256, sizeof( unsigned char* ) );
table->size = 256;
}
- unsigned int hash = (*table->hashcode)( table, key ) % table->size;
+ unsigned int hash =
+ ( (unsigned int) (*table->hashcode)( table, key ) ) % table->size;
unsigned int i = hash;
int hole = -1;
for ( ;; ) {
unsigned int i = hash;
int hole = -1;
for ( ;; ) {
- unsigned char *x = table->data[ i
++
];
+ unsigned char *x = table->data[ i ];
if ( x == 0 ) {
if ( x == 0 ) {
- return ( hole >= 0 )?
-hole : - (int) i
;
+ return ( hole >= 0 )?
(- hole - 1 ): ( - (int) i - 1 )
;
}
}
- if ( x == HOLE ) {
+ if ( x == H
TH
OLE ) {
if ( hole < 0 ) {
hole = i;
}
} else if ( memcmp( x + table->offset, key, table->esize ) == 0 ) {
if ( hole < 0 ) {
hole = i;
}
} else if ( memcmp( x + table->offset, key, table->esize ) == 0 ) {
- return i
-1
;
+ return i;
}
}
+ i++;
if ( i >= table->size ) {
i = 0;
}
if ( i >= table->size ) {
i = 0;
}
@@
-36,7
+36,7
@@
static int htindex(htable *table,unsigned char *key) {
break;
}
}
break;
}
}
- return -1;
+ return -
hole -
1;
}
// Find the keyed element, and assign the x pointer, or assign 0.
}
// Find the keyed element, and assign the x pointer, or assign 0.
@@
-89,7
+89,7
@@
static unsigned char *htnext(htable *table,int *i) {
unsigned char **e = table->data + table->size;
for ( ; p < e; p++ ) {
(*i) += 1;
unsigned char **e = table->data + table->size;
for ( ; p < e; p++ ) {
(*i) += 1;
- if ( *p != 0 && *p != HOLE ) {
+ if ( *p != 0 && *p != H
TH
OLE ) {
return *p;
}
}
return *p;
}
}
@@
-127,7
+127,7
@@
void htdelete(htable *table,unsigned char *p) {
pthread_mutex_lock( &table->lock );
int i = htindex( table, p + table->offset );
if ( i >= 0 ) {
pthread_mutex_lock( &table->lock );
int i = htindex( table, p + table->offset );
if ( i >= 0 ) {
- table->data[ i ] = HOLE;
+ table->data[ i ] = H
TH
OLE;
table->holes += 1;
if ( table->holes > table->fill / 2 ) {
htrehash( table, table->size );
table->holes += 1;
if ( table->holes > table->fill / 2 ) {
htrehash( table, table->size );
@@
-139,7
+139,7
@@
void htdelete(htable *table,unsigned char *p) {
void htdump(htable *table,void (*dumpitem)(int i,unsigned char *p)) {
int i;
for ( i = 0 ; i < table->size; i++ ) {
void htdump(htable *table,void (*dumpitem)(int i,unsigned char *p)) {
int i;
for ( i = 0 ; i < table->size; i++ ) {
- if ( table->data[ i ] && table->data[ i ] != HOLE ) {
+ if ( table->data[ i ] && table->data[ i ] != H
TH
OLE ) {
dumpitem( i, table->data[ i ] );
}
}
dumpitem( i, table->data[ i ] );
}
}