Graphviz 14.1.3~dev.20260124.0732
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 "config.h"
12
13#include <circogen/nodelist.h>
14#include <circogen/circular.h>
15#include <assert.h>
16#include <limits.h>
17#include <stddef.h>
18#include <string.h>
19#include <util/list.h>
20
21void appendNodelist(nodelist_t *list, size_t one, Agnode_t *n) {
22 assert(one <= LIST_SIZE(list));
23
24 // expand the list by one element
25 LIST_APPEND(list, NULL);
26
27 // shuffle everything past where we will insert
28 LIST_SYNC(list);
29 size_t to_move = sizeof(node_t*) * (LIST_SIZE(list) - one - 1);
30 if (to_move > 0) {
31 memmove(LIST_AT(list, one + 1), LIST_AT(list, one), to_move);
32 }
33
34 // insert the new node
35 LIST_SET(list, one, n);
36}
37
38void realignNodelist(nodelist_t *list, size_t np) {
39 assert(np < LIST_SIZE(list));
40 for (size_t i = np; i != 0; --i) {
41 // rotate the list by 1
42 node_t *const head = LIST_POP_FRONT(list);
43 LIST_PUSH_BACK(list, head);
44 }
45}
46
47void
48insertNodelist(nodelist_t * list, Agnode_t * cn, Agnode_t * neighbor,
49 int pos)
50{
51 LIST_REMOVE(list, cn);
52
53 for (size_t i = 0; i < LIST_SIZE(list); ++i) {
54 Agnode_t *here = LIST_GET(list, i);
55 if (here == neighbor) {
56 if (pos == 0) {
57 appendNodelist(list, i, cn);
58 } else {
59 appendNodelist(list, i + 1, cn);
60 }
61 break;
62 }
63 }
64}
65
67static void concatNodelist(nodelist_t * l1, nodelist_t * l2)
68{
69 for (size_t i = 0; i < LIST_SIZE(l2); ++i) {
70 LIST_APPEND(l1, LIST_GET(l2, i));
71 }
72}
73
74void reverseAppend(nodelist_t * l1, nodelist_t * l2)
75{
76 LIST_REVERSE(l2);
77 concatNodelist(l1, l2);
78 LIST_FREE(l2);
79}
80
81#ifdef DEBUG
82void printNodelist(nodelist_t * list)
83{
84 for (size_t i = 0; i < LIST_SIZE(list); ++i) {
85 fprintf(stderr, "%s ", agnameof(LIST_GET(list, i)));
86 }
87 fputs("\n", stderr);
88}
89#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:145
type-generic dynamically expanding list
#define LIST_AT(list, index)
Definition list.h:168
#define LIST_POP_FRONT(list)
Definition list.h:394
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_APPEND(list, item)
Definition list.h:120
#define LIST_FREE(list)
Definition list.h:370
#define LIST_SET(list, index, item)
Definition list.h:202
#define LIST_SYNC(list)
Definition list.h:327
#define LIST_PUSH_BACK(list, item)
Definition list.h:384
#define LIST_REVERSE(list)
Definition list.h:348
#define LIST_REMOVE(list, item)
Definition list.h:218
#define LIST_GET(list, index)
Definition list.h:155
#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:38
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:74
void appendNodelist(nodelist_t *list, size_t one, Agnode_t *n)
Add node after one.
Definition nodelist.c:21
static void concatNodelist(nodelist_t *l1, nodelist_t *l2)
attach l2 to l1.
Definition nodelist.c:67