Skip to content

Commit 70ff7b5

Browse files
committed
Reformatted according to clang-format rules
1 parent c9bf29c commit 70ff7b5

23 files changed

+907
-608
lines changed

include/timeseries.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include <time.h>
1111

1212
#define TS_NAME_MAX_LENGTH 1 << 9
13-
#define TS_CHUNK_SIZE 900 // 15 min
14-
#define TS_MAX_PARTITIONS 16
15-
#define DATA_PATH_SIZE 1 << 8
13+
#define TS_CHUNK_SIZE 900 // 15 min
14+
#define TS_MAX_PARTITIONS 16
15+
#define DATA_PATH_SIZE 1 << 8
1616

1717
extern const size_t TS_FLUSH_SIZE;
1818
extern const size_t TS_BATCH_OFFSET;

src/arena.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#include "arena.h"
22

3-
#define DEFAULT_ALIGNMENT (2 * sizeof(void *))
3+
#define DEFAULT_ALIGNMENT (2 * sizeof(void *))
44
#define is_power_of_two(x) ((x != 0) && ((x & (x - 1)) == 0))
55

6-
static uintptr_t align_forward(uintptr_t ptr, size_t alignment) {
6+
static uintptr_t align_forward(uintptr_t ptr, size_t alignment)
7+
{
78
uintptr_t p, a, modulo;
89
if (!is_power_of_two(alignment))
910
return 0;
1011

11-
p = ptr;
12-
a = (uintptr_t)alignment;
12+
p = ptr;
13+
a = (uintptr_t)alignment;
1314
modulo = p & (a - 1);
1415

1516
if (modulo)
@@ -18,9 +19,10 @@ static uintptr_t align_forward(uintptr_t ptr, size_t alignment) {
1819
return p;
1920
}
2021

21-
static void *arena_alloc_aligned(Arena *a, size_t size, size_t alignment) {
22+
static void *arena_alloc_aligned(Arena *a, size_t size, size_t alignment)
23+
{
2224
uintptr_t curr_ptr = (uintptr_t)a->base + (uintptr_t)a->offset;
23-
uintptr_t offset = align_forward(curr_ptr, alignment);
25+
uintptr_t offset = align_forward(curr_ptr, alignment);
2426
offset -= (uintptr_t)a->base;
2527

2628
if (offset + size > a->size)
@@ -33,25 +35,29 @@ static void *arena_alloc_aligned(Arena *a, size_t size, size_t alignment) {
3335
return ptr;
3436
}
3537

36-
void *arena_alloc(size_t size, void *context) {
38+
void *arena_alloc(size_t size, void *context)
39+
{
3740
if (!size)
3841
return 0;
3942

4043
return arena_alloc_aligned((Arena *)context, size, DEFAULT_ALIGNMENT);
4144
}
4245

43-
void arena_free(size_t size, void *ptr, void *context) {
46+
void arena_free(size_t size, void *ptr, void *context)
47+
{
4448
(void)ptr;
4549
(void)size;
4650
(void)context;
4751
}
4852

49-
void arena_free_all(void *context) {
50-
Arena *a = context;
51-
a->offset = 0;
53+
void arena_free_all(void *context)
54+
{
55+
Arena *a = context;
56+
a->offset = 0;
5257
a->committed = 0;
5358
}
5459

55-
Arena arena_init(void *buffer, size_t size) {
60+
Arena arena_init(void *buffer, size_t size)
61+
{
5662
return (Arena){.base = buffer, .size = size};
5763
}

src/arena.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ typedef struct allocator {
1010
void *context;
1111
} Allocator;
1212

13-
#define alloc(T, n, a) ((T *)((a).alloc(sizeof(T) * n, (a).context)))
13+
#define alloc(T, n, a) ((T *)((a).alloc(sizeof(T) * n, (a).context)))
1414
#define release(s, p, a) ((a).free(s, p, (a).context))
1515

1616
typedef struct arena {

src/binary.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ uint8_t read_u8(const uint8_t *const buf) { return ((uint8_t)*buf); }
88
/*
99
* write_u16() -- store a 16-bit int into a char buffer (like htons())
1010
*/
11-
void write_u16(uint8_t *buf, uint16_t val) {
11+
void write_u16(uint8_t *buf, uint16_t val)
12+
{
1213
*buf++ = val >> 8;
1314
*buf++ = val;
1415
}
1516

1617
/*
1718
* read_u16() -- unpack a 16-bit unsigned from a char buffer (like ntohs())
1819
*/
19-
uint16_t read_u16(const uint8_t *const buf) {
20+
uint16_t read_u16(const uint8_t *const buf)
21+
{
2022
return ((uint16_t)buf[0] << 8) | buf[1];
2123
}
2224

2325
/*
2426
* write_u32() -- store a 32-bit int into a char buffer (like htonl())
2527
*/
26-
void write_u32(uint8_t *buf, uint32_t val) {
28+
void write_u32(uint8_t *buf, uint32_t val)
29+
{
2730
*buf++ = val >> 24;
2831
*buf++ = val >> 16;
2932
*buf++ = val >> 8;
@@ -33,15 +36,17 @@ void write_u32(uint8_t *buf, uint32_t val) {
3336
/*
3437
* read_u32() -- unpack a 32-bit unsigned from a char buffer (like ntohl())
3538
*/
36-
uint32_t read_u32(const uint8_t *const buf) {
39+
uint32_t read_u32(const uint8_t *const buf)
40+
{
3741
return ((uint32_t)buf[0] << 24) | ((uint32_t)buf[1] << 16) |
3842
((uint32_t)buf[2] << 8) | buf[3];
3943
}
4044

4145
/*
4246
* write_i64() -- store a 64-bit int into a char buffer (like htonl())
4347
*/
44-
void write_i64(uint8_t *buf, uint64_t val) {
48+
void write_i64(uint8_t *buf, uint64_t val)
49+
{
4550
*buf++ = val >> 56;
4651
*buf++ = val >> 48;
4752
*buf++ = val >> 40;
@@ -55,7 +60,8 @@ void write_i64(uint8_t *buf, uint64_t val) {
5560
/*
5661
* read_i64() -- unpack a 64-bit unsigned from a char buffer (like ntohl())
5762
*/
58-
uint64_t read_i64(const uint8_t *const buf) {
63+
uint64_t read_i64(const uint8_t *const buf)
64+
{
5965
return ((uint64_t)buf[0] << 56) | ((uint64_t)buf[1] << 48) |
6066
((uint64_t)buf[2] << 40) | ((uint64_t)buf[3] << 32) |
6167
((uint64_t)buf[4] << 24) | ((uint64_t)buf[5] << 16) |
@@ -66,7 +72,8 @@ uint64_t read_i64(const uint8_t *const buf) {
6672
* write_f64() -- store a 64-bit float into a char buffer, taken from beej.us
6773
* guide
6874
*/
69-
void write_f64(uint8_t *buf, double_t val) {
75+
void write_f64(uint8_t *buf, double_t val)
76+
{
7077
unsigned bits = 64, expbits = 11;
7178
long double fnorm;
7279
int shift;
@@ -78,10 +85,10 @@ void write_f64(uint8_t *buf, double_t val) {
7885
} else {
7986
// check sign and begin normalization
8087
if (val < 0) {
81-
sign = 1;
88+
sign = 1;
8289
fnorm = -val;
8390
} else {
84-
sign = 0;
91+
sign = 0;
8592
fnorm = val;
8693
}
8794

@@ -95,13 +102,13 @@ void write_f64(uint8_t *buf, double_t val) {
95102
fnorm *= 2.0;
96103
shift--;
97104
}
98-
fnorm = fnorm - 1.0;
105+
fnorm = fnorm - 1.0;
99106

100107
// calculate the binary form (non-float) of the significand data
101108
significand = fnorm * ((1LL << significandbits) + 0.5f);
102109

103110
// get the biased exponent
104-
exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias
111+
exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias
105112

106113
// return the final answer
107114
uint64_t d =
@@ -115,8 +122,9 @@ void write_f64(uint8_t *buf, double_t val) {
115122
* read_f64() -- unpack a 64-bit float into a char buffer, taken from beej.us
116123
* guide
117124
*/
118-
double_t read_f64(const uint8_t *const buf) {
119-
uint64_t i = read_i64(buf);
125+
double_t read_f64(const uint8_t *const buf)
126+
{
127+
uint64_t i = read_i64(buf);
120128
unsigned bits = 64, expbits = 11;
121129
long double result;
122130
long long shift;
@@ -132,7 +140,7 @@ double_t read_f64(const uint8_t *const buf) {
132140
result += 1.0f; // add the one back on
133141

134142
// deal with the exponent
135-
bias = (1 << (expbits - 1)) - 1;
143+
bias = (1 << (expbits - 1)) - 1;
136144
shift = ((i >> significandbits) & ((1LL << expbits) - 1)) - bias;
137145
while (shift > 0) {
138146
result *= 2.0;

src/client.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* Create a non-blocking socket and use it to connect to the specified host and
1515
* port
1616
*/
17-
static int roach_connect(const struct connect_options *opts) {
17+
static int roach_connect(const struct connect_options *opts)
18+
{
1819

1920
/* socket: create the socket */
2021
int fd = socket(opts->s_family, SOCK_STREAM, 0);
@@ -24,7 +25,7 @@ static int roach_connect(const struct connect_options *opts) {
2425
/* Set socket timeout for read and write if present on options */
2526
if (opts->timeout > 0) {
2627
struct timeval tv;
27-
tv.tv_sec = opts->timeout;
28+
tv.tv_sec = opts->timeout;
2829
tv.tv_usec = 0;
2930
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv));
3031
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv));
@@ -41,8 +42,8 @@ static int roach_connect(const struct connect_options *opts) {
4142

4243
/* build the server's address */
4344
addr.sin_family = opts->s_family;
44-
addr.sin_port = htons(opts->s_port);
45-
addr.sin_addr = *((struct in_addr *)server->h_addr);
45+
addr.sin_port = htons(opts->s_port);
46+
addr.sin_addr = *((struct in_addr *)server->h_addr);
4647
bzero(&(addr.sin_zero), 8);
4748

4849
/* connect: create a connection with the server */
@@ -76,11 +77,13 @@ static int roach_connect(const struct connect_options *opts) {
7677
return CLIENT_FAILURE;
7778
}
7879

79-
void client_init(Client *c, const struct connect_options *opts) {
80+
void client_init(Client *c, const struct connect_options *opts)
81+
{
8082
c->opts = opts;
8183
}
8284

83-
int client_connect(Client *c) {
85+
int client_connect(Client *c)
86+
{
8487
int fd = roach_connect(c->opts);
8588
if (fd < 0)
8689
return CLIENT_FAILURE;
@@ -90,7 +93,8 @@ int client_connect(Client *c) {
9093

9194
void client_disconnect(Client *c) { close(c->fd); }
9295

93-
int client_send_command(Client *c, char *buf) {
96+
int client_send_command(Client *c, char *buf)
97+
{
9498
uint8_t data[BUFSIZE];
9599
Request rq = {.length = strlen(buf) - 1};
96100
snprintf(rq.query, sizeof(rq.query), "%s", buf);
@@ -101,7 +105,8 @@ int client_send_command(Client *c, char *buf) {
101105
return write(c->fd, data, n);
102106
}
103107

104-
int client_recv_response(Client *c, Response *rs) {
108+
int client_recv_response(Client *c, Response *rs)
109+
{
105110
uint8_t data[BUFSIZE];
106111
ssize_t n = read(c->fd, data, BUFSIZE);
107112
if (n < 0)

src/client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <netdb.h>
55
#include <stdio.h>
66

7-
#define CLIENT_SUCCESS 0
8-
#define CLIENT_FAILURE -1
7+
#define CLIENT_SUCCESS 0
8+
#define CLIENT_FAILURE -1
99
#define CLIENT_UNKNOWN_CMD -2
1010

1111
typedef struct response Response;

0 commit comments

Comments
 (0)