phpdbg_btree.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 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. #ifndef PHPDBG_BTREE_H
  21. #define PHPDBG_BTREE_H
  22. #include "zend.h"
  23. typedef struct {
  24. zend_ulong idx;
  25. void *ptr;
  26. } phpdbg_btree_result;
  27. typedef union _phpdbg_btree_branch phpdbg_btree_branch;
  28. union _phpdbg_btree_branch {
  29. phpdbg_btree_branch *branches[2];
  30. phpdbg_btree_result result;
  31. };
  32. typedef struct {
  33. zend_ulong count;
  34. zend_ulong depth;
  35. zend_bool persistent;
  36. phpdbg_btree_branch *branch;
  37. } phpdbg_btree;
  38. typedef struct {
  39. phpdbg_btree *tree;
  40. zend_ulong cur;
  41. zend_ulong end;
  42. } phpdbg_btree_position;
  43. void phpdbg_btree_init(phpdbg_btree *tree, zend_ulong depth);
  44. void phpdbg_btree_clean(phpdbg_btree *tree);
  45. phpdbg_btree_result *phpdbg_btree_find(phpdbg_btree *tree, zend_ulong idx);
  46. phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong idx);
  47. phpdbg_btree_position phpdbg_btree_find_between(phpdbg_btree *tree, zend_ulong lower_idx, zend_ulong higher_idx);
  48. phpdbg_btree_result *phpdbg_btree_next(phpdbg_btree_position *pos);
  49. int phpdbg_btree_delete(phpdbg_btree *tree, zend_ulong idx);
  50. #define PHPDBG_BTREE_INSERT 1
  51. #define PHPDBG_BTREE_UPDATE 2
  52. #define PHPDBG_BTREE_OVERWRITE (PHPDBG_BTREE_INSERT | PHPDBG_BTREE_UPDATE)
  53. int phpdbg_btree_insert_or_update(phpdbg_btree *tree, zend_ulong idx, void *ptr, int flags);
  54. #define phpdbg_btree_insert(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_INSERT)
  55. #define phpdbg_btree_update(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_UPDATE)
  56. #define phpdbg_btree_overwrite(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_OWERWRITE)
  57. /* debugging functions */
  58. void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth);
  59. void phpdbg_btree_dump(phpdbg_btree *tree);
  60. #endif