parQHV
Compute HyperVolumes using threads
 All Data Structures Files Functions Variables Macros
arrayList.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) Year(s), 2013, Luis M. S. Russo and Alexandre
4  * P. Francisco / KDBIO / INESC-ID, <qhv@kdbio.inesc-id.pt>
5  *
6  * Any published media that is related with to use of the distributed
7  * software, or derived software, must contain a reference to "Extending
8  * quick hypervolume. Luís M. S. Russo, Alexandre P. Francisco:
9  * J. Heuristics 22(3): 245-271 (2016)".
10  *
11  * Permission to use, copy, modify, and/or distribute this software for
12  * any purpose with or without fee is hereby granted, provided that the
13  * above copyright notice and this permission notice appear in all
14  * copies.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
17  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
19  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
21  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23  * PERFORMANCE OF THIS SOFTWARE.
24  *
25  */
26 
36 #ifndef ARRAYLIST_H
37 #define ARRAYLIST_H
38 
39 #include <stdlib.h>
40 #include <limits.h>
41 #include "macros.h"
42 
43 /*** typedefs(not structures) and defined constants *******/
44 typedef struct arrayList* arrayList;
45 
46 /*** enums ************************************************/
47 
48 /*** structures declarations (and typedefs of )************/
49 struct arrayList{
50  int* A;
51  int n;
52  int bound;
53  int f;
54 };
55 
56 /*** global variables defined in .c file ******************/
57 
58 /*** declarations of public functions *********************/
59 
60 /*** inline functions *************************************/
61 
62 static sureInline(arrayList) newArrayList(int bound)
63 {
64  arrayList S;
65 
66  S = calloc(1, sizeof(struct arrayList));
67  S->bound = bound;
68  S->f = bound;
69 
70  S->A = (int*)calloc(S->bound/S->f, sizeof(int));
71 
72  return S;
73 }
74 
75 static sureInline(arrayList) newArrayListDef()
76 {
77  return newArrayList(INT_MAX);
78 }
79 
80 static sureInline(void) freeArrayList(arrayList* S)
81 {
82  free((*S)->A);
83  free(*S);
84  *S = NULL;
85 }
86 
87 static sureInline(int*) splitAL(arrayList* S)
88 {
89  int* R;
90 
91  R = (int*)realloc((*S)->A, ((*S)->n)*sizeof(int));
92  free(*S);
93  *S = NULL;
94 
95  return R;
96 }
97 
98 static sureInline(void) clean(arrayList S)
99 {
100  S->n = 0;
101 }
102 
103 static sureInline(int*) get(arrayList S)
104 {
105  return S->A;
106 }
107 
108 static sureInline(int) size(arrayList S)
109 {
110  return S->n;
111 }
112 
113 static sureInline(void) pushAL(arrayList S, int k)
114 {
115  if(S->n == (S->bound/S->f))
116  {
117  S->f /= 2;
118  if(S->f < 1) S->f = 1;
119 
120  S->A = (int*) realloc(S->A, (S->bound/S->f)*sizeof(int));
121  }
122 
123  S->A[S->n] = k;
124  (S->n)++;
125 }
126 static sureInline(void) popAL(arrayList S)
127 {
128  (S->n)--;
129 }
130 
131 #endif /* ARRAYLIST_H */
int * A
Definition: arrayList.h:50
int bound
Definition: arrayList.h:52