|
@@ -1,8 +1,11 @@
|
|
|
#pragma once
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
+#include "pocketpy/common/algorithm.h"
|
|
|
|
|
+
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
-#include "pocketpy/common/algorithm.h"
|
|
|
|
|
|
|
+#include <stdbool.h>
|
|
|
|
|
+#include <assert.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
|
extern "C" {
|
|
extern "C" {
|
|
@@ -17,7 +20,6 @@ typedef struct c11_array{
|
|
|
void c11_array__ctor(c11_array* self, int elem_size, int count);
|
|
void c11_array__ctor(c11_array* self, int elem_size, int count);
|
|
|
void c11_array__dtor(c11_array* self);
|
|
void c11_array__dtor(c11_array* self);
|
|
|
c11_array c11_array__copy(const c11_array* self);
|
|
c11_array c11_array__copy(const c11_array* self);
|
|
|
-void* c11_array__at(c11_array* self, int index);
|
|
|
|
|
|
|
|
|
|
typedef struct c11_vector{
|
|
typedef struct c11_vector{
|
|
|
void* data;
|
|
void* data;
|
|
@@ -29,12 +31,12 @@ typedef struct c11_vector{
|
|
|
void c11_vector__ctor(c11_vector* self, int elem_size);
|
|
void c11_vector__ctor(c11_vector* self, int elem_size);
|
|
|
void c11_vector__dtor(c11_vector* self);
|
|
void c11_vector__dtor(c11_vector* self);
|
|
|
c11_vector c11_vector__copy(const c11_vector* self);
|
|
c11_vector c11_vector__copy(const c11_vector* self);
|
|
|
-void* c11_vector__at(c11_vector* self, int index);
|
|
|
|
|
void c11_vector__reserve(c11_vector* self, int capacity);
|
|
void c11_vector__reserve(c11_vector* self, int capacity);
|
|
|
void c11_vector__clear(c11_vector* self);
|
|
void c11_vector__clear(c11_vector* self);
|
|
|
|
|
|
|
|
-#define c11__getitem(T, self, index) ((T*)(self)->data)[index]
|
|
|
|
|
|
|
+#define c11__getitem(T, self, index) (((T*)(self)->data)[index])
|
|
|
#define c11__setitem(T, self, index, value) ((T*)(self)->data)[index] = value;
|
|
#define c11__setitem(T, self, index, value) ((T*)(self)->data)[index] = value;
|
|
|
|
|
+#define c11__at(T, self, index) ((T*)(self)->data + index)
|
|
|
|
|
|
|
|
#define c11_vector__push(T, self, elem) \
|
|
#define c11_vector__push(T, self, elem) \
|
|
|
do{ \
|
|
do{ \
|
|
@@ -56,19 +58,19 @@ void c11_vector__clear(c11_vector* self);
|
|
|
}while(0)
|
|
}while(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
-#define c11_vector__insert(T, self, p, elem) \
|
|
|
|
|
|
|
+#define c11_vector__insert(T, self, index, elem) \
|
|
|
do{ \
|
|
do{ \
|
|
|
if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity*2); \
|
|
if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity*2); \
|
|
|
- int __n = (self)->count - (p - (T*)(self)->data); \
|
|
|
|
|
- memmove(p + 1, p, __n * sizeof(T)); \
|
|
|
|
|
|
|
+ T* p = (T*)(self)->data + (index); \
|
|
|
|
|
+ memmove(p + 1, p, ((self)->count - (index)) * sizeof(T)); \
|
|
|
*p = (elem); \
|
|
*p = (elem); \
|
|
|
(self)->count++; \
|
|
(self)->count++; \
|
|
|
}while(0)
|
|
}while(0)
|
|
|
|
|
|
|
|
-#define c11_vector__erase(T, self, p) \
|
|
|
|
|
|
|
+#define c11_vector__erase(T, self, index) \
|
|
|
do{ \
|
|
do{ \
|
|
|
- int __n = (self)->count - (p - (T*)(self)->data) - 1; \
|
|
|
|
|
- memmove(p, p + 1, __n * sizeof(T)); \
|
|
|
|
|
|
|
+ T* p = (T*)(self)->data + (index); \
|
|
|
|
|
+ memmove(p, p + 1, ((self)->count - (index) - 1) * sizeof(T)); \
|
|
|
(self)->count--; \
|
|
(self)->count--; \
|
|
|
}while(0)
|
|
}while(0)
|
|
|
|
|
|