vector.h 971 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * vector.h:
  3. * simple vectors
  4. *
  5. * Copyright (c) 2001 Chris Lightfoot. All rights reserved.
  6. *
  7. * $Id: vector.h,v 1.1 2003/10/19 06:44:33 pdw Exp $
  8. *
  9. */
  10. #ifndef __VECTOR_H_ /* include guard */
  11. #define __VECTOR_H_
  12. typedef union _item {
  13. void *v;
  14. long l;
  15. } item;
  16. #define _inline inline
  17. static _inline item item_long(const long l) { item u; u.l = l; return u; }
  18. static _inline item item_ptr(void *const v) { item u; u.v = v; return u; }
  19. typedef struct _vector{
  20. item *ary;
  21. size_t n, n_used;
  22. } *vector;
  23. vector vector_new(void);
  24. void vector_delete(vector);
  25. void vector_delete_free(vector);
  26. void vector_push_back(vector, const item);
  27. void vector_pop_back(vector);
  28. item vector_back(const vector);
  29. item *vector_remove(vector, item *t);
  30. void vector_reallocate(vector, const size_t n);
  31. /* A macro to iterate over a vector */
  32. #define vector_iterate(_v, _t) for ((_t) = (_v)->ary; (_t) < (_v)->ary + (_v)->n_used; ++(_t))
  33. #endif /* __VECTOR_H_ */