Skip to content

Commit

Permalink
Uniform callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikwidlund committed Dec 17, 2017
1 parent 401868a commit 5234acf
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
10 changes: 10 additions & 0 deletions CHANGES
Expand Up @@ -4,3 +4,13 @@ Version 1.0
Released 2017-01-03

* Initial release

Version 1.1
===========

Released 2017-12-17

* New features:

- List type
- More uniform interfaces
11 changes: 4 additions & 7 deletions benchmark/map.c
Expand Up @@ -73,21 +73,18 @@ static void shuffle(int *array, size_t n)

static int set_int_empty = -1;

static size_t set_int_hash(map *m, void *e)
static size_t set_int_hash(void *e)
{
(void) m;
return *(int *) e;
}

static int set_int_equal(map *m, void *e1, void *e2)
static int set_int_equal(void *e1, void *e2)
{
(void) m;
return *(int *) e1 == *(int *) e2;
}

static void set_int_set(map *m, void *e1, void *e2)
static void set_int_set(void *e1, void *e2)
{
(void) m;
*(int *) e1 = *(int *) e2;
}

Expand Down Expand Up @@ -182,5 +179,5 @@ int main()
(void) fprintf(stdout, "%s,%lu,%f,%f,%f,%lu\n", mp->name, mp->size, mp->insert, mp->lookup, mp->delete, mp->sum);
}

vector_destruct(&metrics);
vector_destruct(&metrics, NULL);
}
9 changes: 3 additions & 6 deletions benchmark/map_libdynamic.c
Expand Up @@ -15,21 +15,18 @@ struct map_element
uint32_t value;
};

static size_t hash(map *m, void *e)
static size_t hash(void *e)
{
(void) m;
return *(uint32_t *) e;
}

static int equal(map *m, void *e1, void *e2)
static int equal(void *e1, void *e2)
{
(void) m;
return *(uint32_t *) e1 == *(uint32_t *) e2;
}

static void set(map *m, void *e1, void *e2)
static void set(void *e1, void *e2)
{
(void) m;
*(uint64_t *) e1 = *(uint64_t *) e2;
}

Expand Down
9 changes: 3 additions & 6 deletions benchmark/map_libdynamic_subclass.c
Expand Up @@ -19,21 +19,18 @@ struct map_int_pair_element

static map_int_pair_element empty = {.key = -1};

static size_t hash(map *m, void *e)
static size_t hash(void *e)
{
(void) m;
return *(uint32_t *) e;
}

static void set(map *m, void *dst, void *src)
static void set(void *dst, void *src)
{
(void) m;
*(uint64_t *) dst = *(uint64_t *) src;
}

static int equal(map *m, void *e1, void *e2)
static int equal(void *e1, void *e2)
{
(void) m;
return *(uint32_t *) e1 == *(uint32_t *) e2;
}

Expand Down
2 changes: 1 addition & 1 deletion benchmark/vector_dynamic.c
Expand Up @@ -21,5 +21,5 @@ void vector_dynamic(vector_metric *metric, size_t n)
t2 = ntime();
metric->insert = (double) (t2 - t1) / n;

vector_destruct(&v);
vector_destruct(&v, NULL);
}
9 changes: 7 additions & 2 deletions src/dynamic/buffer.c
@@ -1,8 +1,6 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

#include "buffer.h"

Expand Down Expand Up @@ -64,6 +62,13 @@ void buffer_reserve(buffer *b, size_t capacity)
}
}

void buffer_resize(buffer *b, size_t size)
{
if (size > buffer_capacity(b))
buffer_reserve(b, size);
b->size = size;
}

void buffer_compact(buffer *b)
{
void *data;
Expand Down
1 change: 1 addition & 0 deletions src/dynamic/buffer.h
Expand Up @@ -17,6 +17,7 @@ void buffer_destruct(buffer *);
size_t buffer_size(buffer *);
size_t buffer_capacity(buffer *);
void buffer_reserve(buffer *, size_t);
void buffer_resize(buffer *, size_t);
void buffer_compact(buffer *);

/* modifiers */
Expand Down
5 changes: 5 additions & 0 deletions test/buffer.c
Expand Up @@ -20,6 +20,11 @@ void core()
assert_int_equal(buffer_size(&b), 0);
assert_int_equal(buffer_capacity(&b), 0);

buffer_resize(&b, 100);
assert_int_equal(buffer_size(&b), 100);
buffer_resize(&b, 0);
assert_int_equal(buffer_size(&b), 0);

buffer_reserve(&b, 0);
buffer_reserve(&b, 1024);
assert_int_equal(buffer_capacity(&b), 1024);
Expand Down

0 comments on commit 5234acf

Please sign in to comment.