XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.1 KiB

  1. #include <stdlib.h>
  2. #include <assert.h>
  3. #include "xc_stack.h"
  4. typedef xc_stack_t* S;
  5. void xc_stack_init_ex(S stack, int initsize)
  6. {
  7. stack->cnt = 0;
  8. stack->size = initsize;
  9. stack->data = malloc(sizeof(void *) * stack->size);
  10. }
  11. void xc_stack_destroy(S stack)
  12. {
  13. free(stack->data);
  14. }
  15. void xc_stack_push(S stack, void *item)
  16. {
  17. if (stack->cnt == stack->size) {
  18. stack->size <<= 1;
  19. stack->data = realloc(stack->data, sizeof(void *) * stack->size);
  20. }
  21. stack->data[stack->cnt++] = item;
  22. }
  23. void* xc_stack_pop(S stack)
  24. {
  25. assert(stack != NULL && stack->size > 0);
  26. return stack->data[--stack->cnt];
  27. }
  28. void* xc_stack_top(S stack)
  29. {
  30. assert(stack != NULL && stack->cnt > 0);
  31. return stack->data[stack->cnt-1];
  32. }
  33. void* xc_stack_get(S stack, int n)
  34. {
  35. assert(stack != NULL && stack->cnt > 0);
  36. return stack->data[n];
  37. }
  38. int xc_stack_count(S stack)
  39. {
  40. assert(stack != NULL);
  41. return stack->cnt;
  42. }
  43. void xc_stack_reverse(S stack)
  44. {
  45. int i, j;
  46. void *tmp;
  47. assert(stack != NULL);
  48. for (i = 0, j = stack->cnt - 1; i < j; i ++, j --) {
  49. tmp = stack->data[i];
  50. stack->data[i] = stack->data[j];
  51. stack->data[j] = tmp;
  52. }
  53. }