aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarkus Ongyerth <ongy@ongy.net>2018-07-07 17:56:37 +0200
committerMarkus Ongyerth <ongy@ongy.net>2018-07-14 09:52:34 +0200
commit74ca2f8fcf10f5b00b4a3eeb121e418e1b5212e0 (patch)
tree42e3f80ac6870482c00d221d7a342ca144534556 /util
parent43b20bfea2070df78ba7cb12a78a5f7a42dd21f5 (diff)
Another round of feedback from acrisci
Diffstat (limited to 'util')
-rw-r--r--util/array.c21
-rw-r--r--util/meson.build1
2 files changed, 22 insertions, 0 deletions
diff --git a/util/array.c b/util/array.c
new file mode 100644
index 00000000..9ee39d33
--- /dev/null
+++ b/util/array.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+// https://www.geeksforgeeks.org/move-zeroes-end-array/
+size_t push_zeroes_to_end(uint32_t arr[], size_t n) {
+ size_t count = 0;
+
+ for (size_t i = 0; i < n; i++) {
+ if (arr[i] != 0) {
+ arr[count++] = arr[i];
+ }
+ }
+
+ size_t ret = count;
+
+ while (count < n) {
+ arr[count++] = 0;
+ }
+
+ return ret;
+}
diff --git a/util/meson.build b/util/meson.build
index adc52a53..f9d1997d 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -1,6 +1,7 @@
lib_wlr_util = static_library(
'wlr_util',
files(
+ 'array.c',
'log.c',
'os-compatibility.c',
'region.c',