Replace _set_at2 by _get_at for array.
(Break API)
This commit is contained in:
1 parent
26b8c1d0a2
commit
d1f2b62f66
4 files changed
+15
-9
No files matched your search
@@ -8,3 +8,8 @@ V0.2.*: * worker_sync takes a 'worker_t' as an additional parameter
|
|||||||
* worker_init takes an int as numWorker instead of an unsingned int.
|
* worker_init takes an int as numWorker instead of an unsingned int.
|
||||||
* RBTREE pop method has been renamed into _pop_at
|
* RBTREE pop method has been renamed into _pop_at
|
||||||
* SNAPSHOT_DEF has been removed. use SNAPSHOT_SPSC_DEF
|
* SNAPSHOT_DEF has been removed. use SNAPSHOT_SPSC_DEF
|
||||||
|
* array's _set_at2 has been replaced by array's _get_at.
|
||||||
|
The interface is similar to dict _get_at, making the API cleaner
|
||||||
|
and more generic.
|
||||||
|
_set_at2(a,i,x) ==> set(*_get_at(a,i),x)
|
||||||
|
|
||||||
@@ -47,8 +47,8 @@ static void program_init(program_t p, string_t text) {
|
|||||||
int left;
|
int left;
|
||||||
array_int_pop_back(&left, leftstack);
|
array_int_pop_back(&left, leftstack);
|
||||||
int right = pc;
|
int right = pc;
|
||||||
array_int_set_at2 (p->bracket_map, left, right);
|
*array_int_get_at (p->bracket_map, left) = right;
|
||||||
array_int_set_at2 (p->bracket_map, right, left);
|
*array_int_get_at (p->bracket_map, right) = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc++;
|
pc++;
|
||||||
|
|||||||
@@ -353,24 +353,25 @@
|
|||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline type * \
|
||||||
M_C(name, _set_at2)(array_t v, size_t idx, type x) \
|
M_C(name, _get_at)(array_t v, size_t idx) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
const size_t size = idx + 1; \
|
const size_t size = idx + 1; \
|
||||||
/* NOTE: set at and resize if needed */ \
|
/* resize if needed */ \
|
||||||
if (v->size <= size) { \
|
if (v->size <= size) { \
|
||||||
/* Increase size of array */ \
|
/* Increase size of array */ \
|
||||||
if (M_UNLIKELY (size > v->alloc) ) { \
|
if (M_UNLIKELY (size > v->alloc) ) { \
|
||||||
size_t alloc = M_GET_INC_ALLOC oplist (size) ; \
|
size_t alloc = M_GET_INC_ALLOC oplist (size) ; \
|
||||||
|
/* In case of overflow of size_t */ \
|
||||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||||
return ; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
type *ptr = M_GET_REALLOC oplist (type, v->ptr, alloc); \
|
type *ptr = M_GET_REALLOC oplist (type, v->ptr, alloc); \
|
||||||
if (M_UNLIKELY (ptr == NULL) ) { \
|
if (M_UNLIKELY (ptr == NULL) ) { \
|
||||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||||
return; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
v->ptr = ptr; \
|
v->ptr = ptr; \
|
||||||
v->alloc = alloc; \
|
v->alloc = alloc; \
|
||||||
@@ -380,8 +381,8 @@
|
|||||||
v->size = size; \
|
v->size = size; \
|
||||||
} \
|
} \
|
||||||
assert (idx < v->size); \
|
assert (idx < v->size); \
|
||||||
M_GET_SET oplist(v->ptr[idx], x); \
|
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
|
return &v->ptr[idx]; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
|
|||||||
+1
-1
@@ -281,7 +281,7 @@ static void test_d(void)
|
|||||||
for(int i = 9; i < 19; i++)
|
for(int i = 9; i < 19; i++)
|
||||||
assert (*array_uint_get (a1, i) == 18U-i);
|
assert (*array_uint_get (a1, i) == 18U-i);
|
||||||
|
|
||||||
array_uint_set_at2(a1, 100, 100);
|
*array_uint_get_at(a1, 100) = 100;
|
||||||
assert (*array_uint_back(a1) == 100);
|
assert (*array_uint_back(a1) == 100);
|
||||||
assert (array_uint_size(a1) == 101);
|
assert (array_uint_size(a1) == 101);
|
||||||
array_uint_pop_back (NULL, a1);
|
array_uint_pop_back (NULL, a1);
|
||||||
|
|||||||
Reference in new issue
Block a user