parQHV
Compute HyperVolumes using threads
 All Data Structures Files Functions Variables Macros
subsets.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 <stdlib.h>
28 #include <string.h>
29 #include <stdio.h>
30 #include "macros.h"
31 #include "subsets.h"
32 
33 /*** global variables *************************************/
34 struct setIterator git;
35 
36 /*** file scope macro definitions *************************/
37 
38 /*** file scope type declarations *************************/
39 
40 struct setIterator{
41  int i;
42  unsigned int S[32];
43 };
44 
45 /*** file scope variables *********************************/
46 
47 /*** file scope functions declarations ********************/
48 
49 /*** public functions declarations ************************/
50 
51 /*** file scope functions *********************************/
52 
53 /* ------------------------------------------------------ */
54 
55 /*** public functions *************************************/
56 
57 void newSets(unsigned int t)
58 {
59  int i;
60 
61  i = 0;
62  while(t > 0)
63  {
64  git.S[i] = Rbit(t);
65  i++;
66  t = Rpop(t);
67  }
68 
69  git.i = (1<<i) - 1;
70 }
71 
72 int hasNextSet(void)
73 {
74  return git.i > 0;
75 }
76 
77 unsigned int nextSet(void)
78 {
79  int i;
80  int res;
81 
82  res = 0;
83  i = git.i;
84  git.i--;
85 
86  while(i > 0)
87  {
88  res |= git.S[fastLog2(Rbit(i))];
89  i = Rpop(i);
90  }
91 
92  return res;
93 }
94 
104 /* int main(int argc, char** argv) */
105 /* { */
106 /* newSets(128+64+1); */
107 
108 /* while(hasNextSet()) */
109 /* { */
110 /* printf("%d\n", nextSet()); */
111 /* } */
112 
113 /* return 0; */
114 /* } */
void newSets(unsigned int t)
Definition: subsets.c:57
This returns iterators for diferent type. WARNING, these objects are singleton, so new overwrites exi...
#define Rpop(N)
Definition: subsets.h:88
unsigned int nextSet(void)
Definition: subsets.c:77
#define Rbit(N)
Definition: subsets.h:81
int hasNextSet(void)
Definition: subsets.c:72
#define fastLog2(L)
Definition: subsets.h:98
unsigned int S[32]
Definition: subsets.c:42