pg_list.h 3.01 KB
Newer Older
1 2 3 4 5 6 7 8
/*-------------------------------------------------------------------------
 *
 * pg_list.h--
 *    POSTGRES generic list package
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: pg_list.h,v 1.4 1997/03/12 21:11:23 scrappy Exp $
10 11 12 13 14 15
 *
 *-------------------------------------------------------------------------
 */
#ifndef	PG_LIST_H
#define	PG_LIST_H

16
#include <nodes/nodes.h>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

/* ----------------------------------------------------------------
 *			node definitions
 * ----------------------------------------------------------------
 */

/*----------------------
 * 	Value node
 *----------------------
 */
typedef struct Value {
    NodeTag		type;	/* tag appropriately (eg. T_String) */
    union ValUnion {
	char   		*str;	/* string */ 
	long   		ival;
	double 		dval;
    } val;
} Value;

#define	intVal(v)	(((Value *)v)->val.ival)
#define	floatVal(v)	(((Value *)v)->val.dval)
#define strVal(v)	(((Value *)v)->val.str)


/*----------------------
 * 	List node
 *----------------------
 */
typedef	struct List {
    NodeTag		type;
47 48 49 50
    union {
      void *ptr_value;
      int   int_value;
    } elem;
51 52 53 54 55 56 57 58 59
    struct List		*next;
} List;

#define    NIL		((List *) NULL)

/* ----------------
 *	accessor macros
 * ----------------
 */
60 61 62 63

/* anything that doesn't end in 'i' is assumed to be referring to the */
/* pointer version of the list (where it makes a difference)          */
#define lfirst(l)				((l)->elem.ptr_value)
64 65 66
#define lnext(l)				((l)->next)
#define lsecond(l)				(lfirst(lnext(l)))

67 68
#define lfirsti(l)                              ((l)->elem.int_value)

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
/*
 * foreach -
 *    a convenience macro which loops through the list
 */
#define foreach(_elt_,_list_)   \
    for(_elt_=_list_; _elt_!=NIL;_elt_=lnext(_elt_))


/*
 * function prototypes in nodes/list.c
 */
extern int length(List *list);
extern List *append(List *list1, List *list2);
extern List *nconc(List *list1, List *list2);
extern List *lcons(void *datum, List *list);
extern bool member(void *foo, List *bar);
extern Value *makeInteger(long i);
extern Value *makeFloat(double d);
extern Value *makeString(char *str);
extern List *makeList(void *elem, ...);
extern List *lappend(List *list, void *obj);
extern List *lremove(void *elem, List *list);
extern void freeList(List *list);
     
extern void *nth(int n, List *l);
extern void set_nth(List *l, int n, void *elem);
		    
96 97
List *lconsi(int datum, List *list);
List *lappendi(List *list, int datum);
98 99 100
extern bool intMember(int, List *);
extern List *intAppend(List *list1, List *list2);

101 102
extern int nthi(int n, List *l);

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
extern List *nreverse(List *);
extern List *set_difference(List *, List *);
extern List *set_differencei(List *, List *);
extern List *LispRemove(void *, List *);
extern List *intLispRemove(int, List *);
extern List *LispUnion(List *foo, List *bar);
extern List *LispUnioni(List *foo, List *bar);
extern bool same(List *foo, List *bar);

/* should be in nodes.h but needs List */
extern bool equali(List *a, List *b);

/* in copyfuncs.c */
extern List *listCopy(List *);

#endif /* PG_LIST_H */