2 * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
3 * All rights reserved. The file named COPYRIGHT specifies the terms
4 * and conditions for redistribution.
13 #define ALLOC_START 20
17 static __pset_pointer pset_insert( pset_h pset, const __pset_pointer p );
21 * Create a pointer set and return a handle to it.
22 * Some space is initially allocated for the set.
24 pset_h pset_create( unsigned alloc_start, unsigned alloc_step )
29 pset = (pset_h) malloc( sizeof( struct __pset ) ) ;
33 start = ( alloc_start == 0 ) ? ALLOC_START : alloc_start ;
34 pset->ptrs = (__pset_pointer *) malloc( start * sizeof( __pset_pointer ) ) ;
35 if ( pset->ptrs == NULL )
37 free( (char *) pset ) ;
43 pset->alloc_step = ( alloc_step == 0 ) ? ALLOC_STEP : alloc_step ;
51 void pset_destroy( pset_h pset )
55 free( (char *) pset->ptrs ) ;
56 free( (char *) pset ) ;
59 __pset_pointer pset_add( pset_h pset, const __pset_pointer ptr )
61 return (pset->count < pset->max )
62 ? (pset->ptrs[ pset->count++ ] = ptr)
63 : pset_insert( pset, ptr) ;
67 * Append a pointer to a pset
69 static __pset_pointer pset_insert( pset_h pset, const __pset_pointer p )
71 if ( pset->count >= pset->max )
73 unsigned new_max = pset->max + pset->alloc_step ;
74 __pset_pointer *new_ptrs ;
76 new_ptrs = (__pset_pointer *) realloc(
77 (char *)pset->ptrs, new_max * sizeof( __pset_pointer ) ) ;
78 if ( new_ptrs == NULL )
81 pset->ptrs = new_ptrs ;
83 return( pset->ptrs[ pset->count++ ] = p ) ;
88 * Remove a pointer from a pset by moving every thing above it down 1 spot.
90 void pset_delete( register pset_h pset, register const __pset_pointer ptr )
92 register unsigned u = 0;
93 register int found_it = 0;
95 if ( pset->count == 0 )
98 while ( u < pset->count )
100 if ( pset->ptrs[ u ] == ptr )
103 { /* If not the last one, copy it */
104 if ( (u+1) < pset->count )
105 pset->ptrs[ u ] = pset->ptrs[ u+1 ];
114 * Create a pset iterator
116 psi_h psi_create( pset_h pset )
118 psi_h iter = (psi_h) malloc( sizeof( struct __pset_iterator ) ) ;
127 * Remove an element from a pset
129 void psi_remove( psi_h iter )
131 if ( iter->current < pset_count( iter->pset ) )
133 pset_remove_index( iter->pset, iter->current ) ;