glist.h

# #include "glist.h"

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

## Contents

- Public Routines
- Public Definitions
- Introduction

## Public Routines in File glist.c

#### Index

alist2_insert | i2list_member | ilist_rem_dups | plist_last
alist2_remove | i2list_multimember | ilist_remove_last | plist_member
alist_insert | i2list_multisubset | ilist_removeall | plist_pop
assoc | i2list_prepend | ilist_set | plist_prepend
assoc2a | i2list_removeall | ilist_subset | plist_remove
assoc2b | i3list_append | ilist_subtract | plist_remove_last
copy_i3list | i3list_count | ilist_union | plist_subset
copy_ilist | i3list_prepend | ith_in_plist | plist_subtract
copy_plist | ilist_append | longest_string_in_plist | position_in_ilist
fprint_glist_mem | ilist_cat | multiset_add | position_of_string_in_plist
fprint_ilist | ilist_cat2 | multiset_add_n | reverse_i3list
free_i2list | ilist_copy | multiset_occurrences | reverse_ilist
free_i3list | ilist_count | multiset_to_set | reverse_plist
free_ilist | ilist_insert_up | multiset_union | sort_plist
free_plist | ilist_intersect | p_glist_mem | string_member_plist
get_i2list | ilist_is_set | p_i2list | zap_i2list
get_i3list | ilist_last | p_ilist | zap_i3list
get_ilist | ilist_member | plist_append | zap_ilist
get_plist | ilist_occurrences | plist_cat | zap_plist
i2list_append | ilist_pop | plist_cat2 |
i2list_count | ilist_prepend | plist_count |

#### Details

    I3list alist2_insert(I3list p, int key, int a, int b);

Alist2 (association list) for pairs of integers. Insert key/ pairs. With assoc2a(key), retreive value-a. With assoc2b(key), retreive value-b. If a key has more than one value pair, the most recent is returned. It a key is not in the alist2, INT_MIN is returned. An alist2 can be freed with zap_i3list(alist2).

    I3list alist2_remove(I3list p, int key);

    I2list alist_insert(I2list p, int key, int val);

Alists (association list) for integers. Insert key/value pairs. With assoc(key), retreive value. If a key has more than one value, the most recent is returned. It an key is not in the alist, INT_MIN is returned. An alist can be freed with zap_i2list(alist). This is not efficient, because no hashing is done; lookups are linear.

    int assoc(I2list p, int key);

See alist_insert.

    int assoc2a(I3list p, int key);

See alist2_insert.

    int assoc2b(I3list p, int key);

See alist2_insert.

    I3list copy_i3list(I3list p);

This routine copies a I3list (the whole 3list) and returns the copy.

    Ilist copy_ilist(Ilist p);

This routine copies a Ilist (the whole list) and returns the copy.

    Plist copy_plist(Plist p);

This routine copies a Plist (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 data types associated with the glist package. The Boolean argument heading tells whether to print a heading on the table.

    void fprint_ilist(FILE *fp, Ilist p);

The list of integers is printed to FILE *fp like this: (4 5 1 3), without a newline.

    void free_i2list(I2list p);

    void free_i3list(I3list p);

    void free_ilist(Ilist p);

    void free_plist(Plist p);

    I2list get_i2list(void);

    I3list get_i3list(void);

    Ilist get_ilist(void);

    Plist get_plist(void);

    I2list i2list_append(I2list lst, int i, int j);

This routine appends an integer to a I2list. The updated I2list is returned.

    int i2list_count(I2list p);

This routine returns the length of a I2list.

    I2list i2list_member(I2list lst, int i);

    BOOL i2list_multimember(I2list b, int i, int n);

Is a multimember of multiset b?

    BOOL i2list_multisubset(I2list a, I2list b);

    I2list i2list_prepend(I2list lst, int i, int j);

This routine inserts an integer triple as the first member of a I2list. The updated I2list is returned.

    I2list i2list_removeall(I2list p, int i);

Remove all occurrences of i.

The argument is "used up".

    I3list i3list_append(I3list lst, int i, int j, int k);

This routine appends an integer to a I3list. The updated I3list is returned.

    int i3list_count(I3list p);

This routine returns the length of a I3list.

    I3list i3list_prepend(I3list lst, int i, int j, int k);

This routine inserts an integer triple as the first member of a I3list. The updated I3list is returned.

    Ilist ilist_append(Ilist lst, int i);

This routine appends an integer to a Ilist. The updated Ilist is returned.

    Ilist ilist_cat(Ilist p1, Ilist p2);

Concatenate two Ilists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call.

That is, both arguments are "used up".

    Ilist ilist_cat2(Ilist p1, Ilist p2);

Concatenate two Ilists and return the result. In this version, the second ilist is copied and placed at the end of p1. That is, p1 is "used up", but p2 is not.

    Ilist ilist_copy(Ilist p);

    int ilist_count(Ilist p);

This routine returns the length of a Ilist.

    Ilist ilist_insert_up(Ilist p, int i);

    Ilist ilist_intersect(Ilist a, Ilist b);

Construct the intersection (as a new Ilist).

The arguments are not changed.

    BOOL ilist_is_set(Ilist a);

    Ilist ilist_last(Ilist lst);

    BOOL ilist_member(Ilist lst, int i);

This function checks if an integer is a member of a Ilist. (If a node in the Ilist contains a pointer instead of an integer, the result is undefined.)

    int ilist_occurrences(Ilist p, int i);

How many times does an integer occur in an ilist?

    Ilist ilist_pop(Ilist p);

This routine takes a nonempty Ilist, removes and frees the first node (ignoring the contents), and returns the remainder of the list.

    Ilist ilist_prepend(Ilist lst, int i);

This routine inserts an integer as the first member of a Ilist. The updated Ilist is returned.

    Ilist ilist_rem_dups(Ilist m);

Take a list of integers and remove duplicates.

This version "uses up" the argument.

    Ilist ilist_remove_last(Ilist p);

    Ilist ilist_removeall(Ilist p, int i);

Remove all occurrences of i.

The argument is "used up".

    Ilist ilist_set(Ilist m);

Take a list of integers and remove duplicates. This creates a new list and leave the old list as it was. Don't make any assumptions about the order of the result.

    BOOL ilist_subset(Ilist a, Ilist b);

    Ilist ilist_subtract(Ilist p1, Ilist p2);

Return the members of p1 that are not in p2.

The arguments are not changed.

    Ilist ilist_union(Ilist a, Ilist b);

Construct the union (as a new Ilist).

The arguments need not be sets, the result is a set.

The arguments are not changed.

    void *ith_in_plist(Plist p, int i);

    int longest_string_in_plist(Plist p);

Return -1 if the Plist is empty.

    I2list multiset_add(I2list a, int i);

Add 1 occurrence of i to multiset a.

    I2list multiset_add_n(I2list a, int i, int n);

Add n occurrences of i to multiset a.

    int multiset_occurrences(I2list m, int i);

    Ilist multiset_to_set(I2list m);

    I2list multiset_union(I2list a, I2list b);

The result is constructed from the arguments, so do not refer to either of the arguments after the call. That is, both arguments are "used up".

    void p_glist_mem();

This routine prints (to stdout) memory usage statistics for data types associated with the glist package.

    void p_i2list(I2list p);

The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end.

    void p_ilist(Ilist p);

The list of integers is printed to stdout like this: (4 5 1 3), with a '\n' at the end.

    Plist plist_append(Plist lst, void *v);

This routine appends a pointer to a Plist. The updated Plist is returned.

    Plist plist_cat(Plist p1, Plist p2);

Concatenate two Plists and return the result. The result is constructed from the arguments, so do not refer to either of the arguments after the call.

That is, both args are destroyed.

    Plist plist_cat2(Plist p1, Plist p2);

Concatenate two Plists and return the result. In this version, the second plist is copied and placed at the end of p1.

That is, the first arg is destroyed, and the second is preserved.

    int plist_count(Plist p);

This routine returns the length of a Plist.

    void *plist_last(Plist p);

    BOOL plist_member(Plist lst, void *v);

This function checks if a pointer is a member of a Plist.

    Plist plist_pop(Plist p);

This routine takes a nonempty Plist, removes and frees the first node (ignoring the contents), and returns the remainder of the list.

    Plist plist_prepend(Plist lst, void *v);

This routine inserts a pointer as the first member of a Plist. The updated Plist is returned.

    Plist plist_remove(Plist p, void *v);

Remove the first occurrence of a pointer from a Plist.

    Plist plist_remove_last(Plist p);

    BOOL plist_subset(Plist a, Plist b);

    Plist plist_subtract(Plist p1, Plist p2);

Return the members of p1 that are not in p2.

The arguments are not changed.

    int position_in_ilist(int i, Ilist p);

Count from 1; return -1 if the int is not in the Ilist.

    int position_of_string_in_plist(char *s, Plist p);

Count from 1; return -1 if the string is not in the Plist.

    I3list reverse_i3list(I3list p);

This routine reverses a I3list. The 3list 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_i3list(p);

    Ilist reverse_ilist(Ilist p);

This routine reverses a Ilist. 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_ilist(p);

    Plist reverse_plist(Plist p);

This routine reverses a Plist. 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_plist(p);

    Plist sort_plist(Plist objects,	Ordertype (*comp_proc) (void *, void *));

    BOOL string_member_plist(char *s, Plist p);

    void zap_i2list(I2list p);

This routine frees an I2list (the whole list).

    void zap_i3list(I3list p);

This routine frees a I3list (the whole list).

    void zap_ilist(Ilist p);

This routine frees a Ilist (the whole list).

    void zap_plist(Plist p);

This routine frees a Plist (the whole list). The things to which the members point are not freed.

## Public Definitions in File glist.h

    typedef struct plist * Plist;

    struct plist {
      void *v;
      Plist next;
    };

    typedef struct ilist * Ilist;

    struct ilist {
      int i;
      Ilist next;
    };

    typedef struct i2list * I2list;

    struct i2list {
      int i;
      int j;
      I2list next;
    };

    typedef struct i3list * I3list;

    struct i3list {
      int i;
      int j;
      int k;
      I3list next;
    };

## Introduction

This package handles Plist (singly-linked list of void pointers), Ilist (singly-linked list of integers), I2list (singly-linked list of pairs), I3list (singly-linked list of triples).