-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterativeSubtreeIsomorphism.c
More file actions
669 lines (543 loc) · 20.8 KB
/
iterativeSubtreeIsomorphism.c
File metadata and controls
669 lines (543 loc) · 20.8 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "newCube.h"
#include "graph.h"
#include "bipartiteMatching.h"
#include "subtreeIsoUtils.h"
#include "bitSet.h"
#include "cachedGraph.h"
#include "iterativeSubtreeIsomorphism.h"
// MISC TOOLING
/* vertices of g have their ->visited values set to the postorder. Thus,
children of v are vertices u that are neighbors of v and have u->visited < v->visited */
static struct Graph* makeBipartiteInstanceFromVertices(struct SubtreeIsoDataStore data, struct Vertex* removalVertex, struct Vertex* u, struct Vertex* v, struct GraphPool* gp) {
struct Graph* B;
int sizeofX = degree(u);
int sizeofY = degree(v);
// if one of the neighbors of u is removed from this instance to see if there is a matching covering all neighbors but it,
// the bipartite graph must be smaller
if (removalVertex->number != u->number) {
--sizeofX;
}
/* construct bipartite graph B(v,u) */
B = createGraph(sizeofX + sizeofY, gp);
/* store size of first partitioning set */
B->number = sizeofX;
/* add vertex numbers of original vertices to ->lowPoint of each vertex in B
and add edge labels to vertex labels to compare edges easily */
int i = 0;
for (struct VertexList* e=u->neighborhood; e!=NULL; e=e->next) {
if (e->endPoint->number != removalVertex->number) {
B->vertices[i]->lowPoint = e->endPoint->number;
B->vertices[i]->label = e->label;
++i;
}
}
for (struct VertexList* e=v->neighborhood; e!=NULL; e=e->next) {
B->vertices[i]->lowPoint = e->endPoint->number;
B->vertices[i]->label = e->label;
++i;
}
/* add edge (x,y) if u in S(y,x) */
for (i=0; i<sizeofX; ++i) {
int x = B->vertices[i]->lowPoint;
for (int j=sizeofX; j<B->n; ++j) {
int y = B->vertices[j]->lowPoint;
/* y has to be a child of v */
if (data.g->vertices[y]->visited < v->visited) {
/* edge labels have to match, (v, child)->label in g == (u, child)->label in h
these values were stored in B->vertices[i,j]->label */
if (labelCmp(B->vertices[i]->label, B->vertices[j]->label) == 0) {
if (containsCharacteristic(data, u, data.h->vertices[x], data.g->vertices[y])) {
addResidualEdges(B->vertices[i], B->vertices[j], gp->listPool);
++B->m;
}
}
}
}
}
return B;
}
int computeCharacteristic(struct SubtreeIsoDataStore data, struct Vertex* y, struct Vertex* u, struct Vertex* v, struct GraphPool* gp) {
// TODO speedup by handling leaf case separately
struct Graph* B = makeBipartiteInstanceFromVertices(data, y, u, v, gp);
int sizeofMatching = bipartiteMatchingEvenMoreDirty(B);
int nNeighbors = B->number;
dumpGraph(gp, B);
return (sizeofMatching == nNeighbors) ? 1 : 0;
}
/* vertices of g have their ->visited values set to the postorder. Thus,
children of v are vertices u that are neighbors of v and have u->visited < v->visited */
static struct Graph* makeBipartiteInstanceFromVerticesCached(struct SubtreeIsoDataStore data, struct CachedGraph* cachedB, struct Vertex* removalVertex, struct Vertex* u, struct Vertex* v, struct GraphPool* gp) {
int sizeofX = degree(u);
int sizeofY = degree(v);
// if one of the neighbors of u is removed from this instance to see if there is a matching covering all neighbors but it,
// the bipartite graph must be smaller
if (removalVertex->number != u->number) {
--sizeofX;
}
struct Graph* B = getCachedGraph(sizeofX + sizeofY, cachedB);
/* store size of first partitioning set */
B->number = sizeofX;
/* add vertex numbers of original vertices to ->lowPoint of each vertex in B
and add edge labels to vertex labels to compare edges easily */
int i = 0;
for (struct VertexList* e=u->neighborhood; e!=NULL; e=e->next) {
if (e->endPoint->number != removalVertex->number) {
B->vertices[i]->lowPoint = e->endPoint->number;
B->vertices[i]->label = e->label;
++i;
}
}
for (struct VertexList* e=v->neighborhood; e!=NULL; e=e->next) {
B->vertices[i]->lowPoint = e->endPoint->number;
B->vertices[i]->label = e->label;
++i;
}
/* add edge (x,y) if u in S(y,x) */
for (i=0; i<sizeofX; ++i) {
int x = B->vertices[i]->lowPoint;
for (int j=sizeofX; j<B->n; ++j) {
int y = B->vertices[j]->lowPoint;
/* y has to be a child of v */
if (data.g->vertices[y]->visited < v->visited) {
/* edge labels have to match, (v, child)->label in g == (u, child)->label in h
these values were stored in B->vertices[i,j]->label */
if (labelCmp(B->vertices[i]->label, B->vertices[j]->label) == 0) {
if (containsCharacteristic(data, u, data.h->vertices[x], data.g->vertices[y])) {
addResidualEdges(B->vertices[i], B->vertices[j], gp->listPool);
++B->m;
}
}
}
}
}
return B;
}
//
//int computeCharacteristicCached(struct SubtreeIsoDataStore data, struct CachedGraph* cachedB, struct Vertex* y, struct Vertex* u, struct Vertex* v, struct GraphPool* gp) {
// struct Graph* B = makeBipartiteInstanceFromVerticesCached(data, cachedB, y, u, v, gp);
// int sizeofMatching = bipartiteMatchingEvenMoreDirty(B);
//
// int nNeighbors = B->number;
// returnCachedGraph(cachedB);
// return (sizeofMatching == nNeighbors) ? 1 : 0;
//}
int computeCharacteristicCached(struct SubtreeIsoDataStore data, struct CachedGraph* cachedB, struct Vertex* y, struct Vertex* u, struct Vertex* v, struct GraphPool* gp) {
struct Graph* B = makeBipartiteInstanceFromVerticesCached(data, cachedB, y, u, v, gp);
char hasMatchingCoveringAll = bipartiteMatchingTerminateEarly(B);
returnCachedGraph(cachedB);
return hasMatchingCoveringAll;
}
int* getParentsFromPostorder(struct Graph* g, int* postorder) {
int* parents = malloc(g->n * sizeof(int));
for (int i=0; i<g->n; ++i) {
int v = postorder[i];
parents[v] = g->vertices[v]->lowPoint;
}
return parents;
}
/* Return an array holding the indices of the parents of each vertex in g with root root.
the parent of root does not exist, which is indicated by index -1 */
int* getParents(struct Graph* g, int root) {
int* postorder = getPostorder(g, root);
int* parents = getParentsFromPostorder(g, postorder);
free(postorder);
return parents;
}
// SUBTREE ISOMORPHISM
/**
Iterative Labeled Subtree Isomorphism Check.
Implements the labeled subtree isomorphism algorithm of
Ron Shamir, Dekel Tsur [1999]: Faster Subtree Isomorphism in an iterative version:
Input:
a text tree g
a pattern tree h
the cube that was computed for some subtree h-e and g, where e is an edge to a leaf of h
(object pool data structures)
Output:
yes, if h is subgraph isomorphic to g, no otherwise
the cube for h and g
*/
static void iterativeSubtreeCheck_intern(struct SubtreeIsoDataStore base, struct SubtreeIsoDataStore* current, struct GraphPool* gp) {
struct Graph* g = current->g;
struct Graph* h = current->h;
// new vertex and adjacent one
struct Vertex* b = h->vertices[h->n - 1];
struct Vertex* a = b->neighborhood->endPoint;
int* parentsHa = getParents(h, a->number); // move out / rewrite
struct CachedGraph* cachedB = initCachedGraph(gp, h->n);
current->foundIso = 0;
for (int vi=0; vi<g->n; ++vi) {
struct Vertex* v = g->vertices[current->postorder[vi]];
// add new characteristics
if (containsCharacteristic(base, a, a, v)) {
addCharacteristic(current, b, a, v);
}
if (labelCmp(v->label, b->label) == 0) {
addCharacteristic(current, a, b, v);
// optimized version of computeCharacteristic(*current, b, b, v, gp);
for (struct VertexList* e=v->neighborhood; e!= NULL; e=e->next) {
if (labelCmp(e->label, b->neighborhood->label) == 0) {
// check if e->endPoint is not the parent of v
if (e->endPoint->number != v->lowPoint) {
if (containsCharacteristic(*current, b, a, e->endPoint)) {
addCharacteristic(current, b, b, v);
current->foundIso = 1;
break;
}
}
}
}
}
// filter existing characteristics
for (int ui=0; ui<h->n-1; ++ui) {
struct Vertex* u = h->vertices[ui];
#ifndef BITCUBE
#ifdef INTCUBE
int* oldCharacteristics = rawCharacteristics(base, u, v);
#endif
#ifdef BYTECUBE
uint8_t* oldCharacteristics = rawCharacteristics(base, u, v);
#endif
for (int yi=1; yi<=oldCharacteristics[0]; ++yi) {
struct Vertex* y = h->vertices[oldCharacteristics[yi]];
if (y->number == parentsHa[u->number]) { // might be a problem for y == a ?
addCharacteristic(current, y, u, v);
} else {
int yuCharacteristic = computeCharacteristicCached(*current, cachedB, y, u, v, gp);
if (yuCharacteristic) {
addCharacteristic(current, y, u, v);
if (y == u) {
current->foundIso = 1;
}
}
}
}
#else
// cache computation. yes, this makes a difference! hottest part of this code is checking if a characteristic exists in base.
size_t cubeOffset = (v->number * base.h->n + u->number) * base.h->n;
if (getBit(base.S, cubeOffset + u->number)) {
int uuCharacteristic = computeCharacteristicCached(*current, cachedB, u, u, v, gp);
if (uuCharacteristic) {
addCharacteristic(current, u, u, v);
current->foundIso = 1;
}
}
for (struct VertexList* e=u->neighborhood; e!=NULL; e=e->next) {
struct Vertex* y = e->endPoint;
if (y == b) { continue; } // already dealt with above
if (!getBit(base.S, cubeOffset + y->number)) { continue; } // this is the whole point of this algorithm
if (y->number == parentsHa[u->number]) { // might be a problem for y == a ?
addCharacteristic(current, y, u, v);
} else {
int yuCharacteristic = computeCharacteristicCached(*current, cachedB, y, u, v, gp);
if (yuCharacteristic) {
addCharacteristic(current, y, u, v);
}
}
}
#endif
}
}
free(parentsHa);
dumpCachedGraph(cachedB);
}
struct SubtreeIsoDataStore iterativeSubtreeCheck(struct SubtreeIsoDataStore base, struct Graph* h, struct GraphPool* gp) {
struct SubtreeIsoDataStore info = {0};
info.g = base.g;
info.h = h;
info.postorder = base.postorder;
createNewCubeFromBase(base, &info);
iterativeSubtreeCheck_intern(base, &info, gp);
return info;
}
// INITIALIZATORS
struct SubtreeIsoDataStore initG(struct Graph* g) {
struct SubtreeIsoDataStore info = {0};
info.postorder = getPostorder(g, 0);
info.g = g;
return info;
}
/** create the set of characteristics for a single edge pattern graph */
struct SubtreeIsoDataStore initIterativeSubtreeCheckForEdge(struct SubtreeIsoDataStore base, struct Graph* h) {
struct SubtreeIsoDataStore info = {0};
// copy stuff from below
info.g = base.g;
info.postorder = base.postorder;
// create graph from edge
info.h = h;
char* edgeLabel = h->vertices[0]->neighborhood->label;
// create cube
createNewCubeForEdgePattern(&info);
int* parents = getParentsFromPostorder(info.g, info.postorder);
for (int vi=0; vi<(info.g)->n; ++vi) {
struct Vertex* v = (info.g)->vertices[info.postorder[vi]];
for (int ui=0; ui<2; ++ui) {
struct Vertex* u = (info.h)->vertices[ui];
struct Vertex* y = (info.h)->vertices[(ui + 1) % 2];
if (labelCmp(v->label, u->label) == 0) {
// if vertex labels match, there is a characteristic (H^y_u, v)
addCharacteristic(&info, y, u, v);
char foundIso = 0;
// if there is at least one edge that matches and does not lead to the parent, then there is a characteristic (H^u_u, v)
// we add this characteristic only once below
for (struct VertexList* e=v->neighborhood; e!=NULL; e=e->next) {
if (parents[v->number] != e->endPoint->number) {
// check if edge labels match
if (labelCmp(e->label, edgeLabel) == 0) {
// if edge does not lead to parent, there is a characteristic (H^u_u, v) if vertex labels of endpoint match
if (labelCmp(e->endPoint->label, y->label) == 0) {
foundIso = 1;
}
}
}
}
if (foundIso) {
addCharacteristic(&info, u, u, v);
info.foundIso = 1;
}
}
}
}
free(parents);
return info;
}
/** create the set of characteristics for a single vertex pattern graph */
struct SubtreeIsoDataStore initIterativeSubtreeCheckForSingleton(struct SubtreeIsoDataStore base, struct Graph* h) {
struct SubtreeIsoDataStore info = {0};
// copy stuff from below
info.g = base.g;
info.postorder = base.postorder;
info.h = h;
struct Vertex* u = h->vertices[0];
char* uLabel = u->label;
// create cube
createNewCubeForSingletonPattern(&info);
for (int vi=0; vi<(info.g)->n; ++vi) {
struct Vertex* v = (info.g)->vertices[info.postorder[vi]];
if (labelCmp(v->label, uLabel) == 0) {
// if vertex labels match, there is a characteristic (H^y_u, v)
addCharacteristic(&info, u, u, v);
info.foundIso = 1;
}
}
return info;
}
/** create the set of characteristics for a single edge pattern graph, given as VertexList. A new graph is created. */
struct SubtreeIsoDataStore initIterativeSubtreeCheck(struct SubtreeIsoDataStore base, struct VertexList* patternEdge, struct GraphPool* gp) {
// create graph from edge
struct Graph* h = createGraph(2, gp);
(h)->vertices[0]->label = patternEdge->startPoint->label;
(h)->vertices[1]->label = patternEdge->endPoint->label;
addEdgeBetweenVertices(0, 1, patternEdge->label, h, gp);
return initIterativeSubtreeCheckForEdge(base, h);
}
/// NONITERATIVE VERSION OF SUBTREE ISO ALGORITHM THAT IS COMPATIBLE WITH ABOVE
void addNoncriticalVertexCharacteristics(struct SubtreeIsoDataStore* data, struct Graph* B, struct Vertex* u, struct Vertex* v) {
/* the maximum matching computed above covers all but one neighbor of u
we need to identify those covered neighbors that can be swapped with
that uncovered neighbor without decreasing the cardinality of the matching
these are exactly the non-critical vertices.
a vertex is critical <=> 1.) AND NOT 2.)
hence
a vertex is non-critical <=> NOT 1.) OR 2.)
where
1.) matched in the matching above
2.) reachable by augmenting path from the single unmatched vertex.
This means, all vertices reachable from the single uncovered neighbor of u (including that neighbor are non-critical.
*/
struct Vertex* uncoveredNeighbor = NULL;
// find the single uncovered neighbor of u
for (int i=0; i<B->number; ++i) {
if (!isMatched(B->vertices[i])) {
uncoveredNeighbor = B->vertices[i];
break;
}
}
// mark all vertices reachable from uncoveredNeighbor by an augmenting path
markReachable(uncoveredNeighbor, B->number);
// add non-critical vertices to output
for (int i=0; i<B->number; ++i) {
if (B->vertices[i]->visited == 1) {
// vertex is not critical, add characteristic
addCharacteristicRaw(data, B->vertices[i]->lowPoint, u->number, v->number);
}
}
}
/**
Iterative Labeled Subtree Isomorphism Check.
Implements the labeled subtree isomorphism algorithm of
Ron Shamir, Dekel Tsur [1999]: Faster Subtree Isomorphism in an iterative version:
Input:
a text tree g
a pattern tree h
the cube that was computed for some subtree h-e and g, where e is an edge to a leaf of h
(object pool data structures)
Output:
yes, if h is subgraph isomorphic to g, no otherwise
the cube for h and g
*/
static void noniterativeSubtreeCheck_intern(struct SubtreeIsoDataStore* current, struct GraphPool* gp) {
struct Graph* g = current->g;
struct Graph* h = current->h;
struct CachedGraph* cachedB = initCachedGraph(gp, h->n);
current->foundIso = 0;
for (int vi=0; vi<g->n; ++vi) {
struct Vertex* v = g->vertices[current->postorder[vi]];
for (int ui=0; ui<h->n; ++ui) {
struct Vertex* u = h->vertices[ui];
// check if vertex labels match
if (labelCmp(u->label, v->label) != 0) { continue; }
// compute maximum matching
struct Graph* B = makeBipartiteInstanceFromVerticesCached(*current, cachedB, u, u, v, gp);
int sizeofMatching = bipartiteMatchingEvenMoreDirty(B);
int nNeighbors = B->number;
// is there a subgraph iso here?
if (sizeofMatching == nNeighbors) {
addCharacteristic(current, u, u, v);
current->foundIso = 1;
returnCachedGraph(cachedB);
dumpCachedGraph(cachedB);
return; // early termination when subtree iso is found
}
// compute partial subgraph isomorphisms
if (sizeofMatching == nNeighbors - 1) {
addNoncriticalVertexCharacteristics(current, B, u, v);
}
returnCachedGraph(cachedB);
}
}
dumpCachedGraph(cachedB);
}
struct SubtreeIsoDataStore noniterativeSubtreeCheck(struct SubtreeIsoDataStore base, struct Graph* h, struct GraphPool* gp) {
struct SubtreeIsoDataStore info = {0};
info.g = base.g;
info.h = h;
info.postorder = base.postorder;
if (info.g->n > 0) {
info.S = createNewCube(info.g->n, info.h->n);
noniterativeSubtreeCheck_intern(&info, gp);
dumpNewCube(info.S, info.g->n);
} else {
// if g is empty, then h only matches if it is empty as well.
// g->n == 0 is a special case that is not handled well by the subtree iso algorithm
info.foundIso = h->n == 0 ? 1 : 0;
}
info.S = NULL;
return info;
}
/**
* Due to historic reasons, this function checks if h is subgraph isomorphic to g.
*/
char isSubtree(struct Graph* g, struct Graph* h, struct GraphPool* gp) {
struct SubtreeIsoDataStore info = {0};
info.g = g;
info.h = h;
if (info.g->n > 0) {
info.postorder = getPostorder(g, 0);
info.S = createNewCube(info.g->n, info.h->n);
noniterativeSubtreeCheck_intern(&info, gp);
dumpNewCube(info.S, info.g->n);
free(info.postorder);
} else {
// if g is empty, then h only matches if it is empty as well.
// g->n == 0 is a special case that is not handled well by the subtree iso algorithm
info.foundIso = h->n == 0 ? 1 : 0;
}
return info.foundIso;
}
/**
Iterative Labeled Subtree Isomorphism Check.
Implements the labeled subtree isomorphism algorithm of
Ron Shamir, Dekel Tsur [1999]: Faster Subtree Isomorphism in an iterative version:
Input:
a text tree g
a pattern tree h
the cube that was computed for some subtree h-e and g, where e is an edge to a leaf of h
(object pool data structures)
Output:
yes, if h is subgraph isomorphic to g, no otherwise
the cube for h and g
*/
static struct Vertex* noniterativeRootedSubtreeCheck_intern(struct SubtreeIsoDataStore* current, struct Vertex* hRoot, struct GraphPool* gp) {
struct Graph* g = current->g;
struct Graph* h = current->h;
struct CachedGraph* cachedB = initCachedGraph(gp, h->n);
current->foundIso = 0;
for (int vi=0; vi<g->n; ++vi) {
struct Vertex* v = g->vertices[current->postorder[vi]];
for (int ui=0; ui<h->n; ++ui) {
struct Vertex* u = h->vertices[ui];
// check if vertex labels match
if (labelCmp(u->label, v->label) != 0) { continue; }
// compute maximum matching
struct Graph* B = makeBipartiteInstanceFromVerticesCached(*current, cachedB, u, u, v, gp);
int sizeofMatching = bipartiteMatchingEvenMoreDirty(B);
int nNeighbors = B->number;
// is there a subgraph iso here?
if (sizeofMatching == nNeighbors) {
addCharacteristic(current, u, u, v);
if (u == hRoot) {
current->foundIso = 1;
returnCachedGraph(cachedB);
dumpCachedGraph(cachedB);
return v; // early termination when subtree iso is found
}
}
// compute partial subgraph isomorphisms
if (sizeofMatching == nNeighbors - 1) {
addNoncriticalVertexCharacteristics(current, B, u, v);
}
returnCachedGraph(cachedB);
}
}
dumpCachedGraph(cachedB);
return NULL;
}
/**
* This method checks whether h, rooted at hRoot, is a rooted subtree of g, rooted at gRoot.
* It internally uses the labeled (unrooted) subtree isomorphism algorithm of
* Ron Shamir, Dekel Tsur [1999]: Faster Subtree Isomorphism
*
* but checks, when an undirected subtree iso from h to g is found, whether the vertex of h that is mapped to the
* 'highest' vertex in g rooted at gRoot is hRoot.
*
* If there exists such a subgraph iso, then the function returns a pointer to the image vertex in g; otherwise, it returns NULL.
*/
struct Vertex* computeRootedSubtreeEmbedding(struct Graph* g, struct Vertex* gRoot, struct Graph* h, struct Vertex* hRoot, struct GraphPool* gp) {
struct SubtreeIsoDataStore info = {0};
info.g = g;
info.h = h;
struct Vertex* rootMapping = NULL;
if (info.g->n > 0) {
info.postorder = getPostorder(g, gRoot->number);
info.S = createNewCube(info.g->n, info.h->n);
rootMapping = noniterativeRootedSubtreeCheck_intern(&info, hRoot, gp);
dumpNewCube(info.S, info.g->n);
free(info.postorder);
} else {
// if g is empty, then h only matches if it is empty as well.
// g->n == 0 is a special case that is not handled well by the subtree iso algorithm
info.foundIso = h->n == 0 ? 1 : 0;
}
return rootMapping;
}
struct SubtreeIsoDataStore noniterativeRootedSubtreeCheck(struct SubtreeIsoDataStore base, struct Graph* h, struct Vertex** rootEmbedding, struct GraphPool* gp) {
struct SubtreeIsoDataStore info = {0};
info.g = base.g;
info.h = h;
info.postorder = base.postorder;
if (info.g->n > 0) {
info.S = createNewCube(info.g->n, info.h->n);
*rootEmbedding = noniterativeRootedSubtreeCheck_intern(&info, h->vertices[0], gp);
dumpNewCube(info.S, info.g->n);
} else {
// if g is empty, then h only matches if it is empty as well.
// g->n == 0 is a special case that is not handled well by the subtree iso algorithm
info.foundIso = h->n == 0 ? 1 : 0;
}
info.S = NULL;
return info;
}