Main Page | Modules | File List | File Members

array.c

00001 /* ndk - [ array.c ]
00002  *
00003  * A simple, object oriented, array implementation.
00004  * Used for the idt and gdt
00005  *
00006  * Please see:
00007  *     /src/idt.c
00008  *     /src/gdt.c
00009  *
00010  * (c)2002 dcipher / neuraldk
00011  *           www.neuraldk.org
00012  */
00013 
00014 #include "array.h"
00015 
00016 void *arrayElementAt(Array *array, long eNum) {
00017   return (void *)(array->baseAddress +
00018                  (eNum * array->sizeOfElement));
00019 }
00020 
00021 long arrayFindNthEmptyElement(Array *array, int n) {
00022   int i;
00023   void *currentElement;
00024 
00025   for(i = 0; i < array->numElements; i++) {
00026     n -= arrayIsElementEmpty(array, i);
00027     if(n == 1) return i;
00028   }
00029   return -1;
00030 }
00031 
00032 long arrayIsElementEmpty(Array *array, long eNum) {
00033   char *element = (char *)(array->baseAddress +
00034                           (eNum * array->sizeOfElement));
00035   int i = 0;
00036 
00037   while(i < array->sizeOfElement && element[i] == 0) i++;
00038 
00039   if(i <= array->sizeOfElement && element[i] == 0) return 1;
00040   else return 0;
00041 }

Generated on Sun Nov 21 18:26:11 2004 for ndk by doxygen 1.3.2