Repository navigation
Expand file tree
/
Copy pathcorTreeNavigate.c
More file actions
62 lines (47 loc) · 1.65 KB
/
Copy pathcorTreeNavigate.c
File metadata and controls
62 lines (47 loc) · 1.65 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
//
// FILE corTreeNavigate.c
//
// AUTHOR Ken Zangelin
//
// Copyright 2025 Ken Zangelin
//
// SPDX-License-Identifier: Apache-2.0
//
#include <string.h> // strncpy
#include <unistd.h> // NULL
#include <stdbool.h> // bool
#include "corTree/CorNode.h" // CorNode
#include "corTree/corTreeLookup.h" // corTreeLookup
#include "corTree/corTreeNavigate.h" // Own interface
// -----------------------------------------------------------------------------
//
// corTreeNavigate -
//
CorNode* corTreeNavigate(CorNode* treeP, const char** pathCompV, CorNode** parentPP, bool* onlyLastMissingP)
{
CorNode* hitP = corTreeLookup(treeP, pathCompV[0]);
if (parentPP != NULL)
*parentPP = treeP;
if (hitP == NULL) // No hit - we're done
{
if (onlyLastMissingP != NULL)
*onlyLastMissingP = (pathCompV[1] == NULL)? true : false;
return NULL;
}
if (pathCompV[1] == NULL) // Found it - we're done
return hitP;
return corTreeNavigate(hitP, &pathCompV[1], parentPP, onlyLastMissingP); // Recursive call, one level down
}
// -----------------------------------------------------------------------------
//
// corTreeNavigate2 - true KJ-Tree navigation
//
CorNode* corTreeNavigate2(CorNode* treeP, char** compV)
{
CorNode* hitP = corTreeLookup(treeP, compV[0]);
if (hitP == NULL)
return NULL;
if (compV[1] == NULL)
return hitP;
return corTreeNavigate2(hitP, &compV[1]);
}