summary refs log tree commit diff
path: root/src/Funcs.h
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-06-16 10:35:45 +0300
committerWlodekM <[email protected]>2024-06-16 10:35:45 +0300
commitabef6da56913f1c55528103e60a50451a39628b1 (patch)
treeb3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/Funcs.h
initial commit
Diffstat (limited to 'src/Funcs.h')
-rw-r--r--src/Funcs.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Funcs.h b/src/Funcs.h
new file mode 100644
index 0000000..3ad535b
--- /dev/null
+++ b/src/Funcs.h
@@ -0,0 +1,52 @@
+#ifndef CC_FUNCS_H
+#define CC_FUNCS_H
+#include "Core.h"
+/* 
+Simple function implementations
+  NOTE: doing min(x++, y) etc will increment x twice!
+Copyright 2014-2023 ClassiCube | Licensed under BSD-3
+*/
+
+#define min(x, y) ((x) < (y) ? (x) : (y))
+#define max(x, y) ((x) > (y) ? (x) : (y))
+#define Array_Elems(arr) (sizeof(arr) / sizeof(arr[0]))
+union IntAndFloat { float f; cc_int32 i; cc_uint32 u; };
+
+#define QuickSort_Swap_Maybe()\
+if (i <= j) {\
+	key = keys[i]; keys[i] = keys[j]; keys[j] = key;\
+	i++; j--;\
+}
+
+#define QuickSort_Swap_KV_Maybe()\
+if (i <= j) {\
+	key = keys[i]; keys[i] = keys[j]; keys[j] = key;\
+	value = values[i]; values[i] = values[j]; values[j] = value;\
+	i++; j--;\
+}
+
+#define QuickSort_Recurse(quickSort)\
+if (j - left <= right - i) {\
+	if (left < j) { quickSort(left, j); }\
+	left = i;\
+} else {\
+	if (i < right) { quickSort(i, right); }\
+	right = j;\
+}
+
+#define LinkedList_Append(item, head, tail)\
+if (!head) { head = item; } else { tail->next = item; }\
+tail       = item;\
+item->next = NULL;
+
+#define LinkedList_Remove(item, cur, head, tail)\
+cur = head; \
+if (head == item) head = item->next;\
+\
+while (cur) {\
+	if (cur->next == item) cur->next = item->next; \
+	\
+	tail = cur;\
+	cur  = cur->next;\
+}
+#endif