File: rope_common.h

package info (click to toggle)
tarantool 1.7.2.385.g952d79e-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,556 kB
  • ctags: 28,405
  • sloc: ansic: 180,313; cpp: 26,044; sh: 15,513; python: 4,893; makefile: 1,412
file content (57 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
#ifndef INCLUDES_TARANTOOL_TEST_UNIT_ROPE_COMMON_H
#define INCLUDES_TARANTOOL_TEST_UNIT_ROPE_COMMON_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static inline void *
str_getn(void *ctx, void *data, size_t size, size_t offset)
{
	(void) ctx;
	return (char *) data + offset;
}

static inline void
str_print(void *data, size_t n)
{
	printf("%.*s", (int) n, (char *) data);
}

static inline void *
mem_alloc(void *data, size_t size)
{
	(void) data;
	return malloc(size);
}

static inline void
mem_free(void *data, void *ptr)
{
	(void) data;
	free(ptr);
}

static inline struct rope *
test_rope_new()
{
	return rope_new(str_getn, NULL, mem_alloc, mem_free, NULL);
}

static inline void
test_rope_insert(struct rope *rope, rope_size_t offset, char *str)
{
	printf("insert offset = %zu, str = '%s'\n", (size_t) offset, str);
	rope_insert(rope, offset, str, strlen(str));
	rope_pretty_print(rope, str_print);
	rope_check(rope);
}

static inline void
test_rope_erase(struct rope *rope, rope_size_t offset)
{
	printf("erase offset = %zu\n", (size_t) offset);
	rope_erase(rope, offset);
	rope_pretty_print(rope, str_print);
	rope_check(rope);
}

#endif