home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rsynth / src / darray.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.1 KB  |  45 lines

  1. #if !defined(DARRAY_H)
  2. #define DARRAY_H
  3. typedef struct
  4.  {char     *data;          /* the items */
  5.   unsigned items;          /* number of slots used */
  6.   unsigned alloc;          /* number of slots allocated */
  7.   unsigned short esize;    /* size of items */
  8.   unsigned short get;      /* number to get */
  9.  } darray_t, *darray_ptr;
  10.  
  11. /* return pointer to nth item */
  12. extern void *Darray_find PROTO((darray_t *a,unsigned n));
  13. /* delete nth item */
  14. extern int darray_delete PROTO((darray_t *a,unsigned n));
  15. extern void darray_free  PROTO((darray_t *a));
  16.  
  17. #if !defined(inline)
  18. static inline void darray_init(darray_t *a,unsigned size,unsigned get)
  19. {
  20.  a->esize = size;
  21.  a->get   = get;
  22.  a->items = a->alloc = 0;
  23.  a->data = NULL;
  24. }
  25.  
  26. static inline void *darray_find(darray_t *a,unsigned n)
  27. {
  28.  if (n < a->alloc && n < a->items)
  29.   return (void *) (a->data + n * a->esize);
  30.  return Darray_find(a,n);
  31. }
  32. #else
  33.  
  34. #define darray_init(a,sz,gt) \
  35.  ((a)->esize = (sz), (a)->get = (gt), (a)->items = (a)->alloc = 0, (a)->data = NULL)
  36.  
  37. #define darray_find(a,n) \
  38.  (((n) < (a)->alloc && (n) < (a)->items) \
  39.    ? (void *) ((a)->data + (n) * (a)->esize)  \
  40.    : Darray_find(a,n))
  41.  
  42. #endif 
  43. #endif
  44.  
  45.