1/* struct::graph - critcl - layer 0 declarations
2 * API general utilities
3 */
4
5#ifndef _G_UTIL_H
6#define _G_UTIL_H 1
7
8#include <tcl.h>
9
10/* Allocation macros for common situations.
11 */
12
13#define ALLOC(type)    (type *) ckalloc (sizeof (type))
14#define NALLOC(n,type) (type *) ckalloc ((n) * sizeof (type))
15#define REALLOC(x,n,type) (type *) ckrealloc ((char*) x, (n) * sizeof (type))
16
17/* Assertions in general, and asserting the proper range of an array index.
18 */
19
20#undef  GRAPH_DEBUG
21#define GRAPH_DEBUG 1
22
23#ifdef GRAPH_DEBUG
24#define XSTR(x) #x
25#define STR(x) XSTR(x)
26#define RANGEOK(i,n) ((0 <= (i)) && (i < (n)))
27#define ASSERT(x,msg) if (!(x)) { Tcl_Panic (msg " (" #x "), in file " __FILE__ " @line " STR(__LINE__));}
28#define ASSERT_BOUNDS(i,n) ASSERT (RANGEOK(i,n),"array index out of bounds: " STR(i) " > " STR(n))
29#else
30#define ASSERT(x,msg)
31#define ASSERT_BOUNDS(i,n)
32#endif
33
34/* .................................................. */
35
36/* NL  = Node List. Actually a list of generic pointers.
37 * NLQ = NL Queue. Also useable as stack.
38 */
39
40typedef struct NL *NLptr;
41
42typedef struct NL {
43    NLptr next;
44    void* n;
45} NL;
46
47typedef struct NLQ {
48    NLptr start;
49    NLptr end;
50} NLQ;
51
52void  g_nlq_init   (NLQ* q);
53void  g_nlq_append (NLQ* q, void* n);
54void  g_nlq_push   (NLQ* q, void* n);
55void* g_nlq_pop    (NLQ* q);
56void* g_nlq_clear  (NLQ* q);
57
58#endif /* _G_UTIL_H */
59
60/*
61 * Local Variables:
62 * mode: c
63 * c-basic-offset: 4
64 * fill-column: 78
65 * End:
66 */
67