]> git.saurik.com Git - apple/cf.git/blob - CFBurstTrie.h
CF-1153.18.tar.gz
[apple/cf.git] / CFBurstTrie.h
1 /*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* CFBurstTrie.h
25 Copyright (c) 2008-2014, Apple Inc. All rights reserved.
26 */
27
28 #if !defined(__COREFOUNDATION_CFBURSTTRIE__)
29 #define __COREFOUNDATION_CFBURSTTRIE__ 1
30
31 #include <CoreFoundation/CFString.h>
32 #include <CoreFoundation/CFDictionary.h>
33
34 CF_EXTERN_C_BEGIN
35
36 typedef struct _CFBurstTrie *CFBurstTrieRef;
37 typedef struct _CFBurstTrieCursor *CFBurstTrieCursorRef;
38
39 typedef CF_OPTIONS(CFOptionFlags, CFBurstTrieOpts) {
40 /*!
41 BurstTrie Options
42 Use one or more of these options with CFBurstTrieCreate to tailor optimizations to the data
43 structure for a specific kind of application. Default is no read-write, no compression.
44 */
45
46 /* kCFBurstTrieReadOnly
47 When specified, the dictionary file will be serialized in an optimized format so as to be
48 memory-mapped on the next read. Once a trie is serialized as read-only, insertions can no
49 longer occur.
50 */
51 kCFBurstTrieReadOnly = 1<<1,
52
53 /* kCFBurstTrieBitmapCompression
54 This option can only be used with a read-only trie, and can be used to reduce on disk file size.
55 */
56 kCFBurstTrieBitmapCompression = 1<<2,
57
58 /*
59 kCFBurstTriePrefixCompression
60 This option can only be used with a read-only trie, and can be used to reduce on-disk file size.
61 It is important to note that any optimizations based on word frequency will be lost; recommended
62 for applications that often search for infrequent or uncommon words. This also allow you to use
63 cursor interface.
64 */
65 kCFBurstTriePrefixCompression = 1<<3,
66
67 /*
68 kCFBurstTriePrefixCompression
69 By default, keys at list level are sorted by weight. Use this option to sort them by key value.
70 This allow you to use cursor interface.
71 */
72 kCFBurstTrieSortByKey = 1 << 4
73 };
74
75 // Value for this option should be a CFNumber which contains an int.
76 #define kCFBurstTrieCreationOptionNameContainerSize CFSTR("ContainerSize")
77
78 typedef void (*CFBurstTrieTraversalCallback)(void* context, const UInt8* key, uint32_t keyLength, uint32_t payload, Boolean *stop);
79
80 CF_EXPORT
81 CFBurstTrieRef CFBurstTrieCreate() CF_AVAILABLE(10_7, 4_2);
82
83 CF_EXPORT
84 CFBurstTrieRef CFBurstTrieCreateWithOptions(CFDictionaryRef options) CF_AVAILABLE(10_8, 6_0);
85
86 CF_EXPORT
87 CFBurstTrieRef CFBurstTrieCreateFromFile(CFStringRef path) CF_AVAILABLE(10_7, 4_2);
88
89 CF_EXPORT
90 CFBurstTrieRef CFBurstTrieCreateFromMapBytes(char *mapBase) CF_AVAILABLE(10_7, 4_2);
91
92 CF_EXPORT
93 Boolean CFBurstTrieInsert(CFBurstTrieRef trie, CFStringRef term, CFRange termRange, CFIndex payload) CF_AVAILABLE(10_7, 4_2);
94
95 CF_EXPORT
96 Boolean CFBurstTrieAdd(CFBurstTrieRef trie, CFStringRef term, CFRange termRange, uint32_t payload) CF_AVAILABLE(10_7, 5_0);
97
98
99 CF_EXPORT
100 Boolean CFBurstTrieInsertCharacters(CFBurstTrieRef trie, UniChar *chars, CFIndex numChars, CFIndex payload) CF_AVAILABLE(10_7, 4_2);
101
102 CF_EXPORT
103 Boolean CFBurstTrieAddCharacters(CFBurstTrieRef trie, UniChar *chars, CFIndex numChars, uint32_t payload) CF_AVAILABLE(10_7, 5_0);
104
105
106 CF_EXPORT
107 Boolean CFBurstTrieInsertUTF8String(CFBurstTrieRef trie, UInt8 *chars, CFIndex numChars, CFIndex payload) CF_AVAILABLE(10_7, 4_2);
108
109 CF_EXPORT
110 Boolean CFBurstTrieAddUTF8String(CFBurstTrieRef trie, UInt8 *chars, CFIndex numChars, uint32_t payload) CF_AVAILABLE(10_7, 5_0);
111
112
113 CF_EXPORT
114 Boolean CFBurstTrieInsertWithWeight(CFBurstTrieRef trie, CFStringRef term, CFRange termRange, CFIndex weight, CFIndex payload) CF_AVAILABLE(10_7, 4_2);
115
116 CF_EXPORT
117 Boolean CFBurstTrieAddWithWeight(CFBurstTrieRef trie, CFStringRef term, CFRange termRange, uint32_t weight, uint32_t payload) CF_AVAILABLE(10_7, 5_0);
118
119
120 CF_EXPORT
121 Boolean CFBurstTrieInsertCharactersWithWeight(CFBurstTrieRef trie, UniChar *chars, CFIndex numChars, CFIndex weight, CFIndex payload) CF_AVAILABLE(10_7, 4_2);
122
123 CF_EXPORT
124 Boolean CFBurstTrieAddCharactersWithWeight(CFBurstTrieRef trie, UniChar *chars, CFIndex numChars, uint32_t weight, uint32_t payload) CF_AVAILABLE(10_7, 5_0);
125
126
127 CF_EXPORT
128 Boolean CFBurstTrieInsertUTF8StringWithWeight(CFBurstTrieRef trie, UInt8 *chars, CFIndex numChars, CFIndex weight, CFIndex payload) CF_AVAILABLE(10_7, 4_2);
129
130 CF_EXPORT
131 Boolean CFBurstTrieAddUTF8StringWithWeight(CFBurstTrieRef trie, UInt8 *chars, CFIndex numChars, uint32_t weight, uint32_t payload) CF_AVAILABLE(10_7, 5_0);
132
133
134 CF_EXPORT
135 Boolean CFBurstTrieFind(CFBurstTrieRef trie, CFStringRef term, CFRange termRange, CFIndex *payload) CF_AVAILABLE(10_7, 4_2);
136
137 CF_EXPORT
138 Boolean CFBurstTrieContains(CFBurstTrieRef trie, CFStringRef term, CFRange termRange, uint32_t *payload) CF_AVAILABLE(10_7, 5_0);
139
140
141 CF_EXPORT
142 Boolean CFBurstTrieFindCharacters(CFBurstTrieRef trie, UniChar *chars, CFIndex numChars, CFIndex *payload) CF_AVAILABLE(10_7, 4_2);
143
144 CF_EXPORT
145 Boolean CFBurstTrieContainsCharacters(CFBurstTrieRef trie, UniChar *chars, CFIndex numChars, uint32_t *payload) CF_AVAILABLE(10_7, 5_0);
146
147
148 CF_EXPORT
149 Boolean CFBurstTrieFindUTF8String(CFBurstTrieRef trie, UInt8 *key, CFIndex length, CFIndex *payload) CF_AVAILABLE(10_7, 4_2);
150
151 CF_EXPORT
152 Boolean CFBurstTrieContainsUTF8String(CFBurstTrieRef trie, UInt8 *key, CFIndex length, uint32_t *payload) CF_AVAILABLE(10_7, 5_0);
153
154
155 CF_EXPORT
156 Boolean CFBurstTrieSerialize(CFBurstTrieRef trie, CFStringRef path, CFBurstTrieOpts opts) CF_AVAILABLE(10_7, 4_2);
157
158 CF_EXPORT
159 Boolean CFBurstTrieSerializeWithFileDescriptor(CFBurstTrieRef trie, int fd, CFBurstTrieOpts opts) CF_AVAILABLE(10_7, 4_2);
160
161 CF_EXPORT
162 void CFBurstTrieTraverse(CFBurstTrieRef trie, void *ctx, void (*callback)(void*, const UInt8*, uint32_t, uint32_t)) CF_AVAILABLE(10_7, 4_2);
163
164 CF_EXPORT
165 CFIndex CFBurstTrieGetCount(CFBurstTrieRef trie) CF_AVAILABLE(10_7, 4_2);
166
167 CF_EXPORT
168 CFBurstTrieRef CFBurstTrieRetain(CFBurstTrieRef trie) CF_AVAILABLE(10_7, 4_2);
169
170 CF_EXPORT
171 void CFBurstTrieRelease(CFBurstTrieRef trie) CF_AVAILABLE(10_7, 4_2);
172
173 CF_EXPORT
174 CFBurstTrieCursorRef CFBurstTrieCreateCursorForBytes(CFBurstTrieRef trie, const UInt8* bytes, CFIndex length) CF_AVAILABLE(10_8, 6_0);
175
176 CF_EXPORT
177 CFBurstTrieCursorRef CFBurstTrieCursorCreateByCopy(CFBurstTrieCursorRef cursor) CF_AVAILABLE(10_8, 6_0);
178
179 CF_EXPORT
180 Boolean CFBurstTrieSetCursorForBytes(CFBurstTrieRef trie, CFBurstTrieCursorRef cursor, const UInt8* bytes, CFIndex length) CF_AVAILABLE(10_8, 6_0);
181
182 CF_EXPORT
183 Boolean CFBurstTrieCursorIsEqual(CFBurstTrieCursorRef lhs, CFBurstTrieCursorRef rhs) CF_AVAILABLE(10_8, 6_0);
184
185 CF_EXPORT
186 Boolean CFBurstTrieCursorAdvanceForBytes(CFBurstTrieCursorRef cursor, const UInt8* bytes, CFIndex length) CF_AVAILABLE(10_8, 6_0);
187
188 CF_EXPORT
189 Boolean CFBurstTrieCursorGetPayload(CFBurstTrieCursorRef cursor, uint32_t *payload) CF_AVAILABLE(10_8, 6_0);
190
191 CF_EXPORT
192 void CFBurstTrieTraverseFromCursor(CFBurstTrieCursorRef cursor, void *ctx, CFBurstTrieTraversalCallback callback) CF_AVAILABLE(10_8, 6_0);
193
194 CF_EXPORT
195 void CFBurstTrieCursorRelease(CFBurstTrieCursorRef cursor) CF_AVAILABLE(10_8, 6_0);
196
197 CF_EXTERN_C_END
198
199 #endif /* __COREFOUNDATION_CFBURSTTRIE__ */