summaryrefslogtreecommitdiff
path: root/cmd/main.c
blob: 541d646b04da4d9529fdebf2b1e8570312edc17b (plain)
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
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#include "leven.h"
#include "parse.h"

int main(int argc, char **argv) {
	int rc;
	/* int fd = open("filename", O_RDONLY); */
	/* int len = lseek(fd, 0, SEEK_END); */
	/* void *data = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); */

	char* a = "<root><a/><b></b></root>";
	char* b = "<root><a><b/></a></root>";

	struct Tree a_tree;
	size_t *a_chunks;
	rc = parse_string(a, &a_tree, &a_chunks);
	if(rc != 0) return 1;
	printf("%ld\n", a_tree.len);

	struct Tree b_tree;
	size_t *b_chunks;
	rc = parse_string(b, &b_tree, &b_chunks);
	if(rc != 0) return 1;
	printf("%ld\n", b_tree.len);

	DECL_MAT_DATA(cost, uint32_t, 4, 4,
		0, 2, 2, 2,
		2, 0, 1, 1,
		2, 1, 0, 1,
		2, 1, 1, 0,
	);
	printf("\n");
	for(size_t y = 0; y < b_tree.len; y++) {
		for(size_t x = 0; x < b_tree.adj.stride; x++) {
			printf("%d ", *imat_nid(b_tree.adj, x, y));
		}
		printf("\n");
	}
	printf("\n");
	printf("\n");
	for(size_t y = 0; y < a_tree.len; y++) {
		for(size_t x = 0; x < a_tree.adj.stride; x++) {
			printf("%d ", *imat_nid(a_tree.adj, x, y));
		}
		printf("\n");
	}
	printf("\n");
	/* mat_uint32_t cost = { */
	/* 	.data = malloc(a_tree.len * b_tree.len * sizeof(uint32_t)), */
	/* 	.stride = a_tree.len, */
	/* }; */
	/* assert(cost.data != NULL); */

	mat_uint32_t cost_n = {
		.data = malloc((a_tree.len+1) * (b_tree.len+1) * sizeof(uint32_t)),
		.stride = a_tree.len+1,
	};
	assert(cost_n.data != NULL);

	mat_uint32_t cost_f = {
		.data = malloc((a_tree.len+1) * (b_tree.len+1) * sizeof(uint32_t)),
		.stride = a_tree.len+1,
	};
	assert(cost_f.data != NULL);

	mat_uint32_t cost_s = {
		.data = malloc((a_tree.adj.stride+1) * (b_tree.adj.stride+1) * sizeof(uint32_t)),
		.stride = a_tree.adj.stride+1,
	};
	assert(cost_s.data != NULL);

	constrained_tree_distance(a_tree, b_tree, cost, cost_n, cost_f, cost_s);

	printf("COST_F\n");
	for(size_t y = 0; y < b_tree.len+1; y++) {
		for(size_t x = 0; x < cost.stride; x++) {
			printf("%d ", *imat_uint32_t(cost_f, x, y));
		}
		printf("\n");
	}
	printf("\n");
	printf("COST_N\n");
	for(size_t y = 0; y < b_tree.len+1; y++) {
		for(size_t x = 0; x < cost.stride; x++) {
			printf("%d ", *imat_uint32_t(cost_n, x, y));
		}
		printf("\n");
	}
	printf("\n");

	printf("%d\n", *imat_uint32_t(cost_n, 1, 1));

	DECL_MAT(alignment, uint32_t, 2, 2);
	uint32_t adj_alignment[2] = {0, 0};
	constrained_tree_alignment(
		a_tree,
		b_tree,
		cost,
		cost_n,
		cost_f,
		cost_s,
		adj_alignment,
		alignment
	);

	printf("Hello sailor\n");
	return 0;
}