queue.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*====================================================================*
  2. - Copyright (C) 2001 Leptonica. All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions
  6. - are met:
  7. - 1. Redistributions of source code must retain the above copyright
  8. - notice, this list of conditions and the following disclaimer.
  9. - 2. Redistributions in binary form must reproduce the above
  10. - copyright notice, this list of conditions and the following
  11. - disclaimer in the documentation and/or other materials
  12. - provided with the distribution.
  13. -
  14. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
  18. - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *====================================================================*/
  26. #ifndef LEPTONICA_QUEUE_H
  27. #define LEPTONICA_QUEUE_H
  28. /*
  29. * queue.h
  30. *
  31. * Expandable pointer queue for arbitrary void* data.
  32. *
  33. * The L_Queue is a fifo that implements a queue of void* pointers.
  34. * It can be used to hold a queue of any type of struct.
  35. *
  36. * Internally, it maintains two counters:
  37. * nhead: location of head (in ptrs) from the beginning
  38. * of the array.
  39. * nelem: number of ptr elements stored in the queue.
  40. *
  41. * The element at the head of the queue, which is the next to
  42. * be removed, is array[nhead]. The location at the tail of the
  43. * queue to which the next element will be added is
  44. * array[nhead + nelem].
  45. *
  46. * As items are added to the queue, nelem increases.
  47. * As items are removed, nhead increases and nelem decreases.
  48. * Any time the tail reaches the end of the allocated array,
  49. * all the pointers are shifted to the left, so that the head
  50. * is at the beginning of the array.
  51. * If the array becomes more than 3/4 full, it doubles in size.
  52. *
  53. * The auxiliary stack can be used in a wrapper for re-using
  54. * items popped from the queue. It is not made by default.
  55. *
  56. * For further implementation details, see queue.c.
  57. */
  58. struct L_Queue
  59. {
  60. l_int32 nalloc; /* size of allocated ptr array */
  61. l_int32 nhead; /* location of head (in ptrs) from the */
  62. /* beginning of the array */
  63. l_int32 nelem; /* number of elements stored in the queue */
  64. void **array; /* ptr array */
  65. struct L_Stack *stack; /* auxiliary stack */
  66. };
  67. typedef struct L_Queue L_QUEUE;
  68. #endif /* LEPTONICA_QUEUE_H */