Rename _swap into _swap_at

Add _swap function.
This commit is contained in:
Patrick Pelissier committed 2017-03-14 20:16:38 +01:00
1 parent e0648e3002
commit ecf5547c1e
2 files changed
+23 -3

No files matched your search

+16 -2
View File
@@ -418,9 +418,23 @@
M_C3(array_, name, _pop_at)(NULL, v, i); \
} \
\
/* FIXME: More than a swap_at than a swap? */ \
static inline void \
M_C3(array_, name, _swap)(M_C3(array_, name,_t) v, size_t i, size_t j) \
M_C3(array_, name, _swap)(M_C3(array_, name,_t) v1, M_C3(array_, name,_t) v2) \
{ \
assert (v1 != NULL && v2 != NULL); \
size_t tmp = v1->size; \
v1->size = v2->size; \
v2->size = tmp; \
tmp = v1->alloc; \
v1->alloc = v2->alloc; \
v2->alloc = tmp; \
type *p = v1->ptr; \
v1->ptr = v2->ptr; \
v2->ptr = p; \
} \
\
static inline void \
M_C3(array_, name, _swap_at)(M_C3(array_, name,_t) v, size_t i, size_t j) \
{ \
assert (v != NULL); \
assert(i < v->size && j < v->size && v->ptr != NULL); \
+7 -1
View File
@@ -100,7 +100,7 @@ static void test_uint(void)
s += *array_uint_cget(v, i);
assert( s == 100 * 99 /2 + 999);
array_uint_swap(v, 2, 3);
array_uint_swap_at(v, 2, 3);
assert(*array_uint_cget(v, 2) == 4);
assert(*array_uint_cget(v, 3) == 3);
@@ -141,7 +141,13 @@ static void test_uint(void)
assert(*array_uint_cget(v2, 500) == 0);
assert(array_uint_size(v2) == 1005);
assert(*array_uint_cget(v2, 1004) == 0);
array_uint_init(v);
array_uint_swap(v,v2);
assert(array_uint_size(v) == 1005);
assert(array_uint_size(v2) == 0);
array_uint_clear(v);
array_uint_clear(v2);
}