aboutsummaryrefslogtreecommitdiff
path: root/c_implementation/src/ak_fs_mt.c
blob: 2c3414bc2be1f241b4335f162a7970be447949cb (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
#include <stdio.h>
#include <libakfs.h>
#include <libaklog.h>
#include <stdbool.h>

bool ak_fs_mt_branch_is_null(mt_branch* n)
{
    if ( n == NULL )
    {
        ak_log_warning(__func__, "A NULL mt_branch* node was given");
        return false;
    }
    if (
            ak_fs_sha512sum_is_null(&n->root) &&
            ak_fs_sha512sum_is_null(&n->head) &&
            ak_fs_sha512sum_is_null(&n->tail)
       )
    {
        return true;
    }
    return false;
}

bool ak_fs_mt_branch_compare(mt_branch *a, mt_branch *b)
{
    if ( a == NULL || b == NULL )
    {
        ak_log_warning(__func__, "One or two NULL mt_branch* node was given");
        return false;
    }
    if (
            ak_fs_sha512sum_compare(&a->root, &b->root) &&
            ak_fs_sha512sum_compare(&a->head, &b->head) &&
            ak_fs_sha512sum_compare(&a->tail, &b->tail)
       )
    {
        return true;
    }
    return false;
}

void ak_fs_mt_branch_print(mt_branch *n)
{
    if ( n == NULL )
    {
        ak_log_warning(__func__, "NULL mt_branch* was given");
        return;
    }
    printf("r: %s\n", ak_fs_sha512sum_struct_read_as_string(&n->root));
    printf("h: %s\n", ak_fs_sha512sum_struct_read_as_string(&n->head));
    printf("t: %s\n", ak_fs_sha512sum_struct_read_as_string(&n->tail));
}