iterator.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef ITERATOR_H
  2. #define ITERATOR_H
  3. /*
  4. * Generic constants related to iterators.
  5. */
  6. /*
  7. * The attempt to advance the iterator was successful; the iterator
  8. * reflects the new current entry.
  9. */
  10. #define ITER_OK 0
  11. /*
  12. * The iterator is exhausted and has been freed.
  13. */
  14. #define ITER_DONE -1
  15. /*
  16. * The iterator experienced an error. The iteration has been aborted
  17. * and the iterator has been freed.
  18. */
  19. #define ITER_ERROR -2
  20. /*
  21. * Return values for selector functions for merge iterators. The
  22. * numerical values of these constants are important and must be
  23. * compatible with ITER_DONE and ITER_ERROR.
  24. */
  25. enum iterator_selection {
  26. /* End the iteration without an error: */
  27. ITER_SELECT_DONE = ITER_DONE,
  28. /* Report an error and abort the iteration: */
  29. ITER_SELECT_ERROR = ITER_ERROR,
  30. /*
  31. * The next group of constants are masks that are useful
  32. * mainly internally.
  33. */
  34. /* The LSB selects whether iter0/iter1 is the "current" iterator: */
  35. ITER_CURRENT_SELECTION_MASK = 0x01,
  36. /* iter0 is the "current" iterator this round: */
  37. ITER_CURRENT_SELECTION_0 = 0x00,
  38. /* iter1 is the "current" iterator this round: */
  39. ITER_CURRENT_SELECTION_1 = 0x01,
  40. /* Yield the value from the current iterator? */
  41. ITER_YIELD_CURRENT = 0x02,
  42. /* Discard the value from the secondary iterator? */
  43. ITER_SKIP_SECONDARY = 0x04,
  44. /*
  45. * The constants that a selector function should usually
  46. * return.
  47. */
  48. /* Yield the value from iter0: */
  49. ITER_SELECT_0 = ITER_CURRENT_SELECTION_0 | ITER_YIELD_CURRENT,
  50. /* Yield the value from iter0 and discard the one from iter1: */
  51. ITER_SELECT_0_SKIP_1 = ITER_SELECT_0 | ITER_SKIP_SECONDARY,
  52. /* Discard the value from iter0 without yielding anything this round: */
  53. ITER_SKIP_0 = ITER_CURRENT_SELECTION_1 | ITER_SKIP_SECONDARY,
  54. /* Yield the value from iter1: */
  55. ITER_SELECT_1 = ITER_CURRENT_SELECTION_1 | ITER_YIELD_CURRENT,
  56. /* Yield the value from iter1 and discard the one from iter0: */
  57. ITER_SELECT_1_SKIP_0 = ITER_SELECT_1 | ITER_SKIP_SECONDARY,
  58. /* Discard the value from iter1 without yielding anything this round: */
  59. ITER_SKIP_1 = ITER_CURRENT_SELECTION_0 | ITER_SKIP_SECONDARY
  60. };
  61. #endif /* ITERATOR_H */