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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
Copyright (C) 2015-2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyHTML_UTILS_MCHAR_ASYNC_H
#define MyHTML_UTILS_MCHAR_ASYNC_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <myhtml/myosi.h>
#include <myhtml/utils/mcsync.h>
#define mchar_async_cache_has_nodes(cache) cache.count
typedef struct mchar_async_node mchar_async_node_t;
struct mchar_async_cache_node {
void *value;
size_t size;
size_t left;
size_t right;
size_t parent;
}
typedef mchar_async_cache_node_t;
struct mchar_async_chunk {
char *begin;
size_t length;
size_t size;
struct mchar_async_chunk *next;
struct mchar_async_chunk *prev;
}
typedef mchar_async_chunk_t;
struct mchar_async_cache {
mchar_async_cache_node_t *nodes;
size_t nodes_size;
size_t nodes_length;
size_t nodes_root;
size_t count;
size_t *index;
size_t index_length;
size_t index_size;
}
typedef mchar_async_cache_t;
struct mchar_async_node {
mchar_async_chunk_t *chunk;
mchar_async_cache_t cache;
};
struct mchar_async {
size_t origin_size;
mchar_async_chunk_t **chunks;
size_t chunks_pos_size;
size_t chunks_pos_length;
size_t chunks_size;
size_t chunks_length;
mchar_async_cache_t chunk_cache;
mchar_async_node_t *nodes;
size_t nodes_length;
size_t nodes_size;
size_t *nodes_cache;
size_t nodes_cache_length;
size_t nodes_cache_size;
mcsync_t *mcsync;
}
typedef mchar_async_t;
mchar_async_t * mchar_async_create(size_t pos_size, size_t size);
void mchar_async_init(mchar_async_t *mchar_async, size_t chunk_len, size_t char_size);
void mchar_async_clean(mchar_async_t *mchar_async);
mchar_async_t * mchar_async_destroy(mchar_async_t *mchar_async, int destroy_self);
char * mchar_async_malloc(mchar_async_t *mchar_async, size_t node_idx, size_t size);
char * mchar_async_realloc(mchar_async_t *mchar_async, size_t node_idx, char *data, size_t data_len, size_t new_size);
void mchar_async_free(mchar_async_t *mchar_async, size_t node_idx, char *entry);
size_t mchar_async_node_add(mchar_async_t *mchar_async);
void mchar_async_node_clean(mchar_async_t *mchar_async, size_t node_idx);
void mchar_async_node_delete(mchar_async_t *mchar_async, size_t node_idx);
mchar_async_chunk_t * mchar_async_chunk_malloc(mchar_async_t *mchar_async, mchar_async_node_t *node, size_t length);
char * mchar_async_crop_first_chars(mchar_async_t *mchar_async, size_t node_idx, char *data, size_t crop_len);
char * mchar_async_crop_first_chars_without_cache(char *data, size_t crop_len);
size_t mchar_async_get_size_by_data(const char *data);
// cache
void mchar_async_cache_init(mchar_async_cache_t *cache);
mchar_async_cache_t * mchar_async_cache_destroy(mchar_async_cache_t *cache, bool self_destroy);
void mchar_async_cache_clean(mchar_async_cache_t *cache);
void mchar_async_cache_add(mchar_async_cache_t *cache, void* value, size_t size);
size_t mchar_async_cache_delete(mchar_async_cache_t *cache, size_t size);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* mchar_async_h */
|