2 * Copyright (C) 2010 Joel Rosdahl
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 3 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 /* A simple array of unsigned integers used for the statistics counters. */
24 * Allocate and initialize a struct counters. Data entries up to the size are
28 counters_init(size_t initial_size)
30 struct counters *c = x_malloc(sizeof(*c));
34 counters_resize(c, initial_size);
39 * Free a struct counters.
42 counters_free(struct counters *c)
49 * Set a new size. New data entries are set to 0.
52 counters_resize(struct counters *c, size_t new_size)
54 if (new_size > c->size) {
58 while (c->allocated < new_size) {
59 c->allocated += 32 + c->allocated;
63 c->data = x_realloc(c->data, c->allocated * sizeof(c->data[0]));
65 for (i = c->size; i < new_size; i++) {