Graphviz 13.1.3~dev.20250905.1412
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#include <util/list.h>
18
19void appendNodelist(nodelist_t *list, size_t one, Agnode_t *n) {
20 assert(one <= LIST_SIZE(list));
21
22 // expand the list by one element
23 LIST_APPEND(list, NULL);
24
25 // shuffle everything past where we will insert
26 LIST_SYNC(list);
27 size_t to_move = sizeof(node_t*) * (LIST_SIZE(list) - one - 1);
28 if (to_move > 0) {
29 memmove(LIST_AT(list, one + 1), LIST_AT(list, one), to_move);
30 }
31
32 // insert the new node
33 LIST_SET(list, one, n);
34}
35
36void realignNodelist(nodelist_t *list, size_t np) {
37 assert(np < LIST_SIZE(list));
38 for (size_t i = np; i != 0; --i) {
39 // rotate the list by 1
40 node_t *const head = LIST_POP_FRONT(list);
41 LIST_PUSH_BACK(list, head);
42 }
43}
44
45void
46insertNodelist(nodelist_t * list, Agnode_t * cn, Agnode_t * neighbor,
47 int pos)
48{
49 LIST_REMOVE(list, cn);
50
51 for (size_t i = 0; i < LIST_SIZE(list); ++i) {
52 Agnode_t *here = LIST_GET(list, i);
53 if (here == neighbor) {
54 if (pos == 0) {
55 appendNodelist(list, i, cn);
56 } else {
57 appendNodelist(list, i + 1, cn);
58 }
59 break;
60 }
61 }
62}
63
65static void concatNodelist(nodelist_t * l1, nodelist_t * l2)
66{
67 for (size_t i = 0; i < LIST_SIZE(l2); ++i) {
68 LIST_APPEND(l1, LIST_GET(l2, i));
69 }
70}
71
72void reverseAppend(nodelist_t * l1, nodelist_t * l2)
73{
74 LIST_REVERSE(l2);
75 concatNodelist(l1, l2);
76 LIST_FREE(l2);
77}
78
79#ifdef DEBUG
80void printNodelist(nodelist_t * list)
81{
82 for (size_t i = 0; i < LIST_SIZE(list); ++i) {
83 fprintf(stderr, "%s ", agnameof(LIST_GET(list, i)));
84 }
85 fputs("\n", stderr);
86}
87#endif
#define head
Definition dthdr.h:15
node NULL
Definition grammar.y:181
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:143
type-generic dynamically expanding list
#define LIST_AT(list, index)
Definition list.h:178
#define LIST_POP_FRONT(list)
Definition list.h:403
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_APPEND(list, item)
Definition list.h:132
#define LIST_FREE(list)
Definition list.h:379
#define LIST_SET(list, index, item)
Definition list.h:212
#define LIST_SYNC(list)
Definition list.h:336
#define LIST_PUSH_BACK(list, item)
Definition list.h:393
#define LIST_REVERSE(list)
Definition list.h:357
#define LIST_REMOVE(list, item)
Definition list.h:227
#define LIST_GET(list, index)
Definition list.h:165
#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:36
void insertNodelist(nodelist_t *list, Agnode_t *cn, Agnode_t *neighbor, int pos)
Definition nodelist.c:46
void reverseAppend(nodelist_t *l1, nodelist_t *l2)
Create l1 @ (rev l2) Destroys and frees l2.
Definition nodelist.c:72
void appendNodelist(nodelist_t *list, size_t one, Agnode_t *n)
Add node after one.
Definition nodelist.c:19
static void concatNodelist(nodelist_t *l1, nodelist_t *l2)
attach l2 to l1.
Definition nodelist.c:65