bintree_iterator_init.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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, const void *clientnode)
  41. {
  42. if (clientnode != NULL) {
  43. this->tree = tree;
  44. this->key.magic = MAGIC_NUMBER;
  45. /* fill out the iterator's key */
  46. this->tree->getkeyFn(clientnode, &this->key);
  47. /*
  48. * this assert will fire if the client tries to store more than
  49. * the current storage permits
  50. */
  51. assert(this->key.magic == MAGIC_NUMBER);
  52. }
  53. }
  54. /*--------------------------------------------------------- */