# #include "fpalist.h"

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

## Contents

- Public Routines
- Public Definitions
- Introduction

## Public Routines in File fpalist.c

#### Index

first_fpos | fpalist_insert | next_fpos | zap_fpa_chunks
fpalist_delete | fprint_fpalist_mem | p_fpa_list | zap_fpalist
fpalist_empty | get_fpa_list | p_fpalist_mem |

#### Details

    struct fposition first_fpos(Fpa_list f);

    void fpalist_delete(Fpa_list p, Term t);

    BOOL fpalist_empty(Fpa_list p);

    void fpalist_insert(Fpa_list p, Term t);

    void fprint_fpalist_mem(FILE *fp, BOOL heading);

This routine prints (to FILE *fp) memory usage statistics for data types associated with the fpalist package. The Boolean argument heading tells whether to print a heading on the table.

    Fpa_list get_fpa_list();

    struct fposition next_fpos(struct fposition p);

    void p_fpa_list(Fpa_chunk c);

    void p_fpalist_mem();

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

    void zap_fpa_chunks(Fpa_chunk p);

    void zap_fpalist(Fpa_list p);

## Public Definitions in File fpalist.h

    /* We use the Term ID to order FPA lists. */

    #define FPA_ID_TYPE unsigned
    #define FPA_ID_MAX UINT_MAX
    #define FPA_ID(t) (((Term) t)->u.id)

    /*
      I experimented with using the address of the term as the
      term ID for ordering FPA lists.  Although not technically
      legal in C (because addresses in different arrays (malloced blocks)
      are compared), I believe it works correctly on all modern systems.
      (It didn't work in DOS.)
      However, there is a practical problem.
      On some systems, malloc() returns addresses in increasing order,
      and on others, they are decreasing, giving answers to queries in
      the reverse order, causing different searches.

      define FPA_ID_TYPE Term
      define FPA_ID_MAX ((Term) ULONG_MAX) //
      define FPA_ID(t) ((Term) t)
    */

    #define FLT(x,y) (FPA_ID(x) <  FPA_ID(y))
    #define FGT(x,y) (FPA_ID(x) >  FPA_ID(y))
    #define FLE(x,y) (FPA_ID(x) <= FPA_ID(y))
    #define FGE(x,y) (FPA_ID(x) >= FPA_ID(y))

    #define FTERM(p) ((p).f == NULL ? NULL : (p).f->d[(p).i])

    /* FPA lists */

    typedef struct fpa_chunk *Fpa_chunk;
    typedef struct fpa_list *Fpa_list;

    struct fpa_chunk {
      int size;         /* size of array */
      Term *d;          /* array for chunk */
      int n;            /* current number of items in chunk (right justified) */
      Fpa_list head;    /* beginning of list to which this chunk belongs */
      Fpa_chunk next;   /* list of chunks is singly-linked */
    };

    struct fpa_list {
      Fpa_chunk chunks;
      int num_chunks;
      int chunksize;
      int num_terms;
    };

    /* to maintain a position in an FPA list while traversing for set operations */

    struct fposition {
      Fpa_chunk f;
      int i;
    };

## Introduction