1 /* 2 +----------------------------------------------------------------------+ 3 | Copyright (c) The PHP Group | 4 +----------------------------------------------------------------------+ 5 | This source file is subject to version 3.01 of the PHP license, | 6 | that is bundled with this package in the file LICENSE, and is | 7 | available through the world-wide-web at the following url: | 8 | https://www.php.net/license/3_01.txt | 9 | If you did not receive a copy of the PHP license and are unable to | 10 | obtain it through the world-wide-web, please send a note to | 11 | license@php.net so we can mail you a copy immediately. | 12 +----------------------------------------------------------------------+ 13 | Authors: Felipe Pena <felipe@php.net> | 14 | Authors: Joe Watkins <joe.watkins@live.co.uk> | 15 | Authors: Bob Weinand <bwoebi@php.net> | 16 +----------------------------------------------------------------------+ 17 */ 18 19 #ifndef PHPDBG_BTREE_H 20 #define PHPDBG_BTREE_H 21 22 #include "zend.h" 23 24 typedef struct { 25 zend_ulong idx; 26 void *ptr; 27 } phpdbg_btree_result; 28 29 typedef union _phpdbg_btree_branch phpdbg_btree_branch; 30 union _phpdbg_btree_branch { 31 phpdbg_btree_branch *branches[2]; 32 phpdbg_btree_result result; 33 }; 34 35 typedef struct { 36 zend_ulong count; 37 zend_ulong depth; 38 bool persistent; 39 phpdbg_btree_branch *branch; 40 } phpdbg_btree; 41 42 typedef struct { 43 phpdbg_btree *tree; 44 zend_ulong cur; 45 zend_ulong end; 46 } phpdbg_btree_position; 47 48 void phpdbg_btree_init(phpdbg_btree *tree, zend_ulong depth); 49 void phpdbg_btree_clean(phpdbg_btree *tree); 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_OVERWRITE) 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