summaryrefslogtreecommitdiff
path: root/src/list.h
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2007-10-07 00:36:34 +0200
committerjcid <devnull@localhost>2007-10-07 00:36:34 +0200
commit93715c46a99c96d6c866968312691ec9ab0f6a03 (patch)
tree573f19ec6aa740844f53a7c0eb7114f04096bf64 /src/list.h
Initial revision
Diffstat (limited to 'src/list.h')
-rw-r--r--src/list.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/list.h b/src/list.h
new file mode 100644
index 00000000..8623bf09
--- /dev/null
+++ b/src/list.h
@@ -0,0 +1,49 @@
+/*
+ * Fast list methods
+ * Feb 2000 --Jcid
+ *
+ */
+
+#ifndef __LIST_H__
+#define __LIST_H__
+
+/*
+ * a_List_resize()
+ *
+ * Make sure there's space for 'num_items' items within the list
+ * (First, allocate an 'alloc_step' sized chunk, after that, double the
+ * list size --to make it faster)
+ */
+#define a_List_resize(list,num_items,alloc_step) \
+ if (!list) { \
+ list = dMalloc(alloc_step * sizeof((*list))); \
+ } \
+ if (num_items >= alloc_step){ \
+ while ( num_items >= alloc_step ) \
+ alloc_step <<= 1; \
+ list = dRealloc(list, alloc_step * sizeof((*list))); \
+ }
+
+
+/*
+ * a_List_add()
+ *
+ * Make sure there's space for one more item within the list.
+ */
+#define a_List_add(list,num_items,alloc_step) \
+ a_List_resize(list,num_items,alloc_step)
+
+
+/*
+ * a_List_remove()
+ *
+ * Quickly remove an item from the list
+ * ==> We preserve relative position, but not the element index <==
+ */
+#define a_List_remove(list, item, num_items) \
+ if (list && item < num_items) { \
+ list[item] = list[--num_items]; \
+ }
+
+
+#endif /* __LIST_H__ */