From 195b0c7d812811287996c3f39cbf5e9ec63da482 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 18 Mar 2025 19:23:38 +0200 Subject: use generic conts --- src/vec.c | 68 --------------------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 src/vec.c (limited to 'src/vec.c') diff --git a/src/vec.c b/src/vec.c deleted file mode 100644 index be413a0..0000000 --- a/src/vec.c +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: copyleft-next-0.3.1 */ -/* Copyright 2024 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ - -#include -#include -#include - -#include - -struct vec vec_create(size_t ns) -{ - return (struct vec) { - .n = 0, - .s = 1, - .ns = ns, - .buf = malloc(ns), - }; -} - -size_t vec_len(struct vec *v) -{ - return v->n; -} - -void *vec_at(struct vec *v, size_t i) -{ - assert(i < v->n && "out of vector bounds"); - return v->buf + i * v->ns; -} - -void *vec_back(struct vec *v) -{ - assert(v->n); - return v->buf + (v->n - 1) * v->ns; -} - -void *vec_pop(struct vec *v) -{ - assert(v->n && "attempting to pop empty vector"); - v->n--; - return v->buf + v->n * v->ns; -} - -void vec_append(struct vec *v, void *n) -{ - v->n++; - if (v->n >= v->s) { - v->s *= 2; - v->buf = realloc(v->buf, v->s * v->ns); - } - - void *p = vec_at(v, v->n - 1); - memcpy(p, n, v->ns); -} - -void vec_reset(struct vec *v) -{ - v->n = 0; -} - -void vec_destroy(struct vec *v) { - free(v->buf); -} - -void vec_sort(struct vec *v, vec_comp_t comp) -{ - qsort(v->buf, v->n, v->ns, comp); -} -- cgit v1.2.3