1
0

bintree_iterator_init.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*********************** -*- Mode: C -*- ***********************
  2. * File : bintree_iterator_init.c
  3. *---------------------------------------------------------------
  4. * Description
  5. * ===========
  6. * This operation initialises an iterator. This can then be
  7. * subsequently used for iterating through a tree. This will work
  8. * even if the "clientnode" which defined the current iterator has been
  9. * removed before the next iterator operation.
  10. *
  11. * iter - the iterator instance to initialise
  12. * tree - the tree to associate with this iterator
  13. * clientnode - the starting point for the iteration
  14. *
  15. *---------------------------------------------------------------
  16. * Author : Graeme McKerrell
  17. * Created On : Wed Jan 28 10:33:42 2004
  18. * Status : TESTED
  19. *---------------------------------------------------------------
  20. * HISTORY
  21. * 7-Dec-2004 Graeme McKerrell
  22. * Renamed to the "lub_" namespace
  23. * 3-Nov-2004 Graeme McKerrell
  24. * Added key bounds checking code
  25. * 5-May-2004 Graeme McKerrell
  26. * updates following review
  27. * 9-Feb-2004 Graeme McKerrell
  28. * updated to use new getkey prototype
  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. #include <assert.h>
  36. #define MAGIC_NUMBER 0x12345678
  37. /*--------------------------------------------------------- */
  38. void
  39. lub_bintree_iterator_init(lub_bintree_iterator_t *this,
  40. lub_bintree_t *tree,
  41. const void *clientnode)
  42. {
  43. if(clientnode != NULL)
  44. {
  45. this->tree = tree;
  46. this->key.magic = MAGIC_NUMBER;
  47. /* fill out the iterator's key */
  48. this->tree->getkeyFn(clientnode,&this->key);
  49. /*
  50. * this assert will fire if the client tries to store more than
  51. * the current storage permits
  52. */
  53. assert(this->key.magic == MAGIC_NUMBER);
  54. }
  55. }
  56. /*--------------------------------------------------------- */