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