1 .\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis
2 .\"All rights reserved. The file named COPYRIGHT specifies the terms
3 .\"and conditions for redistribution.
5 .\" $Id: pset.3,v 1.1.1.1 2003/02/19 17:29:27 bbraun Exp $
6 .TH PSET 3X "23 April 1993"
8 pset_create, pset_destroy, pset_add, pset_insert, pset_remove, pset_delete, pset_remove_index, pset_clear, pset_count, pset_pointer, pset_compact, pset_sort, pset_apply - routines that handle pointer sets
16 pset_h pset_create( alloc_start, alloc_step )
17 unsigned alloc_start, alloc_step ;
20 void pset_destroy( pset )
24 ANY_TYPE *pset_add( pset, ptr )
29 void *pset_insert( pset, ptr )
34 void pset_remove( pset, ptr )
39 void pset_delete( pset, ptr )
44 void pset_remove_index( pset, index )
49 void pset_clear( pset )
53 unsigned pset_count( pset )
57 void *pset_pointer( pset, index )
62 void pset_compact( pset )
66 void pset_sort( pset, compfunc )
71 void pset_apply( pset, func, arg )
76 This library provides functions that handle sets of pointers. Pointers
77 can be inserted and deleted from sets and the sets can be enumerated.
78 Pointers are inserted in sets in no particular order. However it is
80 that a sequence of insertions will result in a set which if enumerated
81 will provide the pointers in the same order in which they were inserted
82 (assuming no intervening deletions).
85 creates a pointer set.
87 determines the initial table size, and
89 determines the amount by which the set size is increased in case of
90 overflow. If any of these parameters is 0, a default value is used.
93 destroys the specified pointer set.
96 is a macro that adds a pointer to the specified set.
97 The pointer can be of any type.
100 inserts a pointer to the specified set.
101 This is the same operation as
105 removes a pointer from the specified set.
108 deletes a pointer from the specified set.
109 This is the same operation as
112 .B pset_remove_index()
113 removes the pointer that is at position
117 should be in the range [0, \fBpset_count(pset)\fP) (but there is no
118 check to enforce this).
119 After this operation, the
121 position will be occupied by another pointer.
124 removes all pointers from the specified set.
127 returns the number of pointers in the specified set.
130 returns the pointer at position
132 in the specified set.
134 must be between 0 and
135 .B "pset_count(pset)."
137 is a macro and it can also be used in the left-hand side of assignments.
140 removes all NULL pointers from
144 sorts the pointers in
146 using the specified function.
148 is invoked with 2 arguments that are pointers pointing to pointers stored in
150 For example, if the pset holds pointers to objects of type T, then
151 the function F whose address is in
153 should be defined as:
157 should return a negative, zero or positive value
158 if its first argument is less than, equal to, or greater than its
170 the function is invoked as:
176 is a pset pointer. If
180 the function is invoked as:
185 The following code fragment reads lines from standard input
186 and places them in a pset. Then it sorts the pset, prints the
187 sorted contents to standard output and then it eliminates duplicate
188 lines (which it also prints to standard output).
199 ph = pset_create( 0, 0 ) ;
200 while ( gets( buf ) )
202 pset_add( strcpy( malloc( strlen( buf ) + 1 ), buf ) ) ;
204 pset_sort( ph, compstr ) ;
205 for ( u = 0 ; u < pset_count( ph ) ; u++ )
207 printf( "%s\\n", (char *) pset_pointer( ph, u ) ) ;
220 int compstr( p1, p2 )
226 return( strcmp( *p1, *p2 ) ) ;
233 is a pointer type. Functions that return
237 to indicate an error.
240 returns a pointer set handle or
245 returns its second argument if successful or
250 returns its second argument if successful or
255 always returns the number of pointers in the set.
258 always returns a pointer. There is no check if the specified index is within
264 .B pset_remove_index(),
270 are macros, therefore the \fI&\fR operator cannot be applied to them.