modified: diffout.py
[GalaxyCodeBases.git] / c_cpp / lib / uthash / src / utvector.h
blob932a9dcebb3098b037ebeaab38c338747fc349bc
1 /*
2 Copyright (c) 2003-2016, Troy D. Hanson http://troydhanson.github.com/uthash/
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
12 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
13 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
15 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 /* utvector
26 * maintain a contiguous buffer of 'n' elements ('i' occupied)
27 * the 'n' buffers are deep-inited at the time of allocation
28 * the vector leaves popped slots as-is, clearing them on re-use
29 * the memory management helper mm is used to define the size and
30 * deep-init, deep-fini, deep-copy (into inited slots) and deep-clear.
31 * deep-clear prepares a slot for re-use e.g. reset slot state.
35 #ifndef __UTVECTOR_H_
36 #define __UTVECTOR_H_
38 #include "utmm.h"
40 /* typical usage e.g. a vector of utstring would have
42 .sz = sizeof(UT_string)
43 .init = utstring-init
44 .fini = utstring-done
45 .copy = ustring_concat
46 .clear= utstring-clear
49 typedef struct _UT_vector {
50 UT_mm mm;
51 unsigned i,n;/* i: index of next available slot, n: num slots */
52 char *d; /* n slots of size icd->sz*/
53 } UT_vector;
56 UT_vector *utvector_new(const UT_mm *mm);
57 void utvector_init(UT_vector *v, const UT_mm *mm);
58 void utvector_reserve(UT_vector *v, unsigned num);
59 void utvector_fini(UT_vector *v);
60 UT_vector * utvector_clone(UT_vector *src);
61 void utvector_clear(UT_vector *v);
62 void utvector_copy(UT_vector *dst, UT_vector *src);
63 void utvector_free(UT_vector *v);
64 void *utvector_extend(UT_vector *v);
65 void *utvector_head(UT_vector *v);
66 void *utvector_tail(UT_vector *v);
67 void *utvector_next(UT_vector *v, void *cur);
68 void *utvector_pop(UT_vector *v);
69 void *utvector_elt(UT_vector *v, unsigned i);
70 void utvector_shift(UT_vector *v);
71 void utvector_erase(UT_vector *v, unsigned i);
72 void *utvector_push(UT_vector *v, void *e);
73 unsigned utvector_len(UT_vector *v);
76 #endif /* __UTVECTOR_H_ */