phpdbg_btree.h 2.8 KB

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