Graphviz 12.0.1~dev.20240716.0800
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 size_t to_move = sizeof(node_t*) * (nodelist_size(list) - one - 2);
26 if (to_move > 0) {
27 memmove(nodelist_at(list, one + 2), nodelist_at(list, one + 1), to_move);
28 }
29
30 // insert the new node
31 nodelist_set(list, one + 1, n);
32}
33
34void realignNodelist(nodelist_t *list, size_t np) {
35 assert(np < nodelist_size(list));
36 for (size_t i = np; i != 0; --i) {
37 // rotate the list by 1
38 nodelist_append(list, nodelist_get(list, 0));
39 size_t to_move = sizeof(node_t*) * (nodelist_size(list) - 1);
40 if (to_move > 0) {
41 memmove(nodelist_at(list, 0), nodelist_at(list, 1), to_move);
42 }
43 nodelist_resize(list, nodelist_size(list) - 1, NULL);
44 }
45}
46
47void
48insertNodelist(nodelist_t * list, Agnode_t * cn, Agnode_t * neighbor,
49 int pos)
50{
51 nodelist_remove(list, cn);
52
53 for (size_t i = 0; i < nodelist_size(list); ++i) {
54 Agnode_t *here = nodelist_get(list, i);
55 if (here == neighbor) {
56 if (pos == 0) {
57 nodelist_append(list, NULL);
58 size_t to_move = sizeof(node_t*) * (nodelist_size(list) - i - 1);
59 if (to_move > 0) {
60 memmove(nodelist_at(list, i + 1), nodelist_at(list, i), to_move);
61 }
62 nodelist_set(list, i, cn);
63 } else {
64 appendNodelist(list, i, cn);
65 }
66 break;
67 }
68 }
69}
70
72static void concatNodelist(nodelist_t * l1, nodelist_t * l2)
73{
74 for (size_t i = 0; i < nodelist_size(l2); ++i) {
75 nodelist_append(l1, nodelist_get(l2, i));
76 }
77}
78
79void reverseAppend(nodelist_t * l1, nodelist_t * l2)
80{
81 nodelist_reverse(l2);
82 concatNodelist(l1, l2);
83 nodelist_free(l2);
84}
85
86#ifdef DEBUG
87void printNodelist(nodelist_t * list)
88{
89 for (size_t i = 0; i < nodelist_size(list); ++i) {
90 fprintf(stderr, "%s ", agnameof(nodelist_get(list, i)));
91 }
92 fputs("\n", stderr);
93}
94#endif
node NULL
Definition grammar.y:149
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
#define neighbor(t, i, edim, elist)
Definition make_map.h:37
void realignNodelist(nodelist_t *list, size_t np)
Make np new front of list, with current last hooked to current first.
Definition nodelist.c:34
void insertNodelist(nodelist_t *list, Agnode_t *cn, Agnode_t *neighbor, int pos)
Definition nodelist.c:48
void reverseAppend(nodelist_t *l1, nodelist_t *l2)
Create l1 @ (rev l2) Destroys and frees l2.
Definition nodelist.c:79
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:72