pax_global_header00006660000000000000000000000064132720540310014507gustar00rootroot0000000000000052 comment=e412ea01da2170506b11edbf664cfde583cfd2f0 uthash-0.0~git20180501.e412ea0/000077500000000000000000000000001327205403100154255ustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/.gitmodules000066400000000000000000000001251327205403100176000ustar00rootroot00000000000000[submodule "uthash"] path = uthash url = https://github.com/troydhanson/uthash.git uthash-0.0~git20180501.e412ea0/LICENSE000077700000000000000000000000001327205403100207262uthash/LICENSEustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/Makefile.standalone000066400000000000000000000011501327205403100212110ustar00rootroot00000000000000OBJS=libut.a all: $(OBJS) INCDIR=./include CFLAGS+=-I$(INCDIR) CFLAGS+=-Wall -Wextra CFLAGS+=-g libut.a: libut.o utvector.o utmm.o ringbuf.o ar r $@ $^ libut.o: src/libut.c $(INCDIR)/libut.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< utvector.o: src/utvector.c $(INCDIR)/utvector.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< utmm.o: src/utmm.c $(INCDIR)/utmm.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< ringbuf.o: src/ringbuf.c $(INCDIR)/ringbuf.h $(CC) $(CFLAGS) $(CPPFLAGS) -c $< .PHONY: clean tests install clean: rm -f $(OBJS) *.o make -C tests clean tests: libut.a make -C tests install: libut.a cp $< /usr/local/lib uthash-0.0~git20180501.e412ea0/README.md000066400000000000000000000005451327205403100167100ustar00rootroot00000000000000libut is a bundling of uthash and its extra headers (utstring, etc, and including utvector/utmm) into a libut.h header and libut.a library. It was copied from uthash itself (https://github.com/troydhanson/uthash). It relies on uthash as a submodule, thus needs to be cloned recursively. git clone --recursive https://github.com/troydhanson/libut.git uthash-0.0~git20180501.e412ea0/include/000077500000000000000000000000001327205403100170505ustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/include/libut.h000066400000000000000000000004061327205403100203400ustar00rootroot00000000000000#ifndef __LIBUT_H_ #define __LIBUT_H_ /* libut is a container around other sources */ #include "utmm.h" #include "utvector.h" #include "utstring.h" #include "utarray.h" #include "uthash.h" #include "utringbuffer.h" #include "utlist.h" #endif /* __LIBUT_H_ */ uthash-0.0~git20180501.e412ea0/include/ringbuf.h000066400000000000000000000015511327205403100206570ustar00rootroot00000000000000#ifndef _RINGBUF_H_ #define _RINGBUF_H_ #include #include #include #include /* simple ring buffer */ typedef struct _ringbuf { size_t n; /* allocd size */ size_t u; /* used space */ size_t i; /* input pos */ size_t o; /* output pos */ char d[]; /* C99 flexible array member */ } ringbuf; ringbuf *ringbuf_new(size_t sz); ringbuf *ringbuf_take(void *buf, size_t sz); int ringbuf_put(ringbuf *r, const void *data, size_t len); size_t ringbuf_get_pending_size(ringbuf *r); size_t ringbuf_get_next_chunk(ringbuf *r, char **data); size_t ringbuf_get_writable(ringbuf *r, char **data); void ringbuf_wrote(ringbuf *r, size_t len); void ringbuf_mark_consumed(ringbuf *r, size_t len); void ringbuf_free(ringbuf *r); void ringbuf_clear(ringbuf *r); size_t ringbuf_get_freespace(ringbuf *r); #endif /* _RINGBUF_H_ */ uthash-0.0~git20180501.e412ea0/include/utarray.h000077700000000000000000000000001327205403100256752../uthash/include/utarray.hustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/include/uthash.h000077700000000000000000000000001327205403100253072../uthash/include/uthash.hustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/include/utlist.h000077700000000000000000000000001327205403100253672../uthash/include/utlist.hustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/include/utmm.h000066400000000000000000000036401327205403100202060ustar00rootroot00000000000000#include #include #include /* Copyright (c) 2003-2016, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* utmm * * low level memory primitives * */ #ifndef __UTMM_H_ #define __UTMM_H_ typedef struct { size_t sz; void (*init)(void *buf); //-> utstring-init void (*fini)(void *buf); //-> utstring-done void (*copy)(void *dst, void *src); //-> ustring_concat void (*clear)(void *buf); //-> utstring-clear } UT_mm; void *utmm_new(const UT_mm *mm, size_t n); void utmm_init(const UT_mm *mm, void *buf, size_t n); void utmm_fini(const UT_mm *mm, void *buf, size_t n); void utmm_clear(const UT_mm *mm, void *buf, size_t n); void utmm_copy(const UT_mm *mm, void *dst, void *src, size_t n); /* convenient predefined mm */ extern UT_mm* utmm_int; extern UT_mm* utstring_mm; #endif /* __UTMM_H_ */ uthash-0.0~git20180501.e412ea0/include/utringbuffer.h000077700000000000000000000000001327205403100277232../uthash/include/utringbuffer.hustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/include/utstring.h000077700000000000000000000000001327205403100262552../uthash/include/utstring.hustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/include/utvector.h000066400000000000000000000052761327205403100211060ustar00rootroot00000000000000/* Copyright (c) 2003-2016, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* utvector * * maintain a contiguous buffer of 'n' elements ('i' occupied) * the 'n' buffers are deep-inited at the time of allocation * the vector leaves popped slots as-is, clearing them on re-use * the memory management helper mm is used to define the size and * deep-init, deep-fini, deep-copy (into inited slots) and deep-clear. * deep-clear prepares a slot for re-use e.g. reset slot state. * */ #ifndef __UTVECTOR_H_ #define __UTVECTOR_H_ #include "utmm.h" /* typical usage e.g. a vector of utstring would have * .sz = sizeof(UT_string) .init = utstring-init .fini = utstring-done .copy = ustring_concat .clear= utstring-clear */ typedef struct _UT_vector { UT_mm mm; unsigned i,n;/* i: index of next available slot, n: num slots */ char *d; /* n slots of size icd->sz*/ } UT_vector; UT_vector *utvector_new(const UT_mm *mm); void utvector_init(UT_vector *v, const UT_mm *mm); void utvector_reserve(UT_vector *v, unsigned num); void utvector_fini(UT_vector *v); UT_vector * utvector_clone(UT_vector *src); void utvector_clear(UT_vector *v); void utvector_copy(UT_vector *dst, UT_vector *src); void utvector_free(UT_vector *v); void *utvector_extend(UT_vector *v); void *utvector_head(UT_vector *v); void *utvector_tail(UT_vector *v); void *utvector_next(UT_vector *v, void *cur); void *utvector_pop(UT_vector *v); void *utvector_elt(UT_vector *v, unsigned i); void utvector_shift(UT_vector *v); void utvector_erase(UT_vector *v, unsigned i); void *utvector_push(UT_vector *v, void *e); unsigned utvector_len(UT_vector *v); #endif /* __UTVECTOR_H_ */ uthash-0.0~git20180501.e412ea0/src/000077500000000000000000000000001327205403100162145ustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/src/libut.c000066400000000000000000000035471327205403100175100ustar00rootroot00000000000000/* Copyright (c) 2003-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "libut.h" static void utstring_init_wrapper(void *_buf) { UT_string *buf = (UT_string*)_buf; utstring_init(buf); } static void utstring_done_wrapper(void *_buf) { UT_string *buf = (UT_string*)_buf; utstring_done(buf); } static void utstring_clear_wrapper(void *_buf) { UT_string *buf = (UT_string*)_buf; utstring_clear(buf); } static void utstring_copy_wrapper(void *_dst, void *_src) { UT_string *dst = (UT_string*)_dst; UT_string *src = (UT_string*)_src; utstring_concat(dst,src); } static UT_mm _utstring_mm = { .sz = sizeof(UT_string), .init = utstring_init_wrapper, .fini = utstring_done_wrapper, .copy = utstring_copy_wrapper, .clear = utstring_clear_wrapper }; UT_mm* utstring_mm = &_utstring_mm; uthash-0.0~git20180501.e412ea0/src/ringbuf.c000066400000000000000000000073471327205403100200270ustar00rootroot00000000000000#include "ringbuf.h" ringbuf *ringbuf_new(size_t sz) { ringbuf *r = malloc(sizeof(*r) + sz); if (r == NULL) { fprintf(stderr,"out of memory\n"); goto done; } r->u = r->i = r->o = 0; r->n = sz; done: return r; } void ringbuf_free(ringbuf* r) { free(r); } /* ringbuf_take: alternative to ringbuf_new; caller * provides the buffer to use as the ringbuf. * buffer should be aligned e.g. from malloc/mmap. * note: do not ringbuf_free afterward. */ #define MIN_RINGBUF (sizeof(ringbuf) + 1) ringbuf *ringbuf_take(void *buf, size_t sz) { if (sz < MIN_RINGBUF) return NULL; ringbuf *r = (ringbuf*)buf; r->u = r->i = r->o = 0; r->n = sz - sizeof(*r); // alignment should be ok assert(r->n > 0); return r; } /* copy data in. fails if ringbuf has insuff space. */ #define MIN(a,b) (((a) < (b)) ? (a) : (b)) int ringbuf_put(ringbuf *r, const void *_data, size_t len) { char *data = (char*)_data; size_t a,b,c; if (r->i < r->o) { // available space is a contiguous buffer a = r->o - r->i; assert(a == r->n - r->u); if (len > a) return -1; memcpy(&r->d[r->i], data, len); } else { // available space wraps; it's two buffers b = r->n - r->i; // in-head to eob (receives leading input) c = r->o; // out-head to in-head (receives trailing input) a = b + c; // available space // the only ambiguous case is i==o, that's why u is needed if (r->i == r->o) a = r->n - r->u; assert(a == r->n - r->u); if (len > a) return -1; memcpy(&r->d[r->i], data, MIN(b, len)); if (len > b) memcpy(r->d, &data[b], len-b); } r->i = (r->i + len) % r->n; r->u += len; return 0; } size_t ringbuf_get_freespace(ringbuf *r) { return r->n - r->u; } size_t ringbuf_get_pending_size(ringbuf *r) { return r->u; } size_t ringbuf_get_next_chunk(ringbuf *r, char **data) { // in this case the next chunk is the whole pending buffer if (r->o < r->i) { assert(r->u == r->i - r->o); *data = &r->d[r->o]; return r->u; } // in this case (i==o) either the buffer is empty of full. // r->u tells distinguishes these cases. if ((r->o == r->i) && (r->u == 0)) { *data=NULL; return 0; } // if we're here, that means r->o > r->i. the pending // output is wrapped around the buffer. this function // returns the chunk prior to eob. the next call gets // the next chunk that's wrapped around the buffer. size_t b,c; b = r->n - r->o; // length of the part we're returning c = r->i; // wrapped part length- a sanity check assert(r->u == b + c); *data = &r->d[r->o]; return b; } void ringbuf_mark_consumed(ringbuf *r, size_t len) { assert(len <= r->u); r->o = (r->o + len ) % r->n; r->u -= len; } void ringbuf_clear(ringbuf *r) { r->u = r->i = r->o = 0; } /* * ringbuf_get_writable * * get a pointer into the next chunk of writable space * whose length is returned in *len. If callers writes * into this space, it must be followed with a call to * ringbuf_wrote */ size_t ringbuf_get_writable(ringbuf *r, char **data) { /* any room in ring? */ if (r->n == r->u) { *data = NULL; return 0; } if (r->i == r->o) { assert(r->u == 0); } *data = r->d + r->i; return (r->i >= r->o) ? r->n - r->i : /* free space is from r->i to end */ r->o - r->i; /* free space is from r->i to r->o */ } /* used after ringbuf_get_writable to indicate len * bytes were written. this can only be used with * a len less than, or equal to, the result from * that function */ void ringbuf_wrote(ringbuf *r, size_t len) { size_t max = (r->i >= r->o) ? r->n - r->i : /* free space is from r->i to end */ r->o - r->i; /* free space is from r->i to r->o */ assert(len <= max); r->u += len; r->i = (r->i + len) % r->n; } uthash-0.0~git20180501.e412ea0/src/utmm.c000066400000000000000000000044441327205403100173500ustar00rootroot00000000000000/* Copyright (c) 2003-2015, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* utmm * * low level memory primitives * */ #include "utmm.h" void *utmm_new(const UT_mm *mm, size_t n) { void *o = calloc(n, mm->sz); if (o) return o; fprintf(stderr,"oom"); exit(-1); } void utmm_init(const UT_mm *mm, void *_buf, size_t n) { char *buf = (char*)_buf; if (mm->init == NULL) { memset(buf,0,n*mm->sz); return; } while(n--) { mm->init(buf); buf += mm->sz; } } void utmm_fini(const UT_mm *mm, void *_buf, size_t n) { char *buf = (char*)_buf; if (mm->fini == NULL) return; while(n--) { mm->fini(buf); buf += mm->sz; } } void utmm_clear(const UT_mm *mm, void *_buf, size_t n) { char *buf = (char*)_buf; if (mm->clear == NULL) { memset(buf,0,n*mm->sz); return; } while(n--) { mm->clear(buf); buf += mm->sz; } } void utmm_copy(const UT_mm *mm, void *_dst, void *_src, size_t n) { char *dst = (char*)_dst; char *src = (char*)_src; if (mm->copy == NULL) { memcpy(dst,src,n*mm->sz); return; } while(n--) { mm->copy(dst,src); dst += mm->sz; src += mm->sz; } } /* convenient predefined utmm */ static UT_mm _utmm_int = {.sz = sizeof(int)}; UT_mm* utmm_int = &_utmm_int; uthash-0.0~git20180501.e412ea0/src/utvector.c000066400000000000000000000120271327205403100202350ustar00rootroot00000000000000/* Copyright (c) 2003-2015, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include "utvector.h" #define INITIAL_SIZE 16 /* utvector * * maintain a contiguous buffer of 'n' elements ('i' occupied) * the 'n' buffers are deep-inited at the time of allocation * the vector leaves popped slots as-is, clearing them on re-use * the memory management helper mm is used to define the size and * deep-init, deep-fini, deep-copy (into inited slots) and deep-clear. * deep-clear prepares a slot for re-use e.g. reset slot state. * */ void oom(void) { //fprintf(stderr,"out of memory\n"); exit(-1); } UT_vector *utvector_new(const UT_mm *mm) { UT_vector *v = malloc(sizeof(UT_vector)); if (!v) return NULL; utvector_init(v,mm); return v; } unsigned utvector_len(UT_vector *v) { return v->i; } void utvector_init(UT_vector *v, const UT_mm *mm) { v->mm = *mm; // struct copy v->i = v->n = 0; v->d = NULL; utvector_reserve(v, INITIAL_SIZE); // also inits them, sets v->n } void utvector_reserve(UT_vector *v, unsigned num) { if (v->n - v->i >= num) return; // space is big enough, return unsigned n = num - (v->n - v->i); // minimum we need to grow by if (n < (v->n * 2)) n = (v->n * 2); // grow by at least double current size char *d = realloc(v->d, (n + v->n) * v->mm.sz); if (!d) oom(); v->d = d; void *b = v->d + (v->n * v->mm.sz); // start of newly allocated area utmm_init(&v->mm,b,n); v->n = n + v->n; } void utvector_fini(UT_vector *v) { utmm_fini(&v->mm,v->d,v->n); free(v->d); v->d = NULL; v->i = v->n = 0; } UT_vector * utvector_clone(UT_vector *src) { UT_vector *v = utvector_new(&src->mm); utvector_copy(v, src); return v; } void utvector_clear(UT_vector *v) { v->i = 0; } void utvector_copy(UT_vector *dst, UT_vector *src) { /* dst, src both inited */ assert(dst->mm.sz == src->mm.sz); // double check that its inited utvector_clear(dst); utvector_reserve(dst, src->i); dst->i = src->i; utmm_clear(&dst->mm,dst->d,src->i); utmm_copy(&dst->mm, dst->d, src->d, src->i); } void utvector_free(UT_vector *v) { utvector_fini(v); free(v); } void *utvector_extend(UT_vector *v) { utvector_reserve(v,1); void *b = v->d + (v->i * v->mm.sz); utmm_clear(&v->mm,b,1); v->i++; return b; } void *utvector_next(UT_vector *v, void *cur) { if (cur == NULL) return v->i ? v->d : NULL; assert(cur >= (void*)(v->d)); // user pointer must be inside our data area char *n = (char*)cur + v->mm.sz; // next slot address if (n >= v->d + (v->i * v->mm.sz)) n=NULL; // only if next slot occupied return n; } void *utvector_head(UT_vector *v) { if (v->i == 0) return NULL; return v->d; } void *utvector_tail(UT_vector *v) { if (v->i == 0) return NULL; return v->d + ((v->i - 1) * v->mm.sz); } void *utvector_pop(UT_vector *v) { if (v->i == 0) return NULL; return v->d + (--(v->i) * v->mm.sz); } void *utvector_elt(UT_vector *v, unsigned i) { if (i >= v->i) return NULL; return v->d + (i * v->mm.sz); } /* shifting is not very efficient. we end up throwing away/fini'ing the * head of the vector, then doing a memmove, then having to init a new slot. * we don't return the shifted item because its been fini'd, and we have * no caller memory to copy it into anyway. a cpy_shift maybe handy */ void utvector_shift(UT_vector *v) { assert (v->i); utmm_fini(&v->mm,v->d,1); v->i--; memmove(v->d, v->d + v->mm.sz, (v->n-1)*v->mm.sz); char *b = v->d + ((v->n-1) * v->mm.sz); utmm_init(&v->mm,b,1); } void utvector_erase(UT_vector *v, unsigned i) { assert(v->i); if (i >= v->i) return; utmm_fini(&v->mm, v->d + (i * v->mm.sz), 1); v->i--; if (v->n - 1 > i) { memmove(v->d + (i * v->mm.sz), v->d + ((i+1) * v->mm.sz), (((v->n-1) - i) * v->mm.sz)); } char *b = v->d + ((v->n-1) * v->mm.sz); utmm_init(&v->mm,b,1); } void *utvector_push(UT_vector *v, void *e) { void *b = utvector_extend(v); utmm_copy(&v->mm, b, e, 1); return v->d + ((v->i - 1) * v->mm.sz); } uthash-0.0~git20180501.e412ea0/tests/000077500000000000000000000000001327205403100165675ustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/tests/Makefile000066400000000000000000000011521327205403100202260ustar00rootroot00000000000000PROGS=test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12 \ test13 test14 test15 test16 test17 test18 test19 test20 test21 test22 test23 OBJS=$(patsubst %,%.o,$(PROGS)) CFLAGS += -I../include CFLAGS += -g CFLAGS += -Wall -Wextra LDFLAGS += -L.. -lut TEST_TARGET=run_tests TESTS=./do_tests all: $(OBJS) $(PROGS) $(TEST_TARGET) # static pattern rule: multiple targets $(OBJS): %.o: %.c $(CC) -c $(CPPFLAGS) $(CFLAGS) $< $(PROGS): %: %.o $(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $< $(LDFLAGS) run_tests: $(PROGS) perl $(TESTS) .PHONY: clean clean: rm -f $(PROGS) $(OBJS) test*.out uthash-0.0~git20180501.e412ea0/tests/README000066400000000000000000000013061327205403100174470ustar00rootroot00000000000000test1: test utvector init/fini test2: test utvector of int, push, next test3: test utvector push, pop, extend test4: test utvector_copy test5: test utvector of utstring test6: test utvector of utstring more ops test7: test utvector of utstring even more ops test8: test utextend past initial size int test9: test utextend past initial size utstring test10: test utvector_pop on empty list (int) test11: test utvector_pop on empty list (utstring) test12: test utvector head/tail (int) test13: test utvector head/tail (utstring) test14: test utvector_shift (int) test15: test utvector_shift (utstring) test16: test utvector_elt test17: test utvector_erase test18: test utvector_erase test19: test utvector_erase uthash-0.0~git20180501.e412ea0/tests/do_tests000077500000000000000000000005571327205403100203500ustar00rootroot00000000000000#!/usr/bin/perl use strict; use warnings; my @tests; for (glob "test*[0-9]") { push @tests, $_ if -e "$_.ans"; } my $num_failed=0; for my $test (@tests) { `./$test > $test.out`; `diff $test.out $test.ans`; print "$test failed\n" if $?; $num_failed++ if $?; } print scalar @tests . " tests conducted, $num_failed failed.\n"; exit $num_failed; uthash-0.0~git20180501.e412ea0/tests/test1.ans000066400000000000000000000000001327205403100203200ustar00rootroot00000000000000uthash-0.0~git20180501.e412ea0/tests/test1.c000066400000000000000000000001651327205403100177750ustar00rootroot00000000000000#include "utvector.h" int main() { UT_vector v; utvector_init(&v, utmm_int); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test10.ans000066400000000000000000000000711327205403100204100ustar00rootroot00000000000000extend 1000 pop result: non-null 1000 pop result: null 0 uthash-0.0~git20180501.e412ea0/tests/test10.c000066400000000000000000000010061327205403100200500ustar00rootroot00000000000000#include #include "utvector.h" int main() { int *p; UT_vector v; utvector_init(&v, utmm_int); printf("extend\n"); p = (int*)utvector_extend(&v); *p = 1000; p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); printf("pop\n"); p = (int*)utvector_pop(&v); printf("result: %s %d\n", p ? "non-null" : "null", p ? *p : 0); printf("pop\n"); p = (int*)utvector_pop(&v); printf("result: %s %d\n", p ? "non-null" : "null", p ? *p : 0); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test11.ans000066400000000000000000000000721327205403100204120ustar00rootroot00000000000000extend iterate hello pop hello iterate pop (null) iterate uthash-0.0~git20180501.e412ea0/tests/test11.c000066400000000000000000000014351327205403100200570ustar00rootroot00000000000000#include #include "libut.h" int main() { UT_string *s; UT_vector v; utvector_init(&v, utstring_mm); printf("extend\n"); s = (UT_string*)utvector_extend(&v); utstring_printf(s,"hello"); printf("iterate\n"); s=NULL; while ( (s=(UT_string*)utvector_next(&v,s))) printf("%s\n",utstring_body(s)); printf("pop\n"); s=(UT_string*)utvector_pop(&v); printf("%s\n", s ? utstring_body(s) : "(null)"); printf("iterate\n"); s=NULL; while ( (s=(UT_string*)utvector_next(&v,s))) printf("%s\n",utstring_body(s)); printf("pop\n"); s=(UT_string*)utvector_pop(&v); printf("%s\n", s ? utstring_body(s) : "(null)"); printf("iterate\n"); s=NULL; while ( (s=(UT_string*)utvector_next(&v,s))) printf("%s\n",utstring_body(s)); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test12.ans000066400000000000000000000001151327205403100204110ustar00rootroot000000000000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 head: (non-null) 0 tail: (non-null) 15 uthash-0.0~git20180501.e412ea0/tests/test12.c000066400000000000000000000007011327205403100200530ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); p = (int*)utvector_tail(&v); printf("tail: (%s) %d\n", p?"non-null":"null", p?*p:0); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test13.ans000066400000000000000000000006441327205403100204210ustar00rootroot00000000000000len: 16 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ head: non-null . tail: non-null ................ extend len: 17 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ hello head: non-null . tail: non-null hello uthash-0.0~git20180501.e412ea0/tests/test13.c000066400000000000000000000020061327205403100200540ustar00rootroot00000000000000#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); printf("extend\n"); t = (UT_string*)utvector_extend(&v); utstring_bincpy(t, "hello", 5); dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test14.ans000066400000000000000000000002031327205403100204110ustar00rootroot000000000000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 head: (non-null) 0 tail: (non-null) 15 len: 16 shift len: 15 head: (non-null) 1 clear len: 0 uthash-0.0~git20180501.e412ea0/tests/test14.c000066400000000000000000000013561327205403100200640ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); p = (int*)utvector_tail(&v); printf("tail: (%s) %d\n", p?"non-null":"null", p?*p:0); printf("len: %d\n", utvector_len(&v)); printf("shift\n"); utvector_shift(&v); printf("len: %d\n", utvector_len(&v)); p = (int*)utvector_head(&v); printf("head: (%s) %d\n", p?"non-null":"null", p?*p:0); printf("clear\n"); utvector_clear(&v); printf("len: %d\n", utvector_len(&v)); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test15.ans000066400000000000000000000015421327205403100204210ustar00rootroot00000000000000len: 16 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ head: non-null . tail: non-null ................ shift len: 15, head: non-null .. shift len: 14, head: non-null ... shift len: 13, head: non-null .... shift len: 12, head: non-null ..... shift len: 11, head: non-null ...... shift len: 10, head: non-null ....... shift len: 9, head: non-null ........ shift len: 8, head: non-null ......... shift len: 7, head: non-null .......... shift len: 6, head: non-null ........... shift len: 5, head: non-null ............ shift len: 4, head: non-null ............. shift len: 3, head: non-null .............. shift len: 2, head: non-null ............... shift len: 1, head: non-null ................ shift len: 0, head: null - extend len: 1, head: non-null extended uthash-0.0~git20180501.e412ea0/tests/test15.c000066400000000000000000000021741327205403100200640ustar00rootroot00000000000000#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); t = (UT_string*)utvector_head(&v); printf("head: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); t = (UT_string*)utvector_tail(&v); printf("tail: %s %s\n", t?"non-null":"null", t?utstring_body(t):"-"); for(i=0; i<16; i++) { printf("shift\n"); utvector_shift(&v); t = (UT_string*)utvector_head(&v); printf("len: %d, head: %s %s\n", utvector_len(&v), t?"non-null":"null", t?utstring_body(t):"-"); } printf("extend\n"); t= (UT_string*)utvector_extend(&v); utstring_printf(t,"extended"); t = (UT_string*)utvector_head(&v); printf("len: %d, head: %s %s\n", utvector_len(&v), t?"non-null":"null", t?utstring_body(t):"-"); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test16.ans000066400000000000000000000001701327205403100204160ustar00rootroot000000000000000 1 2 3 4 5 6 7 8 9 elt 0: 0 elt 1: 1 elt 2: 2 elt 3: 3 elt 4: 4 elt 5: 5 elt 6: 6 elt 7: 7 elt 8: 8 elt 9: 9 p is null uthash-0.0~git20180501.e412ea0/tests/test16.c000066400000000000000000000007721327205403100200670ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v,*k; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); k = utvector_clone(&v); while ( (p=(int*)utvector_next(k,p))) printf("%d\n",*p); for(i=0; i<10; i++) { p = (int*)utvector_elt(&v, i); printf("elt %d: %d\n", i, *p); } /* expect null */ p = (int*)utvector_elt(&v, 11); printf("p is %snull\n", p ? "not " : ""); utvector_fini(&v); utvector_free(k); return 0; } uthash-0.0~git20180501.e412ea0/tests/test17.ans000066400000000000000000000002731327205403100204230ustar00rootroot00000000000000. .. ... .... ..... ...... ....... ........ ......... .......... .. ... .... ..... ...... ....... ........ ......... .......... .. .... ..... ...... ....... ........ ......... .......... uthash-0.0~git20180501.e412ea0/tests/test17.c000066400000000000000000000011551327205403100200640ustar00rootroot00000000000000#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 0); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 1); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test18.ans000066400000000000000000000002551327205403100204240ustar00rootroot00000000000000. .. ... .... ..... ...... ....... ........ ......... .......... . .. ... .... ..... ...... ....... ........ ......... . .. ... .... ..... ...... ....... ........ ......... uthash-0.0~git20180501.e412ea0/tests/test18.c000066400000000000000000000011551327205403100200650ustar00rootroot00000000000000#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 9); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 9); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test19.ans000066400000000000000000000000021327205403100204130ustar00rootroot00000000000000. uthash-0.0~git20180501.e412ea0/tests/test19.c000066400000000000000000000007671327205403100200760ustar00rootroot00000000000000#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<1; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_erase(&v, 0); p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test2.ans000066400000000000000000000000241327205403100203270ustar00rootroot000000000000000 1 2 3 4 5 6 7 8 9 uthash-0.0~git20180501.e412ea0/tests/test2.c000066400000000000000000000004021327205403100177700ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test20.ans000066400000000000000000000001131327205403100204060ustar00rootroot00000000000000writable space: 10 next chunk length : 10 abcdefghik next chunk length : 0 uthash-0.0~git20180501.e412ea0/tests/test20.c000066400000000000000000000014201327205403100200510ustar00rootroot00000000000000#include #include "ringbuf.h" int main() { int rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 10); memcpy(data, "abcdefghik", 10); ringbuf_wrote(r, len); len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 0); len = ringbuf_get_next_chunk(r, &data); assert(len == 10); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); len = ringbuf_get_next_chunk(r, &data); assert(len == 0); printf("next chunk length : %zu\n", len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/test21.ans000066400000000000000000000001121327205403100204060ustar00rootroot00000000000000writable space: 5 next chunk length : 10 helloabcde next chunk length : 0 uthash-0.0~git20180501.e412ea0/tests/test21.c000066400000000000000000000015111327205403100200530ustar00rootroot00000000000000#include #include "ringbuf.h" int main() { int sc, rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; sc = ringbuf_put(r, "hello", 5); if (sc < 0) goto done; len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 5); memcpy(data, "abcde", 5); ringbuf_wrote(r, len); len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 0); len = ringbuf_get_next_chunk(r, &data); assert(len == 10); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); len = ringbuf_get_next_chunk(r, &data); assert(len == 0); printf("next chunk length : %zu\n", len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/test22.ans000066400000000000000000000001701327205403100204130ustar00rootroot00000000000000next chunk length : 5 hello writable space: 5 writable space: 5 next chunk length : 5 abcde next chunk length : 5 fghij uthash-0.0~git20180501.e412ea0/tests/test22.c000066400000000000000000000024261327205403100200620ustar00rootroot00000000000000#include #include "ringbuf.h" int main() { int sc, rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; sc = ringbuf_put(r, "hello", 5); if (sc < 0) goto done; len = ringbuf_get_next_chunk(r, &data); assert(len == 5); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* now there are 10 bytes free but only 5 contiguous */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 5); memcpy(data, "abcde", 5); ringbuf_wrote(r, len); /* now there are 5 bytes free, starting at wrap */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 5); memcpy(data, "fghij", 5); ringbuf_wrote(r, len); /* read abcde */ len = ringbuf_get_next_chunk(r, &data); assert(len == 5); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* read fghji after the wrap */ len = ringbuf_get_next_chunk(r, &data); assert(len == 5); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/test23.ans000066400000000000000000000001741327205403100204200ustar00rootroot00000000000000next chunk length : 9 hello, ed writable space: 1 writable space: 9 next chunk length : 1 a next chunk length : 9 bcdefghij uthash-0.0~git20180501.e412ea0/tests/test23.c000066400000000000000000000024321327205403100200600ustar00rootroot00000000000000#include #include "ringbuf.h" int main() { int sc, rc = -1; size_t len; char *data; ringbuf *r = NULL; r = ringbuf_new(10); if (r == NULL) goto done; sc = ringbuf_put(r, "hello, ed", 9); if (sc < 0) goto done; len = ringbuf_get_next_chunk(r, &data); assert(len == 9); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* now there are 10 bytes free but only 1 contiguous */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 1); memcpy(data, "a", 1); ringbuf_wrote(r, len); /* now there are 9 bytes free, starting at wrap */ len = ringbuf_get_writable(r, &data); if (len) printf("writable space: %zu\n", len); assert(len == 9); memcpy(data, "bcdefghij", 9); ringbuf_wrote(r, len); /* read a */ len = ringbuf_get_next_chunk(r, &data); assert(len == 1); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); /* read bcdefghij after the wrap */ len = ringbuf_get_next_chunk(r, &data); assert(len == 9); printf("next chunk length : %zu\n", len); printf("%.*s\n", (int)len, data); ringbuf_mark_consumed(r, len); done: if (r) ringbuf_free(r); return rc; } uthash-0.0~git20180501.e412ea0/tests/test3.ans000066400000000000000000000000571327205403100203360ustar00rootroot00000000000000len 10 len 9 0 1 2 3 4 5 6 7 8 11 len 10 len 0 uthash-0.0~git20180501.e412ea0/tests/test3.c000066400000000000000000000010051327205403100177710ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); printf("len %d\n", utvector_len(&v)); utvector_pop(&v); printf("len %d\n", utvector_len(&v)); p = (int*)utvector_extend(&v); *p = 11; p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); printf("len %d\n", utvector_len(&v)); utvector_clear(&v); printf("len %d\n", utvector_len(&v)); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test4.ans000066400000000000000000000000241327205403100203310ustar00rootroot000000000000000 1 2 3 4 5 6 7 8 9 uthash-0.0~git20180501.e412ea0/tests/test4.c000066400000000000000000000004641327205403100200020ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v,*k; utvector_init(&v, utmm_int); for(i=0; i<10; i++) utvector_push(&v, &i); k = utvector_clone(&v); while ( (p=(int*)utvector_next(k,p))) printf("%d\n",*p); utvector_fini(&v); utvector_free(k); return 0; } uthash-0.0~git20180501.e412ea0/tests/test5.ans000066400000000000000000000001011327205403100203260ustar00rootroot00000000000000. .. ... .... ..... ...... ....... ........ ......... .......... uthash-0.0~git20180501.e412ea0/tests/test5.c000066400000000000000000000006041327205403100177770ustar00rootroot00000000000000#include #include "libut.h" int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } p=NULL; while ( (p=(UT_string*)utvector_next(&v,p))) printf("%s\n",utstring_body(p)); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test6.ans000066400000000000000000000004571327205403100203450ustar00rootroot00000000000000len: 10 . .. ... .... ..... ...... ....... ........ ......... .......... extend len: 11 . .. ... .... ..... ...... ....... ........ ......... .......... extended element pop len: 10 . .. ... .... ..... ...... ....... ........ ......... .......... clear len: 0 push len: 1 allocated utstring done1 done2 uthash-0.0~git20180501.e412ea0/tests/test6.c000066400000000000000000000015471327205403100200070ustar00rootroot00000000000000#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *p; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); printf("extend\n"); p = utvector_extend(&v); utstring_printf(p,"extended element"); dump(&v); printf("pop\n"); utvector_pop(&v); dump(&v); printf("clear\n"); utvector_clear(&v); dump(&v); printf("push\n"); utstring_new(p); utstring_printf(p,"allocated utstring"); utvector_push(&v, p); utstring_free(p); dump(&v); printf("done1\n"); utvector_fini(&v); printf("done2\n"); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test7.ans000066400000000000000000000002301327205403100203330ustar00rootroot00000000000000len: 10 . .. ... .... ..... ...... ....... ........ ......... .......... clone len: 10 . .. ... .... ..... ...... ....... ........ ......... .......... uthash-0.0~git20180501.e412ea0/tests/test7.c000066400000000000000000000010611327205403100177770ustar00rootroot00000000000000#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_vector v; utvector_init(&v, utstring_mm); UT_vector *k; UT_string s; utstring_init(&s); for(i=0; i<10; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); printf("clone\n"); k = utvector_clone(&v); dump(k); utvector_fini(&v); utvector_free(k); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/tests/test8.ans000066400000000000000000000000531327205403100203370ustar00rootroot000000000000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1000 uthash-0.0~git20180501.e412ea0/tests/test8.c000066400000000000000000000004641327205403100200060ustar00rootroot00000000000000#include #include "utvector.h" int main() { int i,*p=NULL; UT_vector v; utvector_init(&v, utmm_int); for(i=0; i<16; i++) utvector_push(&v, &i); p = utvector_extend(&v); *p = 1000; p=NULL; while ( (p=(int*)utvector_next(&v,p))) printf("%d\n",*p); utvector_fini(&v); return 0; } uthash-0.0~git20180501.e412ea0/tests/test9.ans000066400000000000000000000005151327205403100203430ustar00rootroot00000000000000len: 16 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ extend len: 17 . .. ... .... ..... ...... ....... ........ ......... .......... ........... ............ ............. .............. ............... ................ hello uthash-0.0~git20180501.e412ea0/tests/test9.c000066400000000000000000000011161327205403100200020ustar00rootroot00000000000000#include #include "libut.h" void dump(UT_vector *v) { printf("len: %d\n", utvector_len(v)); UT_string *p=NULL; while ( (p=(UT_string*)utvector_next(v,p))) printf("%s\n",utstring_body(p)); } int main() { int i; UT_string *t; UT_vector v; utvector_init(&v, utstring_mm); UT_string s; utstring_init(&s); for(i=0; i<16; i++) { utstring_printf(&s, "."); utvector_push(&v, &s); } dump(&v); printf("extend\n"); t = (UT_string*)utvector_extend(&v); utstring_bincpy(t, "hello", 5); dump(&v); utvector_fini(&v); utstring_done(&s); return 0; } uthash-0.0~git20180501.e412ea0/uthash/000077500000000000000000000000001327205403100167215ustar00rootroot00000000000000