1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #ifndef PHPDBG_BTREE_H
22 #define PHPDBG_BTREE_H
23
24 #include "zend.h"
25
26 typedef struct {
27 zend_ulong idx;
28 void *ptr;
29 } phpdbg_btree_result;
30
31 typedef union _phpdbg_btree_branch phpdbg_btree_branch;
32 union _phpdbg_btree_branch {
33 phpdbg_btree_branch *branches[2];
34 phpdbg_btree_result result;
35 };
36
37 typedef struct {
38 zend_ulong count;
39 zend_ulong depth;
40 phpdbg_btree_branch *branch;
41 } phpdbg_btree;
42
43 typedef struct {
44 phpdbg_btree *tree;
45 zend_ulong cur;
46 zend_ulong end;
47 } phpdbg_btree_position;
48
49 void phpdbg_btree_init(phpdbg_btree *tree, zend_ulong depth);
50 phpdbg_btree_result *phpdbg_btree_find(phpdbg_btree *tree, zend_ulong idx);
51 phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong idx);
52 phpdbg_btree_position phpdbg_btree_find_between(phpdbg_btree *tree, zend_ulong lower_idx, zend_ulong higher_idx);
53 phpdbg_btree_result *phpdbg_btree_next(phpdbg_btree_position *pos);
54 int phpdbg_btree_delete(phpdbg_btree *tree, zend_ulong idx);
55
56 #define PHPDBG_BTREE_INSERT 1
57 #define PHPDBG_BTREE_UPDATE 2
58 #define PHPDBG_BTREE_OVERWRITE (PHPDBG_BTREE_INSERT | PHPDBG_BTREE_UPDATE)
59
60 int phpdbg_btree_insert_or_update(phpdbg_btree *tree, zend_ulong idx, void *ptr, int flags);
61 #define phpdbg_btree_insert(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_INSERT)
62 #define phpdbg_btree_update(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_UPDATE)
63 #define phpdbg_btree_overwrite(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_OWERWRITE)
64
65
66
67 void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth);
68 void phpdbg_btree_dump(phpdbg_btree *tree);
69
70 #endif