bintree_findfirst.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*********************** -*- Mode: C -*- ***********************
  2. * File : bintree_findfirst.c
  3. *---------------------------------------------------------------
  4. * Description
  5. * ===========
  6. * This operation returns the first "clientnode" present in the specified "tree"
  7. *
  8. * tree - the "tree" instance to invoke this operation upon
  9. *
  10. * RETURNS
  11. * "clientnode" instance or NULL if no nodes are present in this view.
  12. *
  13. *---------------------------------------------------------------
  14. * Author : Graeme McKerrell
  15. * Created On : Wed Jan 28 10:15:00 2004
  16. * Status : TESTED
  17. *---------------------------------------------------------------
  18. * HISTORY
  19. * 7-Dec-2004 Graeme McKerrell
  20. * Renamed to the "lub_" namespace
  21. * 5-May-2004 Graeme McKerrell
  22. * updates following review
  23. * 2-Mar-2004 Graeme McKerrell
  24. * fixed comparison logic
  25. * 9-Feb-2004 Graeme McKerrell
  26. * update to use new getkey prototype, removed the now spurious
  27. * nullgetkey() function
  28. * 28-Jan-2004 Graeme McKerrell
  29. * Initial version
  30. *---------------------------------------------------------------
  31. * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
  32. **************************************************************** */
  33. #include "private.h"
  34. /* forward declare these functions */
  35. static lub_bintree_compare_fn compareleft;
  36. /*--------------------------------------------------------- */
  37. void *lub_bintree_findfirst(lub_bintree_t * this)
  38. {
  39. lub_bintree_compare_fn *client_compare = this->compareFn;
  40. /*
  41. * put dummy functions in place
  42. * This will make the search faster and direct it to the left most
  43. * node
  44. */
  45. this->compareFn = compareleft;
  46. /*
  47. * the key doesn't matter here cos we've cobbled the compare function
  48. */
  49. this->root = lub_bintree_splay(this, this->root, NULL);
  50. /* restore the client functions */
  51. this->compareFn = client_compare;
  52. if (NULL == this->root)
  53. return NULL;
  54. else
  55. return lub_bintree_getclientnode(this, this->root);
  56. }
  57. /*--------------------------------------------------------- */
  58. /*
  59. * This comparison operation always returns 1 hence will force a
  60. * search to the left most node.
  61. *
  62. * clientnode - node to compare (not used)
  63. * clientkey - key to compare (not used)
  64. */
  65. static int compareleft(const void *clientnode, const void *clientkey)
  66. {
  67. clientnode = clientnode;
  68. clientkey = clientkey;
  69. return 1;
  70. }
  71. /*--------------------------------------------------------- */