diff options
Diffstat (limited to 'source/blender/blenlib/intern/graph.c')
-rw-r--r-- | source/blender/blenlib/intern/graph.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index fce9d0b6d95..32d9f3b91b7 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -90,12 +90,6 @@ static void addArcToNodeAdjacencyList(BNode *node, BArc *arc) node->flag++; } -void BLI_rebuildAdjacencyList(BGraph *rg) -{ - BLI_freeAdjacencyList(rg); - BLI_buildAdjacencyList(rg); -} - void BLI_buildAdjacencyList(BGraph *rg) { BNode *node; @@ -129,6 +123,38 @@ void BLI_buildAdjacencyList(BGraph *rg) } } +void BLI_rebuildAdjacencyListForNode(BGraph* rg, BNode *node) +{ + BArc *arc; + + if (node->arcs != NULL) + { + MEM_freeN(node->arcs); + } + + node->arcs = MEM_callocN((node->degree) * sizeof(BArc*), "adjacency list"); + + /* temporary use to indicate the first index available in the lists */ + node->flag = 0; + + for(arc = rg->arcs.first; arc; arc= arc->next) + { + if (arc->head == node) + { + addArcToNodeAdjacencyList(arc->head, arc); + } + else if (arc->tail == node) + { + addArcToNodeAdjacencyList(arc->tail, arc); + } + } + + if (node->degree != node->flag) + { + printf("error in node [%p]. Added only %i arcs out of %i\n", node, node->flag, node->degree); + } +} + void BLI_freeAdjacencyList(BGraph *rg) { BNode *node; |