


SRTUNQ(1L)          UNIX Programmer's Manual           SRTUNQ(1L)



NAME
     srtinit, srtin, srtgti, srtgets, srtfree, srtdtree

SYNOPSIS
     #include <stdio.h>
     #include <local/srtunq.h>

     cc file.c -lsrtunq

DESCRIPTION
     _L_i_b_s_r_t_u_n_q._a is a set of sorting routines for a particular
     purpose.  It's use is extracting unique items from a possi-
     bly long list, where items are likely to be replicated
     numerously.  The list of unique items will be small enough
     to fit in main memory.  High speed is desired.

     The caller has control over the database through the use of
     a _s_t_r_u_c_t _s_r_t_e_n_t variable.  The subroutines provide for data
     entry and retrieval, memory allocation and deallocation.

ROUTINES
     void srtinit(ent) struct srtent *ent;
          This subroutine must be called before the first time
          any data is entered or retrieved from a database tree
          whose tag is pointed to by ent. It assumes that the
          database tag has not been used to store a tree, and
          therefore does not attempt to free any such data.

*string; int (*compar)();
     char *srtin(ent, string, compar) struct srtent *ent; char
          The existing data tree is searched.  If the string is
          found in the tree then nothing is done.  Otherwise,
          space is allocated for the string and pointer structure
          via _m_a_l_l_o_c(_3). The string is copied to this new space.
          The structure is linked into the tree.  If space cannot
          be obtained, the operation is aborted, and a pointer to
          an error string is returned.  The data structure
          remains consistent, but the string is not placed in it.
          If the operation is successful, NULL is returned.  The
          strings are compared and sorted with the subroutine
          pointed to by _c_o_m_p_a_r. This subroutine takes two string
          pointers as arguments.  It returns zero if the strings
          are the same, less than zero if the first string should
          precede the second, and greater than zero if the second
          string should precede the first.  If the subroutine
          pointer is NULL, then a simple string compare is used,
          which sorts in ascending ASCII order, and strings of
          different length comparing as unequal.

     void srtgti(ent); struct srtent *ent;
          This subroutine initializes the database tag pointed to
          by ent so that a tree transversal can be made via



Printed 5/16/88               PUCC                              1






SRTUNQ(1L)          UNIX Programmer's Manual           SRTUNQ(1L)



          _s_r_t_g_e_t_s.

     char *srtgets(ent); struct srtent *ent;
          This routine extracts the next string from the data
          structure.  The strings are returned in increasing
          order.  When the list is exhausted, NULL is returned.

     void srtfree(ent) struct srtent *ent;
          This subroutine deletes a database, and re-initializes
          the database tag.  It assumes that the database tag was
          initialized at one time via _s_r_t_i_n_i_t (other routines
          will probably also have been called).  The space for-
          mally occupied by string data and pointer structures is
          deallocated via _f_r_e_e(_3).

     void srtdtree(ent, tbl) struct srtent *ent; struct srtbl *tbl;
          This subroutine recursively deletes a database subtree.
          The space formally occupied by the string data and
          pointer structures is deallocated via _f_r_e_e(_3). This
          routine is most likely only of use internally.

EXAMPLE
     main()
     {
         char buf[80], *p;
         struct srtent d;
         srtinit(&d);
         while (fgets(buf, stdin, 79) != NULL)
             if ((p = srtin(&d, "foo")) != NULL)
                 printf("test: %s0, p);  /* warning message */
         srtgti(&d);
         while ((p = srtgets(&d)) != NULL)
             puts(p);
         srtfree(&d);
     }

DIAGNOSTICS
     There are no messages printed by these routines.  Catchable
     errors are returned as strings.  Compiled in errors such as
     the use of strings that are not null terminated tend to
     result in core files.

FILES
     /usr/local/lib/libsrtunq.a
     /usr/include/local/srtunq.h

SEE ALSO
     malloc(3), qsort(3)

AUTHOR
     Stephen Uitti, PUCC




Printed 5/16/88               PUCC                              2






SRTUNQ(1L)          UNIX Programmer's Manual           SRTUNQ(1L)



BUGS
     Likely.





















































Printed 5/16/88               PUCC                              3



