summaryrefslogtreecommitdiff
path: root/goo/GooList.cc
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2005-03-03 19:45:58 +0000
committerKristian Høgsberg <krh@redhat.com>2005-03-03 19:45:58 +0000
commitcb02d5d0e770e2a8cbe5a8ac810820a2ce5fec0c (patch)
tree89a707862fc867a1aaa879ad3f6fbfb5f16a0a30 /goo/GooList.cc
Initial revision
Diffstat (limited to 'goo/GooList.cc')
-rw-r--r--goo/GooList.cc92
1 files changed, 92 insertions, 0 deletions
diff --git a/goo/GooList.cc b/goo/GooList.cc
new file mode 100644
index 00000000..15b2f5f6
--- /dev/null
+++ b/goo/GooList.cc
@@ -0,0 +1,92 @@
+//========================================================================
+//
+// GooList.cc
+//
+// Copyright 2001-2003 Glyph & Cog, LLC
+//
+//========================================================================
+
+#include <config.h>
+
+#ifdef USE_GCC_PRAGMAS
+#pragma implementation
+#endif
+
+#include <string.h>
+#include "gmem.h"
+#include "GooList.h"
+
+//------------------------------------------------------------------------
+// GooList
+//------------------------------------------------------------------------
+
+GooList::GooList() {
+ size = 8;
+ data = (void **)gmalloc(size * sizeof(void*));
+ length = 0;
+ inc = 0;
+}
+
+GooList::GooList(int sizeA) {
+ size = sizeA;
+ data = (void **)gmalloc(size * sizeof(void*));
+ length = 0;
+ inc = 0;
+}
+
+GooList::~GooList() {
+ gfree(data);
+}
+
+void GooList::append(void *p) {
+ if (length >= size) {
+ expand();
+ }
+ data[length++] = p;
+}
+
+void GooList::append(GooList *list) {
+ int i;
+
+ while (length + list->length > size) {
+ expand();
+ }
+ for (i = 0; i < list->length; ++i) {
+ data[length++] = list->data[i];
+ }
+}
+
+void GooList::insert(int i, void *p) {
+ if (length >= size) {
+ expand();
+ }
+ if (i < length) {
+ memmove(data+i+1, data+i, (length - i) * sizeof(void *));
+ }
+ data[i] = p;
+ ++length;
+}
+
+void *GooList::del(int i) {
+ void *p;
+
+ p = data[i];
+ if (i < length - 1) {
+ memmove(data+i, data+i+1, (length - i - 1) * sizeof(void *));
+ }
+ --length;
+ if (size - length >= ((inc > 0) ? inc : size/2)) {
+ shrink();
+ }
+ return p;
+}
+
+void GooList::expand() {
+ size += (inc > 0) ? inc : size;
+ data = (void **)grealloc(data, size * sizeof(void*));
+}
+
+void GooList::shrink() {
+ size -= (inc > 0) ? inc : size/2;
+ data = (void **)grealloc(data, size * sizeof(void*));
+}