1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*
+----------------------------------------------------------------------+
| Zend OPcache |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@php.net> |
| Zeev Suraski <zeev@php.net> |
| Stanislav Malyshev <stas@zend.com> |
| Dmitry Stogov <dmitry@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef ZEND_ACCELERATOR_HASH_H
#define ZEND_ACCELERATOR_HASH_H
#include "zend.h"
/*
zend_accel_hash - is a hash table allocated in shared memory and
distributed across simultaneously running processes. The hash tables have
fixed sizen selected during construction by zend_accel_hash_init(). All the
hash entries are preallocated in the 'hash_entries' array. 'num_entries' is
initialized by zero and grows when new data is added.
zend_accel_hash_update() just takes the next entry from 'hash_entries'
array and puts it into appropriate place of 'hash_table'.
Hash collisions are resolved by separate chaining with linked lists,
however, entries are still taken from the same 'hash_entries' array.
'key' and 'data' passed to zend_accel_hash_update() must be already
allocated in shared memory. Few keys may be resolved to the same data.
using 'indirect' entries, that point to other entries ('data' is actually
a pointer to another zend_accel_hash_entry).
zend_accel_hash_update() requires exclusive lock, however,
zend_accel_hash_find() does not.
*/
typedef struct _zend_accel_hash_entry zend_accel_hash_entry;
struct _zend_accel_hash_entry {
zend_ulong hash_value;
const char *key;
zend_accel_hash_entry *next;
void *data;
uint32_t key_length;
zend_bool indirect;
};
typedef struct _zend_accel_hash {
zend_accel_hash_entry **hash_table;
zend_accel_hash_entry *hash_entries;
uint32_t num_entries;
uint32_t max_num_entries;
uint32_t num_direct_entries;
} zend_accel_hash;
void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size);
void zend_accel_hash_clean(zend_accel_hash *accel_hash);
zend_accel_hash_entry* zend_accel_hash_update(
zend_accel_hash *accel_hash,
const char *key,
uint32_t key_length,
zend_bool indirect,
void *data);
void* zend_accel_hash_find(
zend_accel_hash *accel_hash,
zend_string *key);
zend_accel_hash_entry* zend_accel_hash_find_entry(
zend_accel_hash *accel_hash,
zend_string *key);
void* zend_accel_hash_str_find(
zend_accel_hash *accel_hash,
const char *key,
uint32_t key_length);
zend_accel_hash_entry* zend_accel_hash_str_find_entry(
zend_accel_hash *accel_hash,
const char *key,
uint32_t key_length);
int zend_accel_hash_unlink(
zend_accel_hash *accel_hash,
const char *key,
uint32_t key_length);
static inline zend_bool zend_accel_hash_is_full(zend_accel_hash *accel_hash)
{
if (accel_hash->num_entries == accel_hash->max_num_entries) {
return 1;
} else {
return 0;
}
}
#endif /* ZEND_ACCELERATOR_HASH_H */
|