1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_gsacust.c - generic sorted arrays
6 (C) Copyright 2001 by Pavel Pisa - Originator
8 The uLan utilities library can be used, copied and modified under
10 - GPL - GNU General Public License
11 - LGPL - GNU Lesser General Public License
12 - MPL - Mozilla Public License
13 - and other licenses added by project originators
14 Code can be modified and re-distributed under any combination
15 of the above listed licenses. If contributor does not agree with
16 some of the licenses, he/she can delete appropriate line.
17 Warning, if you delete all lines, you are not allowed to
18 distribute source code and/or binaries utilizing code.
20 See files COPYING and README for details.
22 *******************************************************************/
25 #include "ul_utmalloc.h"
28 #define GSA_ALLOC_STEP 8
29 #define GSA_DEALLOC_STEP 32
32 gsa_cust_init_array_field(gsa_array_field_t *array)
41 gsa_cust_insert_at(gsa_array_field_t *array, void *item, unsigned where)
43 unsigned acnt=array->alloc_count;
44 unsigned cnt=array->count;
46 if(where>cnt) where=cnt;
47 if((cnt+1>=acnt)||!array->items)
51 items=malloc(acnt*sizeof(void*));
53 items=realloc(array->items,acnt*sizeof(void*));
55 array->alloc_count=acnt;
58 else items=array->items;
60 memmove(p+1,p,(char*)(items+cnt)-(char*)p);
67 gsa_cust_delete_at(gsa_array_field_t *array, unsigned indx)
69 unsigned acnt=array->alloc_count;
70 unsigned cnt=array->count;
71 void **items=array->items;
73 if(indx>=cnt) return -1;
76 memmove(p,p+1,(items+cnt-p)*sizeof(void *));
77 if(acnt-cnt>GSA_DEALLOC_STEP+GSA_ALLOC_STEP)
79 acnt-=GSA_DEALLOC_STEP;
80 items=realloc(array->items,acnt*sizeof(void*));
82 array->alloc_count=acnt;