bintree.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2010-2017 The RetroArch team
  2. *
  3. * ---------------------------------------------------------------------------------------
  4. * The following license statement only applies to this file (bintree.h).
  5. * ---------------------------------------------------------------------------------------
  6. *
  7. * Permission is hereby granted, free of charge,
  8. * to any person obtaining a copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
  11. * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef __LIBRETRODB_BINTREE_H__
  23. #define __LIBRETRODB_BINTREE_H__
  24. #include <retro_common_api.h>
  25. RETRO_BEGIN_DECLS
  26. typedef int (*bintree_cmp_func)(const void *a, const void *b, void *ctx);
  27. typedef int (*bintree_iter_cb) (void *value, void *ctx);
  28. typedef struct bintree_node
  29. {
  30. void *value;
  31. struct bintree_node *parent;
  32. struct bintree_node *left;
  33. struct bintree_node *right;
  34. } bintree_node_t;
  35. typedef struct bintree
  36. {
  37. struct bintree_node *root;
  38. void *ctx;
  39. bintree_cmp_func cmp;
  40. } bintree_t;
  41. bintree_t *bintree_new(bintree_cmp_func cmp, void *ctx);
  42. int bintree_insert(bintree_t *t, struct bintree_node *root, void *value);
  43. int bintree_iterate(struct bintree_node *n, bintree_iter_cb cb, void *ctx);
  44. void bintree_free(struct bintree_node *n);
  45. RETRO_END_DECLS
  46. #endif