| 1 | /* $Id$Revision: */ |
| 2 | |
| 3 | /************************************************************************* |
| 4 | * Copyright (c) 2011 AT&T Intellectual Property |
| 5 | * All rights reserved. This program and the accompanying materials |
| 6 | * are made available under the terms of the Eclipse Public License v1.0 |
| 7 | * which accompanies this distribution, and is available at |
| 8 | * http://www.eclipse.org/legal/epl-v10.html |
| 9 | * |
| 10 | * Contributors: See CVS logs. Details at http://www.graphviz.org/ |
| 11 | *************************************************************************/ |
| 12 | |
| 13 | #ifndef VECTOR_H |
| 14 | #define VECTOR_H |
| 15 | #include <stdlib.h> |
| 16 | struct vector_struct { |
| 17 | int maxlen; |
| 18 | int len; |
| 19 | void *v; |
| 20 | size_t size_of_elem; |
| 21 | void (*deallocator)(void *v); |
| 22 | }; |
| 23 | |
| 24 | typedef struct vector_struct *Vector; |
| 25 | |
| 26 | /* deallocator works on each element of the vector */ |
| 27 | Vector Vector_new(int maxlen, size_t size_of_elem, void (*deallocator)(void *v)); |
| 28 | |
| 29 | Vector Vector_add(Vector v, void *stuff); |
| 30 | |
| 31 | Vector Vector_reset(Vector v, void *stuff, int i); |
| 32 | |
| 33 | void Vector_delete(Vector v); |
| 34 | |
| 35 | void* Vector_get(Vector v, int i); |
| 36 | |
| 37 | int Vector_get_length(Vector v); |
| 38 | |
| 39 | Vector Vector_reset(Vector v, void *stuff, int i); |
| 40 | |
| 41 | /*------------- vector of strings ----------- */ |
| 42 | |
| 43 | typedef Vector StringVector; |
| 44 | |
| 45 | Vector StringVector_new(int len, int delete_element_strings); |
| 46 | Vector StringVector_add(Vector v, char *i); |
| 47 | void StringVector_delete(Vector v); |
| 48 | char** StringVector_get(Vector v, int i); |
| 49 | int StringVector_get_length(Vector v); |
| 50 | Vector StringVector_reset(Vector v, char *content, int pos); |
| 51 | void StringVector_fprint(FILE *fp, StringVector v); |
| 52 | void StringVector_fprint1(FILE *fp, StringVector v); |
| 53 | StringVector StringVector_part(StringVector v, int n, int *selected_list); |
| 54 | /*------------- integer vector ----------- */ |
| 55 | |
| 56 | typedef Vector IntegerVector; |
| 57 | |
| 58 | Vector IntegerVector_new(int len); |
| 59 | Vector IntegerVector_add(Vector v, int i); |
| 60 | void IntegerVector_delete(Vector v); |
| 61 | int* IntegerVector_get(Vector v, int i); |
| 62 | int IntegerVector_get_length(Vector v); |
| 63 | Vector IntegerVector_reset(Vector v, int content, int pos); |
| 64 | |
| 65 | |
| 66 | |
| 67 | #endif |
| 68 | |