|
|
| version 1.10, 2001/01/29 22:34:58 | version 1.15, 2001/02/22 11:08:25 |
|---|---|
| Line 10 | Line 10 |
| For more information about Zend please visit http://www.zend.com/ | For more information about Zend please visit http://www.zend.com/ |
| */ | */ |
| #include "pa_pool.h" | #include "pa_hash.h" |
| #include "pa_threads.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) { |
| 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) { | |
| return apool.malloc(size); | |
| } | |
| Hash::Hash(Pool& apool, bool athread_safe) : | void Hash::construct(Pool& apool, bool athread_safe) { |
| pool(apool), | thread_safe=athread_safe; |
| 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 **>(calloc(sizeof(Pair *)*size)); |
| } | } |
| void Hash::expand() { | void Hash::expand() { |
| Line 47 void Hash::expand() { | Line 43 void Hash::expand() { |
| // 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]; |
| refs=static_cast<Pair **>(pool.calloc(sizeof(Pair *)*size)); | refs=static_cast<Pair **>(calloc(sizeof(Pair *)*size)); |
| // rehash | // rehash |
| Pair **old_ref=old_refs; | Pair **old_ref=old_refs; |
| Line 93 void Hash::put(const Key& key, Value *va | Line 89 void Hash::put(const Key& key, Value *va |
| } | } |
| // proper pair not found -- create&link_in new pair | // proper pair not found -- create&link_in new pair |
| *ref=new(pool) Pair(code, key, value, *ref); | *ref=NEW Pair(code, key, value, *ref); |
| } | } |
| Hash::Value *Hash::get(const Key& key) { SYNCHRONIZED(thread_safe); | Hash::Value *Hash::get(const Key& key) const { 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) |