source: vis_dev/glu-2.3/src/sparse/sparse_int.h @ 99

Last change on this file since 99 was 13, checked in by cecile, 13 years ago

library glu 2.3

File size: 2.3 KB
Line 
1#include "sparse.h"
2#include "util.h"
3
4
5/*
6 *  sorted, double-linked list insertion
7 *
8 *  type: object type
9 *
10 *  first, last: fields (in header) to head and tail of the list
11 *  count: field (in header) of length of the list
12 *
13 *  next, prev: fields (in object) to link next and previous objects
14 *  value: field (in object) which controls the order
15 *
16 *  newval: value field for new object
17 *  e: an object to use if insertion needed (set to actual value used)
18 */
19
20#define sorted_insert(type, first, last, count, next, prev, value, newval, e) \
21    if (last == 0) { \
22        e->value = newval; \
23        first = e; \
24        last = e; \
25        e->next = 0; \
26        e->prev = 0; \
27        count++; \
28    } else if (last->value < newval) { \
29        e->value = newval; \
30        last->next = e; \
31        e->prev = last; \
32        last = e; \
33        e->next = 0; \
34        count++; \
35    } else if (first->value > newval) { \
36        e->value = newval; \
37        first->prev = e; \
38        e->next = first; \
39        first = e; \
40        e->prev = 0; \
41        count++; \
42    } else { \
43        type *p; \
44        for(p = first; p->value < newval; p = p->next) \
45            ; \
46        if (p->value > newval) { \
47            e->value = newval; \
48            p = p->prev; \
49            p->next->prev = e; \
50            e->next = p->next; \
51            p->next = e; \
52            e->prev = p; \
53            count++; \
54        } else { \
55            e = p; \
56        } \
57    }
58
59
60/*
61 *  double linked-list deletion
62 */
63#define dll_unlink(p, first, last, next, prev, count) { \
64    if (p->prev == 0) { \
65        first = p->next; \
66    } else { \
67        p->prev->next = p->next; \
68    } \
69    if (p->next == 0) { \
70        last = p->prev; \
71    } else { \
72        p->next->prev = p->prev; \
73    } \
74    count--; \
75}
76
77
78#ifdef FAST_AND_LOOSE
79extern sm_element *sm_element_freelist;
80extern sm_row *sm_row_freelist;
81extern sm_col *sm_col_freelist;
82
83#define sm_element_alloc(newobj) \
84    if (sm_element_freelist == NIL(sm_element)) { \
85        newobj = ALLOC(sm_element, 1); \
86    } else { \
87        newobj = sm_element_freelist; \
88        sm_element_freelist = sm_element_freelist->next_col; \
89    } \
90    newobj->user_word = NIL(char); \
91
92#define sm_element_free(e) \
93    (e->next_col = sm_element_freelist, sm_element_freelist = e)
94
95#else
96
97#define sm_element_alloc(newobj)        \
98    newobj = ALLOC(sm_element, 1);      \
99    newobj->user_word = NIL(char);
100#define sm_element_free(e)              \
101    FREE(e)
102#endif
103
104
105EXTERN void sm_row_remove_element(sm_row *, sm_element *);
106EXTERN void sm_col_remove_element(sm_col *, sm_element *);
107
108/* LINTLIBRARY */
Note: See TracBrowser for help on using the repository browser.