393 |
remove_range (array, count, size, idx, 1); |
remove_range (array, count, size, idx, 1); |
394 |
} |
} |
395 |
|
|
396 |
|
/* Moves an element in ARRAY, which consists of COUNT elements of |
397 |
|
SIZE bytes each, from OLD_IDX to NEW_IDX, shifting around |
398 |
|
other elements as needed. Runs in O(abs(OLD_IDX - NEW_IDX)) |
399 |
|
time. */ |
400 |
|
void |
401 |
|
move_element (void *array_, size_t count, size_t size, |
402 |
|
size_t old_idx, size_t new_idx) |
403 |
|
{ |
404 |
|
assert (array_ != NULL || count == 0); |
405 |
|
assert (old_idx < count); |
406 |
|
assert (new_idx < count); |
407 |
|
|
408 |
|
if (old_idx != new_idx) |
409 |
|
{ |
410 |
|
char *array = array_; |
411 |
|
char *element = xmalloc (size); |
412 |
|
char *new = array + new_idx * size; |
413 |
|
char *old = array + old_idx * size; |
414 |
|
|
415 |
|
memcpy (element, old, size); |
416 |
|
if (new < old) |
417 |
|
memmove (new + size, new, (old_idx - new_idx) * size); |
418 |
|
else |
419 |
|
memmove (old, old + size, (new_idx - old_idx) * size); |
420 |
|
memcpy (new, element, size); |
421 |
|
|
422 |
|
free (element); |
423 |
|
} |
424 |
|
} |
425 |
|
|
426 |
/* A predicate and its auxiliary data. */ |
/* A predicate and its auxiliary data. */ |
427 |
struct pred_aux |
struct pred_aux |
428 |
{ |
{ |