-
Notifications
You must be signed in to change notification settings - Fork 8
/
fastcci_diamond.cc
65 lines (57 loc) · 1.41 KB
/
fastcci_diamond.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include "fastcci.h"
#if !defined(__APPLE__)
#include <malloc.h>
#endif
/**
* Find all small category diamonds:
*
* A
* / \
* B C
* \ /
* D
*/
int main(int argc, char *argv[]) {
int *cat;
int maxcat = readFile("../fastcci.cat", cat);
maxcat /= sizeof(int);
tree_type *tree;
readFile("../fastcci.tree", tree);
// subsubcat masks
int *ssm1 = (int*)malloc(maxcat * sizeof(int));
int *ssm2 = (int*)malloc(maxcat * sizeof(int));
memset(ssm1, 255, maxcat * sizeof(*ssm1));
// go over all categories that could be the root A of the diamond
int nummatch = 0;
for (int v=0; v<maxcat; ++v)
if (cat[v]>-1)
{
int i = cat[v], cstart = i+2, cend = tree[i];
// go over sub cats and tag sub sub cats
for (int w=cstart; w<cend; ++w)
{
int j = cat[tree[w]], scstart = j+2, scend = tree[j];
// go over sub sub cats and tag
for (int x=scstart; x<scend; ++x)
{
if (ssm1[tree[x]] == v)
{
// we've already seen this subsubcat from another subcat
printf("%d|%d|%d|%d\n", v, ssm2[tree[x]], tree[w], tree[x]);
nummatch++;
}
else
{
ssm1[tree[x]] = v;
ssm2[tree[x]] = tree[w];
}
}
}
}
printf("\n%d diamonds found.\n", nummatch);
free(cat);
free(tree);
return 0;
}