6 typedef struct Region
{
9 Region():corner_count(0),corners(NULL
) { }
15 Node():v(0),next(NULL
) {}
16 Node(int v
, Node
*next
):v(v
),next(next
) {}
23 List():item(0),len(0),first(NULL
),last(NULL
) { }
26 Region
*regions
= new Region
[99999];
27 List
*adj
= new List
[99999];
29 void list_append(List
*list
, int item
) {
30 if ( list
->first
== NULL
) {
31 list
->first
= new Node(item
, NULL
);
32 list
->last
= list
->first
;
34 list
->last
->next
= new Node(item
,NULL
);
35 list
->last
= list
->last
->next
;
40 typedef void *iter_func(int item
);
42 void list_iter(List
*list
, iter_func f
) {
43 Node
*cur
= list
->first
;
44 for( ;cur
!= NULL
;cur
= cur
->next
) {
49 void print_item(int item
) {
50 printf("item: %d", item
);
60 bool share_a_corner(Region
*a
, Region
*b
) {
61 for ( int ca
= 0; ca
< a
->corner_count
; ca
+= 2) {
62 float ax
= a
->corners
[ca
];
63 float ay
= a
->corners
[ca
+1];
64 for ( int cb
= 0; cb
< b
->corner_count
; cb
+= 2) {
65 float bx
= b
->corners
[cb
];
66 float by
= b
->corners
[cb
+1];
67 if ( ax
== bx
&& ay
== by
)
75 FILE *f
= fopen("dat.cache", "rb");
76 clock_t start
= clock();
77 printf("CLOCKS_PER_SEC: %d\r\n", CLOCKS_PER_SEC
);
82 if ( fread(&id
, sizeof(int), 1, f
) == 0 ) break;
83 if ( fread(&num_v
, sizeof(short), 1, f
) == 0 ) break;
84 int num_floats
= num_v
*2;
85 float *row
= new float[num_floats
];
86 if ( fread(row
, sizeof(float), num_floats
, f
) < num_floats
) break;
87 regions
[id
].corner_count
= num_v
;
88 regions
[id
].corners
= row
;
91 printf("Loading %d boundaries took: %d ms\r\n", region_count
, (clock()- start
));
94 for ( int i
= 0; i
< 99999; i
++ ) {
95 Region
*a
= ®ions
[i
];
96 clock_t row_start
= clock();
97 // printf("Starting region %d\r\n", i);
99 if ( a
->corner_count
> 0 ) {
100 for ( int j
= 0; j
< 99999; j
++ ) {
101 Region
*b
= ®ions
[j
];
102 if ( b
->corner_count
> 0 ) {
103 if ( share_a_corner(a
, b
) == 1 ) {
104 // printf("Connecting %d -> %d\r\n", i, j);
106 list_append(&adj
[i
], j
);
111 int elapsed
= (clock() - start
);
112 float pct_complete
= i
/99999.0;
113 int remaining
= elapsed
* ((1 - pct_complete
) / pct_complete
);
114 printf("[%.2f%% Elapsed: %d s ETA: %d s] Region %d took %d ms \r", pct_complete
*100, elapsed
/1000, remaining
/1000, i
, (clock() - row_start
));
117 printf("Computing adj took: %d ms\r\n", (clock() - start
));
118 FILE *out
= fopen("adj.cache","wb");
119 for ( int i
= 0; i
< 99999; i
++) {
120 List
*list
= &adj
[i
];
121 if ( list
->len
== 0 ) continue;
122 printf("index: %d (%d items): ", i
, list
->len
);
123 fwrite(&i
, sizeof(int), 1, out
);
124 fwrite(&list
->len
, sizeof(short), 1, out
);
125 Node
*cur
= list
->first
;
126 while( cur
!= NULL
) {
127 fwrite(&cur
->v
, sizeof(int), 1, out
);
128 printf("%d ", cur
->v
);