forked from waynebhayes/BLANT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libblant.c
114 lines (106 loc) · 3.6 KB
/
libblant.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <sys/file.h>
#include <sys/mman.h>
#include <assert.h>
#include "blant.h"
char* _BLANT_DIR = DEFAULT_BLANT_DIR;
// Given a TINY_GRAPH and k, return the integer ID created from one triangle (upper or lower) of the adjacency matrix.
int TinyGraph2Int(TINY_GRAPH *g, int k)
{
int i, j, bitPos=0, Gint = 0, bit;
#if LOWER_TRIANGLE // Prefer lower triangle to be compatible with Ine Melckenbeeck's Jesse code.
for(i=k-1;i>0;i--)
{
for(j=i-1;j>=0;j--)
#else // UPPER_TRIANGLE // this is what we used in the original faye code and paper with Adib Hasan and Po-Chien Chung.
for(i=k-2;i>=0;i--)
{
for(j=k-1;j>i;j--)
#endif
{
if(TinyGraphAreConnected(g,i,j))
{
bit = (1 << bitPos);
Gint |= bit;
}
bitPos++;
}
}
return Gint;
}
/*
** Given an integer, build the graph into the TINY_GRAPH *G, which has already been allocated.
** Handles either upper or lower triangle representation depending upon compile-time option below.
*/
void BuildGraph(TINY_GRAPH* G, int Gint)
{
int i, j, bitPos=0, k = G->n;
int Gint2 = Gint; // Gint2 has bits nuked as they're used, so when it's zero we can stop.
TinyGraphEdgesAllDelete(G);
#if LOWER_TRIANGLE
for(i=k-1;i>0;i--)
{
for(j=i-1;j>=0;j--)
#else // UPPER_TRIANGLE
for(i=k-2;i>=0;i--)
{
for(j=k-1;j>i;j--)
#endif
{
if(!Gint2) break;
int bit = (1 << bitPos);
if(Gint & bit)
TinyGraphConnect(G,i,j);
Gint2 &= ~bit;
bitPos++;
}
if(!Gint2) break;
}
}
/*
** Given a pre-allocated filename buffer, a 256MB aligned array K, num nodes k
** Mmap the canon_map binary file to the aligned array.
*/
short int* mapCanonMap(char* BUF, short int *K, int k) {
int Bk = (1 <<(k*(k-1)/2));
sprintf(BUF, "%s/%s/canon_map%d.bin", _BLANT_DIR, CANON_DIR, k);
int Kfd = open(BUF, 0*O_RDONLY);
assert(Kfd > 0);
//short int *Kf = Mmap(K, Bk*sizeof(short int), Kfd); // Using Mmap will cause error due to MAP_FIXED flag
short int *Kf = (short int*) mmap(K, sizeof(short int)*Bk, PROT_READ, MAP_PRIVATE, Kfd, 0);
assert(Kf != MAP_FAILED);
return Kf;
}
int canonListPopulate(char *BUF, int *canon_list, SET *connectedCanonicals, int k) {
sprintf(BUF, "%s/%s/canon_list%d.txt", _BLANT_DIR, CANON_DIR, k);
FILE *fp_ord=fopen(BUF, "r");
if(!fp_ord) Fatal("cannot find %s\n", BUF);
int numCanon, i, connected, numEdges;
assert(1==fscanf(fp_ord, "%d",&numCanon));
for(i=0; i<numCanon; i++) {
assert(3==fscanf(fp_ord, "%d %d %d", &canon_list[i], &connected, &numEdges));
if(connectedCanonicals && connected) SetAdd(connectedCanonicals, i);
}
fclose(fp_ord);
return numCanon;
}
int orbitListPopulate(char *BUF, int orbit_list[MAX_CANONICALS][maxK], int orbit_canon_mapping[MAX_ORBITS], int numCanon, int k) {
sprintf(BUF, "%s/%s/orbit_map%d.txt", _BLANT_DIR, CANON_DIR, k);
FILE *fp_ord=fopen(BUF, "r");
if(!fp_ord) Fatal("cannot find %s\n", BUF);
int numOrbit, i, j;
assert(1==fscanf(fp_ord, "%d",&numOrbit));
for(i=0; i<numCanon; i++) for(j=0; j<k; j++) {
assert(1==fscanf(fp_ord, "%d", &orbit_list[i][j]));
orbit_canon_mapping[orbit_list[i][j]] = i;
}
fclose(fp_ord);
return numOrbit;
}
void orcaOrbitMappingPopulate(char *BUF, int orca_orbit_mapping[58], int k) {
sprintf(BUF, "%s/%s/orca_orbit_mapping%d.txt", _BLANT_DIR, "orca_jesse_blant_table", k);
FILE *fp_ord=fopen(BUF, "r");
if(!fp_ord) Fatal("cannot find %s\n", BUF);
int numOrbit, i;
assert(1==fscanf(fp_ord, "%d",&numOrbit));
for (i=0; i<numOrbit; i++) { assert(1==fscanf(fp_ord, "%d", &orca_orbit_mapping[i])); }
}