summaryrefslogtreecommitdiff
path: root/src/leven.h
blob: bdd27f6101080afe607f6bf15f87a088ce6bca33 (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
#pragma once

#include <stddef.h>
#include <stdint.h>

#define MAT_TYPE uint32_t
#include "mat.h"

typedef struct {
	uint32_t *data;
	size_t stride[2];
} mat3_uint32_t;

static inline uint32_t* imat3_uint32_t(mat3_uint32_t mat, size_t x, size_t y, size_t z) {
	assert(x >= 0);
	assert(y >= 0 && y < mat.stride[0]);
	assert(z >= 0 && z < mat.stride[1]);
	return &mat.data[x + y*mat.stride[0] + z*(mat.stride[0]*mat.stride[1])];
}
#define DECL_MAT3(NAME, T, X, Y, Z) \
	mat3_uint32_t NAME = { \
		.data = (T[X * Y * Z]){}, \
		.stride = {X, Y}, \
	} \

typedef uint16_t nid;

#define MAT_TYPE nid
#include "mat.h"

void string_edit_distance(const nid *a, size_t la, const nid *b, size_t lb, const mat_uint32_t weight, mat_uint32_t cost);
void string_edit_alignment(const nid *a, size_t la, const nid *b, size_t lb, const mat_uint32_t weight, const mat_uint32_t cost, uint32_t *alignment);

struct Tree {
	mat_nid adj;
	size_t len;
};

typedef struct {
	const mat_uint32_t cost;
	mat_uint32_t cost_n;
	mat_uint32_t cost_f;
	mat_uint32_t cost_s;
} CTedData;

void constrained_tree_distance(
	struct Tree a,
	struct Tree b,
	CTedData data
);

void constrained_tree_alignment(
	const struct Tree a,
	const struct Tree b,
	CTedData data,
	uint32_t *adj_alignment,
	uint32_t *alignment
);