]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/libsvn_fs_x/string_table.h
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / libsvn_fs_x / string_table.h
1 /* string_table.h : interface to string tables, private to libsvn_fs_x
2  *
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  */
22
23 #ifndef SVN_LIBSVN_FS_X_STRING_TABLE_H
24 #define SVN_LIBSVN_FS_X_STRING_TABLE_H
25
26 #include "svn_io.h"
27 #include "private/svn_temp_serializer.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32
33 /* A string table is a very space efficient, read-only representation for
34  * a set of strings with high degreed of prefix and postfix overhead.
35  *
36  * Creating a string table is a two-stage process:  Use a builder class,
37  * stuff all the strings in there and let it then do the heavy lifting of
38  * classification and compression to create the actual string table object.
39  *
40  * We will use this for the various path values in FSX change lists and
41  * node revision items.
42  */
43
44 /* the string table builder */
45 typedef struct string_table_builder_t string_table_builder_t;
46
47 /* the string table */
48 typedef struct string_table_t string_table_t;
49
50 /* Returns a new string table builder object, allocated in RESULT_POOL.
51  */
52 string_table_builder_t *
53 svn_fs_x__string_table_builder_create(apr_pool_t *result_pool);
54
55 /* Add an arbitrary NUL-terminated C-string STRING of the given length LEN
56  * to BUILDER.  Return the index of that string in the future string table.
57  * If LEN is 0, determine the length of the C-string internally.
58  */
59 apr_size_t
60 svn_fs_x__string_table_builder_add(string_table_builder_t *builder,
61                                    const char *string,
62                                    apr_size_t len);
63
64 /* Return an estimate for the on-disk size of the resulting string table.
65  * The estimate may err in both directions but tends to overestimate the
66  * space requirements for larger tables.
67  */
68 apr_size_t
69 svn_fs_x__string_table_builder_estimate_size(string_table_builder_t *builder);
70
71 /* From the given BUILDER object, create a string table object allocated
72  * in POOL that contains all strings previously added to BUILDER.
73  */
74 string_table_t *
75 svn_fs_x__string_table_create(const string_table_builder_t *builder,
76                               apr_pool_t *pool);
77
78 /* Extract string number INDEX from TABLE and return a copy of it allocated
79  * in POOL.  If LENGTH is not NULL, set *LENGTH to strlen() of the result
80  * string.  Returns an empty string for invalid indexes.
81  */
82 const char*
83 svn_fs_x__string_table_get(const string_table_t *table,
84                            apr_size_t index,
85                            apr_size_t *length,
86                            apr_pool_t *pool);
87
88 /* Write a serialized representation of the string table TABLE to STREAM.
89  * Use SCRATCH_POOL for temporary allocations.
90  */
91 svn_error_t *
92 svn_fs_x__write_string_table(svn_stream_t *stream,
93                              const string_table_t *table,
94                              apr_pool_t *scratch_pool);
95
96 /* Read the serialized string table representation from STREAM and return
97  * the resulting runtime representation in *TABLE_P.  Allocate it in
98  * RESULT_POOL and use SCRATCH_POOL for temporary allocations.
99  */
100 svn_error_t *
101 svn_fs_x__read_string_table(string_table_t **table_p,
102                             svn_stream_t *stream,
103                             apr_pool_t *result_pool,
104                             apr_pool_t *scratch_pool);
105
106 /* Serialize string table *ST within the serialization CONTEXT.
107  */
108 void
109 svn_fs_x__serialize_string_table(svn_temp_serializer__context_t *context,
110                                  string_table_t **st);
111
112 /* Deserialize string table *TABLE within the BUFFER.
113  */
114 void
115 svn_fs_x__deserialize_string_table(void *buffer,
116                                    string_table_t **table);
117
118 /* Extract string number INDEX from the cache serialized representation at
119  * TABLE and return a copy of it allocated in POOL.  If LENGTH is not NULL,
120  * set *LENGTH to strlen() of the result string.  Returns an empty string
121  * for invalid indexes.
122  */
123 const char*
124 svn_fs_x__string_table_get_func(const string_table_t *table,
125                                 apr_size_t idx,
126                                 apr_size_t *length,
127                                 apr_pool_t *pool);
128
129 #ifdef __cplusplus
130 }
131 #endif /* __cplusplus */
132
133 #endif /* SVN_LIBSVN_FS_X_STRING_TABLE_H */