-
Notifications
You must be signed in to change notification settings - Fork 8
/
fastcci_pfs_search.cc
60 lines (49 loc) · 1.39 KB
/
fastcci_pfs_search.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
#include <stdio.h>
#include <stdlib.h>
#include "fastcci.h"
#if !defined(__APPLE__)
#include <malloc.h>
#endif
// Search categories with a given number of Parent cat, File, and Sub cat counts
int main(int argc, char *argv[]) {
if (argc!=4) exit(1);
int P = atoi(argv[1]);
int F = atoi(argv[1]);
int S = atoi(argv[1]);
int *cat;
int maxcat = readFile("../fastcci.cat", cat);
maxcat /= sizeof(int);
tree_type *tree;
readFile("../fastcci.tree", tree);
// parent category counter
int *pcc = (int*)malloc(maxcat * sizeof(int));
memset(pcc, 0, maxcat * sizeof(*pcc));
// go over all cats and increment pcc for the subcats
printf("Counting each categorie's parents...\n");
for (int v=0; v<maxcat; ++v)
if (cat[v]>-1)
{
int i = cat[v], cstart = i+2, cend = tree[i];
// increase parent cat counter
for (int j=cstart; j<cend; ++j) pcc[tree[j]]++;
}
// go over all cats and compare pcc, file count, and subcat count
printf("Matching...\n");
int nummatch = 0;
for (int v=0; v<maxcat; ++v)
if (cat[v]>-1)
{
int i = cat[v], cstart = i+2, cend = tree[i], cfile = tree[i+1];
// counters
int nfile = cfile - cend;
int scc = cend - cstart;
if (pcc[v]==P && nfile==F && scc==S) {
nummatch++;
printf("%d|", v);
}
}
printf("\n%d matches found.\n", nummatch);
free(cat);
free(tree);
return 0;
}