-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.h
49 lines (34 loc) · 1.27 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
#ifndef __UTILS_H_
#define __UTILS_H_
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "MKPlugin.h"
struct buf_t {
void *data;
// size of an individual value
int value_size;
// total values added in buf
int size;
// total amount of values that it can hold
// before resize
int cap;
};
// initializes a newly created buf, with data type size and number of data items
void buf_init(struct buf_t *buf, int value_size, int init_size);
void buf_free(struct buf_t *buf);
// resize buf to the size, rest of the memory is released
void buf_resize(struct buf_t *buf, int size);
// move the current write index to the start, total cap stays the same
void buf_reset(struct buf_t *buf);
// free unused memory, may not be efficient if further pushes are expected
void buf_compact(struct buf_t *buf);
// add an item at write index, it literally copies themem to buf using
// the initial init_size, if no memory is available then buf is resized
void buf_push(struct buf_t *buf, const void *item);
void *buf_get(struct buf_t *buf, int index);
void *buf_set(struct buf_t *buf, int index, const void *);
int mk_list_len(struct mk_list *);
int get_time_diff_ms(struct timeval, struct timeval);
#endif