]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_hptree.c
Fix compilation on GCC 4.7 for ARM ABI.
[ulut.git] / ulut / ul_hptree.c
1 /*******************************************************************
2   uLan Utilities Library - C library of basic reusable constructions
3
4   ul_hptree.c  - heap tree implementation
5
6   (C) Copyright 2003-2004 by Pavel Pisa - Originator
7
8   The uLan utilities library can be used, copied and modified under
9   next licenses
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.
19   
20   See files COPYING and README for details.
21
22  *******************************************************************/
23
24 #include <string.h>
25 #include "ul_utmalloc.h"
26 #include "ul_hptree.h"
27
28 int ul_hpt_init_root_hpt(ul_hpt_root_field_t *hpt_root, int acapacity)
29 {
30   ul_hpt_node_t **ha;
31   hpt_root->count=0;
32   hpt_root->capacity=acapacity;
33   ha=malloc(hpt_root->capacity*sizeof(void *));
34   if(!ha){
35     hpt_root->heaparr=NULL;
36     hpt_root->capacity=0;
37     return -1;
38   }
39   hpt_root->heaparr=ha-1;
40   return 0;
41 }
42
43 int ul_hpt_enlarge_hpt(ul_hpt_root_field_t *hpt_root)
44 {
45   ul_hpt_node_t **ha;
46   long acap;
47   acap=hpt_root->capacity;
48   acap=((acap+7)&(~7))*2;
49   ha=realloc(hpt_root->heaparr+1,acap*sizeof(void *));
50   if(!ha) return -1;  
51   hpt_root->capacity=acap;
52   hpt_root->heaparr=ha-1;
53   return 0;
54 }
55
56 void ul_hpt_done_root_hpt(ul_hpt_root_field_t *hpt_root)
57 {
58   if(hpt_root->heaparr)
59     free(hpt_root->heaparr+1);
60 }