Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1.  
  2. /*
  3. * Definition for the stack data structure
  4. * Copyright (c) 2009, Kazuhiko Sakaguchi All rights reserved.
  5. * This file is part of the libdatastruct.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of the Stricter.org nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY KAZUHIKO SAKAGUCHI ''AS IS'' AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL KAZUHIKO SAKAGUCHI BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29.  
  30. #ifndef HEADER_STACK_H
  31.  
  32. #define HEADER_STACK_H
  33.  
  34. #include <stddef.h>
  35.  
  36. /*******************************************************************************
  37. Constants
  38. *******************************************************************************/
  39.  
  40. #define STACK_SUCCESS 0x00000000
  41. #define STACK_MEMORY_ALLOCATION_ERROR 0x00000001
  42. #define STACK_EMPTY 0x00000002
  43. #define STACK_OFFSET_IS_TOO_LARGE 0x00000004
  44.  
  45. #define STACK_MEMORY_ALLOCATION_UNIT_SIZE 32
  46.  
  47. /*******************************************************************************
  48. Structures
  49. *******************************************************************************/
  50.  
  51. typedef struct stack stack_t;
  52.  
  53. typedef struct stack
  54. {
  55. void *array;
  56. size_t size;
  57. size_t element_size;
  58. size_t array_size;
  59. void (*release_function)(void *);
  60. };
  61.  
  62. /*******************************************************************************
  63. Macros
  64. *******************************************************************************/
  65.  
  66. #define stack_size(stack) \
  67. ((stack)->size)
  68.  
  69. #define stack_empty(stack) \
  70. (!(stack)->size)
  71.  
  72. /*******************************************************************************
  73. Functions
  74. *******************************************************************************/
  75.  
  76. extern stack_t *stack_initialize
  77. (const size_t,void (*)(void *));
  78. extern void stack_release
  79. (stack_t *);
  80. extern unsigned int stack_bottom
  81. (stack_t *,void *);
  82. extern unsigned int stack_top
  83. (stack_t *,void *);
  84. extern unsigned int stack_refer_from_bottom
  85. (stack_t *,const size_t,void *);
  86. extern unsigned int stack_refer_from_top
  87. (stack_t *,const size_t,void *);
  88. extern unsigned int stack_refer_many_elements_from_bottom
  89. (stack_t *,const size_t,const size_t,void *);
  90. extern unsigned int stack_refer_many_elements_from_top
  91. (stack_t *,const size_t,const size_t,void *);
  92. extern unsigned int stack_push
  93. (stack_t *,const void *);
  94. extern unsigned int stack_pop
  95. (stack_t *,void *);
  96. extern unsigned int stack_push_many_elements
  97. (stack_t *,const size_t,const void *);
  98. extern unsigned int stack_pop_many_elements
  99. (stack_t *,const size_t,void *);
  100.  
  101. #endif
Add Comment
Please, Sign In to add comment