avl.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* avl.h - avl tree definitions */
  13. /*
  14. * Copyright (c) 1993 Regents of the University of Michigan.
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms are permitted
  18. * provided that this notice is preserved and that due credit is given
  19. * to the University of Michigan at Ann Arbor. The name of the University
  20. * may not be used to endorse or promote products derived from this
  21. * software without specific prior written permission. This software
  22. * is provided ``as is'' without express or implied warranty.
  23. */
  24. #ifndef _AVL
  25. #define _AVL
  26. /*
  27. * this structure represents a generic avl tree node.
  28. */
  29. typedef struct avlnode {
  30. caddr_t avl_data;
  31. signed char avl_bf;
  32. struct avlnode *avl_left;
  33. struct avlnode *avl_right;
  34. } Avlnode;
  35. #define NULLAVL ((Avlnode *) NULL)
  36. /* balance factor values */
  37. #define LH -1
  38. #define EH 0
  39. #define RH 1
  40. /* avl routines */
  41. #define avl_getone(x) (x == 0 ? 0 : (x)->avl_data)
  42. #define avl_onenode(x) (x == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
  43. extern int avl_insert();
  44. extern caddr_t avl_delete();
  45. extern caddr_t avl_find();
  46. extern caddr_t avl_getfirst();
  47. extern caddr_t avl_getnext();
  48. extern int avl_dup_error();
  49. extern int avl_apply();
  50. extern int avl_free();
  51. /* apply traversal types */
  52. #define AVL_PREORDER 1
  53. #define AVL_INORDER 2
  54. #define AVL_POSTORDER 3
  55. /* what apply returns if it ran out of nodes */
  56. #define AVL_NOMORE -6
  57. #ifndef _IFP
  58. #define _IFP
  59. typedef int (*IFP)();
  60. #endif
  61. caddr_t avl_find_lin( Avlnode *root, caddr_t data, IFP fcmp );
  62. #endif /* _AVL */