b374176cf7fa6f6058989a5d7d33191005ef0b69
[util-vserver.git] / ensc_vector / vector.h
1 // $Id: vector.h,v 1.4 2005/07/03 09:12:31 ensc Exp $    --*- c++ -*--
2
3 // Copyright (C) 2002,2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //  
18
19 #ifndef H_UTILVSERVER_VECTOR_VECTOR_H
20 #define H_UTILVSERVER_VECTOR_VECTOR_H
21
22 #include <stdlib.h>
23
24 struct Vector
25 {
26     void        *data;
27     size_t      count;
28     size_t      allocated;
29
30     size_t      elem_size;
31 };
32
33 typedef enum { vecMOVE_FRONT, vecSHIFT_ONCE }            VectorSelfOrgMethod;
34
35 void    Vector_init(struct Vector *, size_t elem_size);
36 void    Vector_free(struct Vector *);
37 void *  Vector_search(struct Vector *, void const *key, int (*compar)(const void *, const void *));
38 void *  Vector_searchSelfOrg(struct Vector *, void const *key,
39                              int (*compar)(const void *, const void *),
40                              VectorSelfOrgMethod method);
41 void    Vector_sort(struct Vector *, int (*compar)(const void *, const void *));
42 void    Vector_unique(struct Vector *, int (*compar)(const void *, const void *));
43 void *  Vector_pushback(struct Vector *);
44 void *  Vector_insert(struct Vector *, void const *key, int (*compar)(const void *, const void *));
45 void    Vector_popback(struct Vector *);
46 void    Vector_resize(struct Vector *vec);
47 void    Vector_clear(struct Vector *vec);
48 void    Vector_zeroEnd(struct Vector *vec);
49 void    Vector_foreach(struct Vector *vec, void (*func)(void *, void *), void *);
50
51 static void             Vector_foreach_const(struct Vector const *vec,
52                                              void (*func)(void const *, void *),
53                                              void *);
54 static void const *     Vector_searchSelfOrg_const(struct Vector const *, void const *key,
55                                                    int (*compar)(const void *, const void *),
56                                                    VectorSelfOrgMethod method);
57 static void const *     Vector_search_const(struct Vector const *, void const *key, int (*compar)(const void *, const void *));
58 static void *           Vector_begin(struct Vector *);
59 static void *           Vector_end(struct Vector *);
60 static void const *     Vector_begin_const(struct Vector const *);
61 static void const *     Vector_end_const(struct Vector const *);
62 static size_t           Vector_count(struct Vector const *vec);
63
64 #include "vector.hc"
65
66 #endif  //  H_UTILVSERVER_VECTOR_VECTOR_H