-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleafnode_attachleaf.c
62 lines (50 loc) · 1.72 KB
/
leafnode_attachleaf.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
#include "CommandLineInterface/CLIcore.h"
#include "clustering_defs.h"
#include "addvector_to_CF.h"
/**
* @brief Attach EXISITNG leaf to leafnode
*
* @param ctree clustering tree
* @param CFindexleaf CF index of leaf
* @param CFindexleafnode CF index of node to which leaf should be attached
* @return errno_t
*/
errno_t
leafnode_attachleaf(CLUSTERTREE *ctree, long CFindexleaf, long CFindexleafnode)
{
DEBUG_TRACE_FSTART();
ctree->CFarray[CFindexleafnode]
.leafindex[ctree->CFarray[CFindexleafnode].NBleaf] = CFindexleaf;
ctree->CFarray[CFindexleafnode].NBleaf++;
ctree->CFarray[CFindexleaf].parentindex = CFindexleafnode;
ctree->CFarray[CFindexleaf].level =
ctree->CFarray[CFindexleafnode].level + 1;
long cfi = CFindexleafnode;
while(cfi != -1)
{
//printf("========= ADDING VECTOR TO NODE %ld (%s)\n", cfi, __FILE__);
//fflush(stdout);
ctree->CFarray[cfi].status |= CLUSTER_CF_STATUS_UPDATE;
int addOK = 1; // don't test radius
addvector_to_CF(ctree,
ctree->CFarray[CFindexleaf].datasumvec,
ctree->CFarray[CFindexleaf].datassq,
ctree->CFarray[CFindexleaf].N,
cfi,
&addOK);
// move upstream to propagate change
long cfip = ctree->CFarray[cfi].parentindex;
if(cfi == cfip)
{
FUNC_RETURN_FAILURE(
"Attaching leaf %ld to node %ld: CF parent %ld points to "
"itself",
CFindexleaf,
CFindexleafnode,
cfi);
}
cfi = cfip;
}
DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
}