parQHV
Compute HyperVolumes using threads
 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 /*** file scope macro definitions *************************/
34 
35 /*** file scope type declarations *************************/
36 
37 /*** file scope variables *********************************/
38 
39 /*** file scope functions declarations ********************/
40 
41 /*** public functions declarations ************************/
42 
43 /*** file scope functions *********************************/
44 
45 /* ------------------------------------------------------ */
46 
47 /*** public functions *************************************/
48 
49 void initUnion(int n, struct unionData* ud)
50 {
51  if(ud->size < n)
52  {
53  if(ud->size != 0)
54  { /* Free current structs first */
55  freeArrayList(&(ud->members));
56  CHfree(&(ud->presences));
57  }
58 
59  ud->size = 2*n; /*trick to avoid quadratic problems */
60 
61  ud->members = newArrayList(ud->size);
62  ud->presences = CHalloc(ud->size);
63  }
64 }
65 
66 void finishUnion(struct unionData* ud)
67 {
68  freeArrayList(&(ud->members));
69  CHfree(&(ud->presences));
70 }
71 
72 void resetUnion(struct unionData* ud)
73 {
74  int i;
75 
76  arrayList members = ud->members;
77  counterHash presences = ud->presences;
79  i = 0;
80  while(i < size(members))
81  {
82  CHzero(presences, get(members)[i]);
83  i++;
84  }
85  clean(members);
86 }
87 
88 int member(int i, struct unionData* ud)
89 {
90  return CHget(ud->presences, i);
91 }
92 
93 void insertUnion(int i, struct unionData* ud)
94 {
95  if(!member(i, ud))
96  pushAL(ud->members, i);
97 
98  CHinc(ud->presences, i, 1);
99 }
100 
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 initUnion(int n, struct unionData *ud)
Definition: unionFilter.c:49
int member(int i, struct unionData *ud)
Definition: unionFilter.c:88
Structure for uniting two sets, without repetition.
void CHfree(counterHash *this)
Definition: counterHash.c:66
Less than 1K use array of counters.
Definition: counterHash.c:39
void finishUnion(struct unionData *ud)
Definition: unionFilter.c:66
void resetUnion(struct unionData *ud)
Definition: unionFilter.c:72
void insertUnion(int i, struct unionData *ud)
Definition: unionFilter.c:93