mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 09:59:48 +01:00
util/array: add array_remove_at
This commit is contained in:
parent
dbb0e2f75b
commit
a6ed4ae308
2 changed files with 15 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <wayland-util.h>
|
||||
|
||||
size_t push_zeroes_to_end(uint32_t arr[], size_t n);
|
||||
|
||||
|
@ -21,4 +22,9 @@ bool set_add(uint32_t values[], size_t *len, size_t cap, uint32_t target);
|
|||
*/
|
||||
bool set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target);
|
||||
|
||||
/**
|
||||
* Remove a chunk of memory of the specified size at the specified offset.
|
||||
*/
|
||||
void array_remove_at(struct wl_array *arr, size_t offset, size_t size);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "util/array.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
// https://www.geeksforgeeks.org/move-zeroes-end-array/
|
||||
size_t push_zeroes_to_end(uint32_t arr[], size_t n) {
|
||||
|
@ -46,3 +47,11 @@ bool set_remove(uint32_t values[], size_t *len, size_t cap, uint32_t target) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void array_remove_at(struct wl_array *arr, size_t offset, size_t size) {
|
||||
assert(arr->size >= offset + size);
|
||||
|
||||
char *data = arr->data;
|
||||
memmove(&data[offset], &data[offset + size], arr->size - offset - size);
|
||||
arr->size -= size;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue