#include "glist.h"

This page has information from files glist.h and glist.c.

Contents


Public Routines in File glist.c

Index

copy_glistget_g2listilist_appendplist_member
fprint_glist_memget_glistilist_memberplist_prepend
fprint_ilistglist_catilist_prependreverse_glist
free_g2listglist_countp_glist_memzap_g2list
free_glistglist_popp_ilistzap_glist
g2list_popi2list_prependplist_append

Details


Glist copy_glist(Glist p);
This routine copies a Glist (the whole list) and returns the copy.
void fprint_glist_mem(FILE *fp, BOOL heading);
This routine prints (to FILE *fp) memory usage statistics for Glists. The Boolean argument heading tells whether to print a heading on the table.
void fprint_ilist(FILE *fp, Glist p);
This routine assumes that the Glist p contains integers. The list of integers is printed to FILE *fp like this: (4 5 1 3), without a newline.
void free_g2list(G2list p);
This routine frees a G2list node. If you wish to free a whole G2list 2list, call zap_g2list();
void free_glist(Glist p);
This routine frees a Glist node. If you wish to free a whole Glist list, call zap_glist();
G2list g2list_pop(G2list p);
This routine takes a nonempty G2list, removes and frees the first node (ignoring the contents), and returns the remainder of the 2list.
G2list get_g2list(void);
This routine allocates and returns a G2list node.
Glist get_glist(void);
This routine allocates and returns a Glist node.
Glist glist_cat(Glist p1, Glist p2);
Concatenate two Glists and return the result. The result is constructed from the arguments, so not refer to either of the arguments after the call.
int glist_count(Glist p);
This routine returns the length of a Glist.
Glist glist_pop(Glist p);
This routine takes a nonempty Glist, removes and frees the first node (ignoring the contents), and returns the remainder of the list.
G2list i2list_prepend(G2list lst, int i1, int i2);
This routine inserts an integer as the first member of a G2list. The updated G2list is returned.
Glist ilist_append(Glist lst, int i);
This routine appends an integer to a Glist. The updated Glist is returned.
BOOL ilist_member(Glist lst, int i);
This function checks if an integer is a member of a Glist. (If a node in the Glist contains a pointer instead of an integer, the result is undefined.)
Glist ilist_prepend(Glist lst, int i);
This routine inserts an integer as the first member of a Glist. The updated Glist is returned.
void p_glist_mem(void);
This routine prints (to stdout) memory usage statistics for Glists.
void p_ilist(Glist p);
This routine assumes that the Glist p contains integers. The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end.
Glist plist_append(Glist lst, void *p);
This routine appends a pointer to a Glist. The updated Glist is returned. (The whole Glist is traversed.)
BOOL plist_member(Glist lst, void *p);
This routine checks if a pointer is a member of a Glist. If any node of the Glist contains an integer instead of a pointer, the result is undefined.
Glist plist_prepend(Glist lst, void *p);
This routine inserts a pointer as the first member of a Glist. The updated Glist is returned.
Glist reverse_glist(Glist p);
This routine reverses a Glist. The list is reversed in-place, so you should not refer to the argument after calling this routine. A good way to use it is like this:
p = reverse_glist(p);

void zap_g2list(G2list p);
This routine frees a G2list (the whole 2list). If the 2list contains any pointers, the things to which they point are not freed.
void zap_glist(Glist p);
This routine frees a Glist (the whole list). If the list contains any pointers, the things to which they point are not freed.

Public Definitions in File glist.h

typedef struct glist * Glist;
typedef struct g2list * G2list;

struct glist {
  Glist next;
  union {
    int i;
    void *v;
  } u;
};

struct g2list {
  G2list next;
  union {
    int i;
    void *v;
  } u1;
  union {
    int i;
    void *v;
  } u2;
};


Introduction

This package handles Glist (generic) lists, which are simple, singly linked lists. The members of the lists can be integers or pointers. In particular, each is a union of (int) and (void *). There is no way to determine the types of the members of the list, so you have to remember what kind of data are there.

Note that when assigning to and from a (void *), you don't need a cast, but when dereferencing a (void *), you do need a cast.

There are two informal subtypes: "ilist" for lists of integers, and "plist" for lists of pointers. Several of the routines (which have "ilist" or "plist" in the name) apply to these suptypes. The rest of the routines apply to any Glist.


These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.