added Mem_ExpandableArray_IndexRange and
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 18 Apr 2007 09:29:50 +0000 (09:29 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 18 Apr 2007 09:29:50 +0000 (09:29 +0000)
Mem_ExpandableArray_RecordAtIndex which allow iterating the array

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7128 d7cf8633-e32d-0410-b094-e92efae38249

zone.c
zone.h

diff --git a/zone.c b/zone.c
index 0bb3253..3cbde6c 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -458,6 +458,28 @@ void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record)
        }
 }
 
+size_t Mem_ExpandableArray_IndexRange(memexpandablearray_t *l)
+{
+       size_t i, j, k;
+       if (!l->numarrays)
+               return 0;
+       i = l->numarrays - 1;
+       for (j = 0, k = 0;k < l->arrays[i].numflaggedrecords;j++)
+               if (l->arrays[i].allocflags[j])
+                       k++;
+       return l->numrecordsperarray * i + j;
+}
+
+void *Mem_ExpandableArray_RecordAtIndex(memexpandablearray_t *l, size_t index)
+{
+       size_t i, j;
+       i = index / l->numrecordsperarray;
+       j = index % l->numrecordsperarray;
+       if (i >= l->numarrays || !l->arrays[i].allocflags[j])
+               return NULL;
+       return (void *)l->arrays[i].data + j * l->recordsize;
+}
+
 
 // used for temporary memory allocations around the engine, not for longterm
 // storage, if anything in this pool stays allocated during gameplay, it is
diff --git a/zone.h b/zone.h
index d70b967..cd19662 100644 (file)
--- a/zone.h
+++ b/zone.h
@@ -158,6 +158,8 @@ void Mem_ExpandableArray_NewArray(memexpandablearray_t *l, mempool_t *mempool, s
 void Mem_ExpandableArray_FreeArray(memexpandablearray_t *l);
 void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l);
 void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record);
+size_t Mem_ExpandableArray_IndexRange(memexpandablearray_t *l);
+void *Mem_ExpandableArray_RecordAtIndex(memexpandablearray_t *l, size_t index);
 
 // used for temporary allocations
 extern mempool_t *tempmempool;