pike.git/
src/
block_alloc.h
Branch:
Tag:
Non-build tags
All tags
No tags
2001-07-04
2001-07-04 07:02:09 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>
be759ea202b06330f84db261e3d7de6ad17fa5c8 (
27
lines) (+
14
/-
13
)
[
Show
|
Annotate
]
Branch:
7.2
saner hashing
Rev: src/block_alloc.h:1.28
Rev: src/block_alloc_h.h:1.9
1:
-
/* $Id: block_alloc.h,v 1.
27
2000
/
12
/
05
21
:
08
:
15
per
Exp $ */
+
/* $Id: block_alloc.h,v 1.
28
2001
/
07
/
04
07
:
02
:
09
hubbe
Exp $ */
#undef PRE_INIT_BLOCK #undef INIT_BLOCK #undef EXIT_BLOCK
113:
BLOCK_ALLOC(DATA,BSIZE) \ \ struct DATA **PIKE_CONCAT(DATA,_hash_table)=0; \
-
ptrdiff
_t PIKE_CONCAT(DATA,_hash_table_size)=0; \
-
static
ptrdiff
_t PIKE_CONCAT(num_,DATA)=0;
\
+
size
_t PIKE_CONCAT(DATA,_hash_table_size)=0;
\
+
static
size
_t PIKE_CONCAT(num_,DATA)=0; \
\ inline struct DATA * \
-
PIKE_CONCAT(really_low_find_,DATA)(void *ptr,
ptrdiff
_t hval) \
+
PIKE_CONCAT(really_low_find_,DATA)(void *ptr,
size
_t hval)
\
{ \ struct DATA *p,**pp; \ p=PIKE_CONCAT(DATA,_hash_table)[hval]; \
151:
/* Time to re-hash */ \ struct DATA **old_hash= PIKE_CONCAT(DATA,_hash_table); \ struct DATA *p; \
-
ptrdiff
_t hval;
\
-
ptrdiff
_t e=PIKE_CONCAT(DATA,_hash_table_size);
\
+
size
_t hval; \
+
size
_t e=PIKE_CONCAT(DATA,_hash_table_size); \
\ PIKE_CONCAT(DATA,_hash_table_size)*=2; \ PIKE_CONCAT(DATA,_hash_table_size)++; \
162:
{ \ MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \ sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \
-
while(--
e
>
=
0) \
+
while(
e
-- >
0) \
{ \ while((p=old_hash[e])) \ { \ old_hash[e]=p->BLOCK_ALLOC_NEXT; \
-
hval=(
ptrdiff
_t)(p->data);
\
+
hval=(
size
_t)(p->data); \
hval%=PIKE_CONCAT(DATA,_hash_table_size); \ p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \ PIKE_CONCAT(DATA,_hash_table)[hval]=p; \
181:
} \ \ \
-
struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr,
ptrdiff
_t hval) \
+
struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr,
size
_t hval)
\
{ \ struct DATA *p; \ \
193:
PIKE_CONCAT(DATA,_hash_table_size)) \ { \ PIKE_CONCAT(DATA,_rehash)(); \
-
hval=(
ptrdiff
_t)ptr;
\
+
hval=(
size
_t)ptr; \
hval%=PIKE_CONCAT(DATA,_hash_table_size); \ } \ \
207:
struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr) \ { \ struct DATA *p; \
-
ptrdiff
_t hval=(
ptrdiff
_t)ptr;
\
+
size
_t hval=(
size
_t)ptr; \
hval%=PIKE_CONCAT(DATA,_hash_table_size); \ if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ return p; \
218:
int PIKE_CONCAT3(check_,DATA,_semafore)(void *ptr) \ { \ struct DATA *p; \
-
ptrdiff
_t hval=(
ptrdiff
_t)ptr;
\
+
size
_t hval=(
size
_t)ptr; \
hval%=PIKE_CONCAT(DATA,_hash_table_size); \ if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ return 0; \
230:
int PIKE_CONCAT(remove_,DATA)(void *ptr) \ { \ struct DATA *p; \
-
ptrdiff
_t hval=(
ptrdiff
_t)ptr;
\
+
size
_t hval=(
size
_t)ptr; \
if(!PIKE_CONCAT(DATA,_hash_table)) return 0; \ hval%=PIKE_CONCAT(DATA,_hash_table_size); \ if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \