exQHV
Compute Exclusive HyperVolumes sequentially
 All Data Structures Files Functions Variables Macros
unionFilter.c
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 
27 #include "unionFilter.h"
28 #include "counterHash.h"
29 #include "arrayList.h"
30 
31 /*** global variables *************************************/
32 
33 arrayList members;
34 counterHash presences;
36 /*** file scope macro definitions *************************/
37 
38 /*** file scope type declarations *************************/
39 
40 /*** file scope variables *********************************/
41 
42 /*** file scope functions declarations ********************/
43 
44 /*** public functions declarations ************************/
45 
46 /*** file scope functions *********************************/
47 
48 /* ------------------------------------------------------ */
49 
50 /*** public functions *************************************/
51 
52 void initUnion(int n)
53 {
54  static int size = 0;
55 
56  if(size < n)
57  {
58  if(size != 0)
59  { /* Free current structs first */
60  freeArrayList(&(members));
61  CHfree(&(presences));
62  }
63 
64  size = 2*n;
65 
66  members = newArrayList(size);
67  presences = CHalloc(size);
68  }
69 }
70 
71 void finishUnion(void)
72 {
73  freeArrayList(&members);
74  CHfree(&presences);
75 }
76 
77 void resetUnion(void)
78 {
79  int i;
80 
81  i = 0;
82  while(i < size(members))
83  {
84  CHzero(presences, get(members)[i]);
85  i++;
86  }
87  clean(members);
88 }
89 
90 int member(int i)
91 {
92  return CHget(presences, i);
93 }
94 
95 void insertUnion(int i)
96 {
97  if(!member(i))
98  pushAL(members, i);
99 
100  CHinc(presences, i, 1);
101 }
102 
counterHash CHalloc(int n)
Definition: counterHash.c:56
void CHzero(counterHash this, int i)
Definition: counterHash.c:78
int CHget(counterHash this, int i)
Definition: counterHash.c:83
A hash for containing counter values.
void CHinc(counterHash this, int i, int a)
Definition: counterHash.c:73
This header implements an arrayList for integers.
void resetUnion(void)
Definition: unionFilter.c:77
void finishUnion(void)
Definition: unionFilter.c:71
Structure for uniting two sets, without repetition.
void initUnion(int n)
Definition: unionFilter.c:52
void CHfree(counterHash *this)
Definition: counterHash.c:66
Less than 1K use array of counters.
Definition: counterHash.c:39
void insertUnion(int i)
Definition: unionFilter.c:95
int member(int i)
Definition: unionFilter.c:90