xref: /PHP-7.4/sapi/phpdbg/phpdbg_btree.h (revision 0cf7de1c)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,	  |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Felipe Pena <felipe@php.net>                                |
16    | Authors: Joe Watkins <joe.watkins@live.co.uk>                        |
17    | Authors: Bob Weinand <bwoebi@php.net>                                |
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 	zend_bool persistent;
41 	phpdbg_btree_branch *branch;
42 } phpdbg_btree;
43 
44 typedef struct {
45 	phpdbg_btree *tree;
46 	zend_ulong cur;
47 	zend_ulong end;
48 } phpdbg_btree_position;
49 
50 void phpdbg_btree_init(phpdbg_btree *tree, zend_ulong depth);
51 void phpdbg_btree_clean(phpdbg_btree *tree);
52 phpdbg_btree_result *phpdbg_btree_find(phpdbg_btree *tree, zend_ulong idx);
53 phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong idx);
54 phpdbg_btree_position phpdbg_btree_find_between(phpdbg_btree *tree, zend_ulong lower_idx, zend_ulong higher_idx);
55 phpdbg_btree_result *phpdbg_btree_next(phpdbg_btree_position *pos);
56 int phpdbg_btree_delete(phpdbg_btree *tree, zend_ulong idx);
57 
58 #define PHPDBG_BTREE_INSERT 1
59 #define PHPDBG_BTREE_UPDATE 2
60 #define PHPDBG_BTREE_OVERWRITE (PHPDBG_BTREE_INSERT | PHPDBG_BTREE_UPDATE)
61 
62 int phpdbg_btree_insert_or_update(phpdbg_btree *tree, zend_ulong idx, void *ptr, int flags);
63 #define phpdbg_btree_insert(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_INSERT)
64 #define phpdbg_btree_update(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_UPDATE)
65 #define phpdbg_btree_overwrite(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_OWERWRITE)
66 
67 
68 /* debugging functions */
69 void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth);
70 void phpdbg_btree_dump(phpdbg_btree *tree);
71 
72 #endif
73