|
|
| version 1.2, 2001/01/27 12:04:43 | version 1.9, 2001/01/29 20:46:22 |
|---|---|
| Line 11 | Line 11 |
| */ | */ |
| #include "pa_pool.h" | #include "pa_pool.h" |
| #include "pa_threads.h" | |
| void *Hash::Pair::operator new(size_t size, Pool& apool) { | |
| void *Hash::Pair::operator new(size_t size, Pool *apool) { | return apool.malloc(size); |
| return apool->malloc(size); | |
| } | } |
| /* Zend comment: Generated on an Octa-ALPHA 300MHz CPU & 2.5GB RAM monster */ | /* Zend comment: Generated on an Octa-ALPHA 300MHz CPU & 2.5GB RAM monster */ |
| Line 26 uint Hash::sizes[]={ | Line 26 uint Hash::sizes[]={ |
| int Hash::sizes_count= | int Hash::sizes_count= |
| sizeof(sizes)/sizeof(uint); | sizeof(sizes)/sizeof(uint); |
| void *Hash::operator new(size_t size, Pool *apool) { | void *Hash::operator new(size_t size, Pool& apool) { |
| return apool->malloc(size); | return apool.malloc(size); |
| } | } |
| Hash::Hash(Pool *apool) { | Hash::Hash(Pool& apool, bool athread_safe) : |
| pool=apool; | pool(apool), |
| thread_safe(athread_safe) { | |
| size=sizes[size_index=0]; | size=sizes[size_index=0]; |
| threshold=size*THRESHOLD_PERCENT/100; | threshold=size*THRESHOLD_PERCENT/100; |
| used=0; | used=0; |
| refs=static_cast<Pair **>(pool->calloc(sizeof(Pair *)*size)); | refs=static_cast<Pair **>(pool.calloc(sizeof(Pair *)*size)); |
| } | } |
| void Hash::expand() { | void Hash::expand() { |
| int old_size=size; | int old_size=size; |
| Pair **old_refs=refs; | Pair **old_refs=refs; |
| // allocated bigger refs array | // allocated bigger refs array |
| size_index=size_index+1<sizes_count?size_index+1:sizes_count-1; | size_index=size_index+1<sizes_count?size_index+1:sizes_count-1; |
| size=sizes[size_index]; | size=sizes[size_index]; |
| Pair **refs=static_cast<Pair **>(pool->calloc(sizeof(Pair *)*size)); | refs=static_cast<Pair **>(pool.calloc(sizeof(Pair *)*size)); |
| // rehash | // rehash |
| Pair **old_ref=old_refs; | Pair **old_ref=old_refs; |
| Line 63 void Hash::expand() { | Line 64 void Hash::expand() { |
| } | } |
| } | } |
| uint Hash::generic_code(uint aresult, char *start, uint size) { | uint Hash::generic_code(uint aresult, const char *start, uint size) { |
| uint result=aresult, g; | uint result=aresult, g; |
| char *end=start+size; | const char *end=start+size; |
| while (start<end) { | while (start<end) { |
| result=(result<<4)+*start++; | result=(result<<4)+*start++; |
| Line 77 uint Hash::generic_code(uint aresult, ch | Line 78 uint Hash::generic_code(uint aresult, ch |
| return result; | return result; |
| } | } |
| void Hash::put(Key& key, Value *value) { | void Hash::put(Key& key, Value *value) { SYNCHRONIZED(thread_safe); |
| if(full()) | if(full()) |
| expand(); | expand(); |
| Line 91 void Hash::put(Key& key, Value *value) { | Line 92 void Hash::put(Key& key, Value *value) { |
| return; | return; |
| } | } |
| // not found proper pair -- create&link_in new pair | // proper pair not found -- create&link_in new pair |
| *ref=new(pool) Pair(code, key, value, *ref); | *ref=new(pool) Pair(code, key, value, *ref); |
| } | } |
| Value* Hash::get(Key& key) { | Hash::Value *Hash::get(Key& key) { SYNCHRONIZED(thread_safe); |
| uint code=key.hash_code(); | uint code=key.hash_code(); |
| uint index=code%size; | uint index=code%size; |
| for(Pair *pair=refs[index]; pair; pair=pair->link) | for(Pair *pair=refs[index]; pair; pair=pair->link) |