iron_array.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #pragma once
  2. #include <stdint.h>
  3. typedef struct i8_array {
  4. int8_t *buffer;
  5. uint32_t length;
  6. uint32_t capacity;
  7. } i8_array_t;
  8. typedef struct u8_array {
  9. uint8_t *buffer;
  10. uint32_t length;
  11. uint32_t capacity;
  12. } u8_array_t;
  13. typedef struct i16_array {
  14. int16_t *buffer;
  15. uint32_t length;
  16. uint32_t capacity;
  17. } i16_array_t;
  18. typedef struct u16_array {
  19. uint16_t *buffer;
  20. uint32_t length;
  21. uint32_t capacity;
  22. } u16_array_t;
  23. typedef struct i32_array {
  24. int32_t *buffer;
  25. uint32_t length;
  26. uint32_t capacity;
  27. } i32_array_t;
  28. typedef struct u32_array {
  29. uint32_t *buffer;
  30. uint32_t length;
  31. uint32_t capacity;
  32. } u32_array_t;
  33. typedef struct f32_array {
  34. float *buffer;
  35. uint32_t length;
  36. uint32_t capacity;
  37. } f32_array_t;
  38. typedef struct any_array {
  39. void **buffer;
  40. uint32_t length;
  41. uint32_t capacity;
  42. } any_array_t;
  43. typedef struct char_ptr_array {
  44. char **buffer;
  45. uint32_t length;
  46. uint32_t capacity;
  47. } char_ptr_array_t;
  48. typedef u8_array_t buffer_t;
  49. void array_free(void *a);
  50. void i8_array_push(i8_array_t *a, int8_t e);
  51. void u8_array_push(u8_array_t *a, uint8_t e);
  52. void i16_array_push(i16_array_t *a, int16_t e);
  53. void u16_array_push(u16_array_t *a, uint16_t e);
  54. void i32_array_push(i32_array_t *a, int32_t e);
  55. void u32_array_push(u32_array_t *a, uint32_t e);
  56. void f32_array_push(f32_array_t *a, float e);
  57. void any_array_push(any_array_t *a, void *e);
  58. void char_ptr_array_push(char_ptr_array_t *a, void *e);
  59. void i8_array_resize(i8_array_t *a, uint32_t size);
  60. void u8_array_resize(u8_array_t *a, uint32_t size);
  61. void i16_array_resize(i16_array_t *a, uint32_t size);
  62. void u16_array_resize(u16_array_t *a, uint32_t size);
  63. void i32_array_resize(i32_array_t *a, uint32_t size);
  64. void u32_array_resize(u32_array_t *a, uint32_t size);
  65. void f32_array_resize(f32_array_t *a, uint32_t size);
  66. void any_array_resize(any_array_t *a, uint32_t size);
  67. void char_ptr_array_resize(char_ptr_array_t *a, uint32_t size);
  68. void buffer_resize(buffer_t *b, uint32_t size);
  69. void array_sort(any_array_t *ar, int (*compare)(const void *, const void *));
  70. void i32_array_sort(i32_array_t *ar, int (*compare)(const void *, const void *));
  71. void *array_pop(any_array_t *ar);
  72. int i32_array_pop(i32_array_t *ar);
  73. void *array_shift(any_array_t *ar);
  74. void array_splice(any_array_t *ar, uint32_t start, uint32_t delete_count);
  75. void i32_array_splice(i32_array_t *ar, uint32_t start, uint32_t delete_count);
  76. any_array_t *array_concat(any_array_t *a, any_array_t *b);
  77. any_array_t *array_slice(any_array_t *a, uint32_t begin, uint32_t end);
  78. void array_insert(any_array_t *a, uint32_t at, void *e);
  79. void array_remove(any_array_t *ar, void *e);
  80. void char_ptr_array_remove(char_ptr_array_t *ar, char *e);
  81. void i32_array_remove(i32_array_t *ar, int e);
  82. int32_t array_index_of(any_array_t *ar, void *e);
  83. int32_t char_ptr_array_index_of(char_ptr_array_t *ar, char *e);
  84. int32_t i32_array_index_of(i32_array_t *ar, int e);
  85. void array_reverse(any_array_t *ar);
  86. buffer_t *buffer_slice(buffer_t *a, uint32_t begin, uint32_t end);
  87. uint8_t buffer_get_u8(buffer_t *b, uint32_t p);
  88. int8_t buffer_get_i8(buffer_t *b, uint32_t p);
  89. uint16_t buffer_get_u16(buffer_t *b, uint32_t p);
  90. int16_t buffer_get_i16(buffer_t *b, uint32_t p);
  91. uint32_t buffer_get_u32(buffer_t *b, uint32_t p);
  92. int32_t buffer_get_i32(buffer_t *b, uint32_t p);
  93. float buffer_get_f32(buffer_t *b, uint32_t p);
  94. double buffer_get_f64(buffer_t *b, uint32_t p);
  95. int64_t buffer_get_i64(buffer_t *b, uint32_t p);
  96. void buffer_set_u8(buffer_t *b, uint32_t p, uint8_t n);
  97. void buffer_set_i8(buffer_t *b, uint32_t p, int8_t n);
  98. void buffer_set_u16(buffer_t *b, uint32_t p, uint16_t n);
  99. void buffer_set_i16(buffer_t *b, uint32_t p, uint16_t n);
  100. void buffer_set_u32(buffer_t *b, uint32_t p, uint32_t n);
  101. void buffer_set_i32(buffer_t *b, uint32_t p, int32_t n);
  102. void buffer_set_f32(buffer_t *b, uint32_t p, float n);
  103. buffer_t *buffer_create(uint32_t length);
  104. buffer_t *buffer_create_from_raw(uint8_t *raw, uint32_t length);
  105. f32_array_t *f32_array_create(uint32_t length);
  106. f32_array_t *f32_array_create_from_buffer(buffer_t *b);
  107. f32_array_t *f32_array_create_from_array(f32_array_t *from);
  108. f32_array_t *f32_array_create_from_raw(float *raw, uint32_t length);
  109. f32_array_t *f32_array_create_x(float x);
  110. f32_array_t *f32_array_create_xy(float x, float y);
  111. f32_array_t *f32_array_create_xyz(float x, float y, float z);
  112. f32_array_t *f32_array_create_xyzw(float x, float y, float z, float w);
  113. f32_array_t *f32_array_create_xyzwv(float x, float y, float z, float w, float v);
  114. u32_array_t *u32_array_create(uint32_t length);
  115. u32_array_t *u32_array_create_from_array(u32_array_t *from);
  116. u32_array_t *u32_array_create_from_raw(uint32_t *raw, uint32_t length);
  117. i32_array_t *i32_array_create(uint32_t length);
  118. i32_array_t *i32_array_create_from_array(i32_array_t *from);
  119. i32_array_t *i32_array_create_from_raw(int32_t *raw, uint32_t length);
  120. u16_array_t *u16_array_create(uint32_t length);
  121. u16_array_t *u16_array_create_from_raw(uint16_t *raw, uint32_t length);
  122. i16_array_t *i16_array_create(uint32_t length);
  123. i16_array_t *i16_array_create_from_array(i16_array_t *from);
  124. i16_array_t *i16_array_create_from_raw(int16_t *raw, uint32_t length);
  125. u8_array_t *u8_array_create(uint32_t length);
  126. u8_array_t *u8_array_create_from_array(u8_array_t *from);
  127. u8_array_t *u8_array_create_from_raw(uint8_t *raw, uint32_t length);
  128. u8_array_t *u8_array_create_from_string(char *s);
  129. char *u8_array_to_string(u8_array_t *a);
  130. i8_array_t *i8_array_create(uint32_t length);
  131. i8_array_t *i8_array_create_from_raw(int8_t *raw, uint32_t length);
  132. any_array_t *any_array_create(uint32_t length);
  133. any_array_t *any_array_create_from_raw(void **raw, uint32_t length);
  134. char_ptr_array_t *char_ptr_array_create(uint32_t length);