Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
nodelist.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <circogen/nodelist.h>
12#include <circogen/circular.h>
13#include <assert.h>
14#include <limits.h>
15#include <stddef.h>
16#include <string.h>
17
18void appendNodelist(nodelist_t *list, size_t one, Agnode_t *n) {
19 assert(one <= nodelist_size(list));
20
21 // expand the list by one element
22 nodelist_append(list, NULL);
23
24 // shuffle everything past where we will insert
25 nodelist_sync(list);
26 size_t to_move = sizeof(node_t*) * (nodelist_size(list) - one - 1);
27 if (to_move > 0) {
28 memmove(nodelist_at(list, one + 1), nodelist_at(list, one), to_move);
29 }
30
31 // insert the new node
32 nodelist_set(list, one, n);
33}
34
35void realignNodelist(nodelist_t *list, size_t np) {
36 assert(np < nodelist_size(list));
37 for (size_t i = np; i != 0; --i) {
38 // rotate the list by 1
39 node_t *const head = nodelist_pop_front(list);
40 nodelist_push_back(list, head);
41 }
42}
43
44void
45insertNodelist(nodelist_t * list, Agnode_t * cn, Agnode_t * neighbor,
46 int pos)
47{
48 nodelist_remove(list, cn);
49
50 for (size_t i = 0; i < nodelist_size(list); ++i) {
51 Agnode_t *here = nodelist_get(list, i);
52 if (here == neighbor) {
53 if (pos == 0) {
54 appendNodelist(list, i, cn);
55 } else {
56 appendNodelist(list, i + 1, cn);
57 }
58 break;
59 }
60 }
61}
62
64static void concatNodelist(nodelist_t * l1, nodelist_t * l2)
65{
66 for (size_t i = 0; i < nodelist_size(l2); ++i) {
67 nodelist_append(l1, nodelist_get(l2, i));
68 }
69}
70
71void reverseAppend(nodelist_t * l1, nodelist_t * l2)
72{
73 nodelist_reverse(l2);
74 concatNodelist(l1, l2);
75 nodelist_free(l2);
76}
77
78#ifdef DEBUG
79void printNodelist(nodelist_t * list)
80{
81 for (size_t i = 0; i < nodelist_size(list); ++i) {
82 fprintf(stderr, "%s ", agnameof(nodelist_get(list, i)));
83 }
84 fputs("\n", stderr);
85}
86#endif
#define head
Definition dthdr.h:15
node NULL
Definition grammar.y:163
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
#define neighbor(t, i, edim, elist)
Definition make_map.h:41
void realignNodelist(nodelist_t *list, size_t np)
Make np new front of list, with current last hooked to current first.
Definition nodelist.c:35
void insertNodelist(nodelist_t *list, Agnode_t *cn, Agnode_t *neighbor, int pos)
Definition nodelist.c:45
void reverseAppend(nodelist_t *l1, nodelist_t *l2)
Create l1 @ (rev l2) Destroys and frees l2.
Definition nodelist.c:71
void appendNodelist(nodelist_t *list, size_t one, Agnode_t *n)
Add node after one.
Definition nodelist.c:18
static void concatNodelist(nodelist_t *l1, nodelist_t *l2)
attach l2 to l1.
Definition nodelist.c:64