home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.68.zip / src / asm / vec.h < prev   
C/C++ Source or Header  |  2008-04-01  |  3KB  |  85 lines

  1. #ifndef ALREADY_INCLUDED_VEC
  2. #define ALREADY_INCLUDED_VEC
  3.  
  4. /*
  5.  * Copyright (c) 2003 - 2005 Magnus Lind.
  6.  *
  7.  * This software is provided 'as-is', without any express or implied warranty.
  8.  * In no event will the authors be held liable for any damages arising from
  9.  * the use of this software.
  10.  *
  11.  * Permission is granted to anyone to use this software, alter it and re-
  12.  * distribute it freely for any non-commercial, non-profit purpose subject to
  13.  * the following restrictions:
  14.  *
  15.  *   1. The origin of this software must not be misrepresented; you must not
  16.  *   claim that you wrote the original software. If you use this software in a
  17.  *   product, an acknowledgment in the product documentation would be
  18.  *   appreciated but is not required.
  19.  *
  20.  *   2. Altered source versions must be plainly marked as such, and must not
  21.  *   be misrepresented as being the original software.
  22.  *
  23.  *   3. This notice may not be removed or altered from any distribution.
  24.  *
  25.  *   4. The names of this software and/or it's copyright holders may not be
  26.  *   used to endorse or promote products derived from this software without
  27.  *   specific prior written permission.
  28.  *
  29.  */
  30.  
  31. #include "callback.h"
  32. #include "membuf.h"
  33. #include <string.h>
  34.  
  35.  
  36. #define STATIC_VEC_INIT(EL_SIZE) {(EL_SIZE), STATIC_MEMBUF_INIT, 1}
  37.  
  38. struct vec {
  39.     size_t elsize;
  40.     struct membuf buf;
  41.     int flags;
  42. };
  43.  
  44. struct vec_iterator {
  45.     struct vec *vec;
  46.     int pos;
  47. };
  48.  
  49. void vec_init(struct vec *p, size_t elsize);
  50. void vec_clear(struct vec *p, cb_free * f);
  51. void vec_free(struct vec *p, cb_free * f);
  52.  
  53. int vec_count(struct vec *p);
  54. void *vec_get(struct vec *p, int index);
  55. void *vec_insert(struct vec *p, int index, const void *in);
  56. void *vec_push(struct vec *p, const void *in);
  57. /**
  58.  * Gets the position where the key is stored in the vector. The vector
  59.  * needs to be sorted for this function to work. Returns the position,
  60.  * -1 on error or a negative number that can be converted to where
  61.  * it should have been if it had been inserted. insert_pos = -(val + 2)
  62.  **/
  63. int vec_find(struct vec *p, cb_cmp * f, const void *key);
  64.  
  65. /**
  66.  * Gets a pointer to the element that the key points to.
  67.  * Returns a pointer that may be null if not found.
  68.  **/
  69. void *vec_find2(struct vec *p, cb_cmp * f, const void *key);
  70.  
  71. /**
  72.  * Inserts the in element in its correct position in a sorted vector.
  73.  * returns 1 if insertion is successful, 0 if element is already
  74.  * inserted or -1 on error. If out is not NULL it will be
  75.  * dereferenced and set to the inserted element.
  76.  **/
  77. int vec_insert_uniq(struct vec *p, cb_cmp * f, const void *in, void **out);
  78. void vec_sort(struct vec *p, cb_cmp * f);
  79.  
  80. void vec_get_iterator(struct vec *p, struct vec_iterator *i);
  81. void *vec_iterator_next(struct vec_iterator *i);
  82.  
  83.  
  84. #endif
  85.