Skip to content

Commit 5234acf

Browse files
Uniform callbacks
1 parent 401868a commit 5234acf

8 files changed

Lines changed: 34 additions & 22 deletions

File tree

CHANGES

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ Version 1.0
44
Released 2017-01-03
55

66
* Initial release
7+
8+
Version 1.1
9+
===========
10+
11+
Released 2017-12-17
12+
13+
* New features:
14+
15+
- List type
16+
- More uniform interfaces

benchmark/map.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,18 @@ static void shuffle(int *array, size_t n)
7373

7474
static int set_int_empty = -1;
7575

76-
static size_t set_int_hash(map *m, void *e)
76+
static size_t set_int_hash(void *e)
7777
{
78-
(void) m;
7978
return *(int *) e;
8079
}
8180

82-
static int set_int_equal(map *m, void *e1, void *e2)
81+
static int set_int_equal(void *e1, void *e2)
8382
{
84-
(void) m;
8583
return *(int *) e1 == *(int *) e2;
8684
}
8785

88-
static void set_int_set(map *m, void *e1, void *e2)
86+
static void set_int_set(void *e1, void *e2)
8987
{
90-
(void) m;
9188
*(int *) e1 = *(int *) e2;
9289
}
9390

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

185-
vector_destruct(&metrics);
182+
vector_destruct(&metrics, NULL);
186183
}

benchmark/map_libdynamic.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@ struct map_element
1515
uint32_t value;
1616
};
1717

18-
static size_t hash(map *m, void *e)
18+
static size_t hash(void *e)
1919
{
20-
(void) m;
2120
return *(uint32_t *) e;
2221
}
2322

24-
static int equal(map *m, void *e1, void *e2)
23+
static int equal(void *e1, void *e2)
2524
{
26-
(void) m;
2725
return *(uint32_t *) e1 == *(uint32_t *) e2;
2826
}
2927

30-
static void set(map *m, void *e1, void *e2)
28+
static void set(void *e1, void *e2)
3129
{
32-
(void) m;
3330
*(uint64_t *) e1 = *(uint64_t *) e2;
3431
}
3532

benchmark/map_libdynamic_subclass.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ struct map_int_pair_element
1919

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

22-
static size_t hash(map *m, void *e)
22+
static size_t hash(void *e)
2323
{
24-
(void) m;
2524
return *(uint32_t *) e;
2625
}
2726

28-
static void set(map *m, void *dst, void *src)
27+
static void set(void *dst, void *src)
2928
{
30-
(void) m;
3129
*(uint64_t *) dst = *(uint64_t *) src;
3230
}
3331

34-
static int equal(map *m, void *e1, void *e2)
32+
static int equal(void *e1, void *e2)
3533
{
36-
(void) m;
3734
return *(uint32_t *) e1 == *(uint32_t *) e2;
3835
}
3936

benchmark/vector_dynamic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ void vector_dynamic(vector_metric *metric, size_t n)
2121
t2 = ntime();
2222
metric->insert = (double) (t2 - t1) / n;
2323

24-
vector_destruct(&v);
24+
vector_destruct(&v, NULL);
2525
}

src/dynamic/buffer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include <stdlib.h>
22
#include <stdint.h>
33
#include <string.h>
4-
#include <fcntl.h>
5-
#include <unistd.h>
64

75
#include "buffer.h"
86

@@ -64,6 +62,13 @@ void buffer_reserve(buffer *b, size_t capacity)
6462
}
6563
}
6664

65+
void buffer_resize(buffer *b, size_t size)
66+
{
67+
if (size > buffer_capacity(b))
68+
buffer_reserve(b, size);
69+
b->size = size;
70+
}
71+
6772
void buffer_compact(buffer *b)
6873
{
6974
void *data;

src/dynamic/buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void buffer_destruct(buffer *);
1717
size_t buffer_size(buffer *);
1818
size_t buffer_capacity(buffer *);
1919
void buffer_reserve(buffer *, size_t);
20+
void buffer_resize(buffer *, size_t);
2021
void buffer_compact(buffer *);
2122

2223
/* modifiers */

test/buffer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ void core()
2020
assert_int_equal(buffer_size(&b), 0);
2121
assert_int_equal(buffer_capacity(&b), 0);
2222

23+
buffer_resize(&b, 100);
24+
assert_int_equal(buffer_size(&b), 100);
25+
buffer_resize(&b, 0);
26+
assert_int_equal(buffer_size(&b), 0);
27+
2328
buffer_reserve(&b, 0);
2429
buffer_reserve(&b, 1024);
2530
assert_int_equal(buffer_capacity(&b), 1024);

0 commit comments

Comments
 (0)