xref: /PHP-7.0/sapi/phpdbg/phpdbg_btree.h (revision 478f119a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2017 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 	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 /* debugging functions */
67 void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth);
68 void phpdbg_btree_dump(phpdbg_btree *tree);
69 
70 #endif
71