Guest User

Untitled

a guest
Apr 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 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 max_used_size;
  58. size_t element_size;
  59. size_t array_size;
  60. void (*release_function)(void *);
  61. void *(*copy_function)(void *, const void *, size_t);
  62. };
  63.  
  64. /*******************************************************************************
  65. Macros
  66. *******************************************************************************/
  67.  
  68. #define stack_size(stack) \
  69. ((stack)->size)
  70.  
  71. #define stack_empty(stack) \
  72. (!(stack)->size)
  73.  
  74. /*******************************************************************************
  75. Functions
  76. *******************************************************************************/
  77.  
  78. extern stack_t *stack_initialize
  79. (const size_t,void (*release_function)(void *),void *(*copy_function)(void *, const void *, size_t));
  80. extern void stack_release
  81. (stack_t *);
  82. extern unsigned int stack_bottom
  83. (stack_t *,void *);
  84. extern unsigned int stack_top
  85. (stack_t *,void *);
  86. extern unsigned int stack_refer_from_bottom
  87. (stack_t *,const size_t,void *);
  88. extern unsigned int stack_refer_from_top
  89. (stack_t *,const size_t,void *);
  90. extern unsigned int stack_refer_many_elements_from_bottom
  91. (stack_t *,const size_t,const size_t,void *);
  92. extern unsigned int stack_refer_many_elements_from_top
  93. (stack_t *,const size_t,const size_t,void *);
  94. extern unsigned int stack_push
  95. (stack_t *,const void *);
  96. extern unsigned int stack_pop
  97. (stack_t *,void *);
  98. extern unsigned int stack_push_many_elements
  99. (stack_t *,const size_t,const void *);
  100. extern unsigned int stack_pop_many_elements
  101. (stack_t *,const size_t,void *);
  102.  
  103. #endif
Add Comment
Please, Sign In to add comment