-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.c
69 lines (56 loc) · 1.25 KB
/
common.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
/**
Copyright (c) 2022 Vicente Romero Calero. All rights reserved.
Licensed under the MIT License.
See LICENSE file in the project root for full license information.
*/
#include <stdarg.h>
#include <stdlib.h>
#include "internals.h"
vtenc *vtenc_create(void)
{
vtenc *handler;
handler = malloc(sizeof(*handler));
if (handler) {
handler->params.allow_repeated_values = 1;
handler->params.skip_full_subtrees = 1;
handler->params.min_cluster_length = 1;
handler->out_size = 0;
}
return handler;
}
void vtenc_destroy(vtenc *handler)
{
if (!handler)
return;
free(handler);
}
int vtenc_config(vtenc *handler, int op, ...)
{
va_list ap;
int rc = VTENC_OK;
va_start(ap, op);
switch (op) {
case VTENC_CONFIG_ALLOW_REPEATED_VALUES: {
handler->params.allow_repeated_values = va_arg(ap, int);
break;
}
case VTENC_CONFIG_SKIP_FULL_SUBTREES: {
handler->params.skip_full_subtrees = va_arg(ap, int);
break;
}
case VTENC_CONFIG_MIN_CLUSTER_LENGTH: {
handler->params.min_cluster_length = va_arg(ap, size_t);
break;
}
default: {
rc = VTENC_ERR_CONFIG;
break;
}
}
va_end(ap);
return rc;
}
size_t vtenc_encoded_size(vtenc *enc)
{
return enc->out_size;
}