1
0

bintree_findlast.c 2.6 KB

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