2 * Copyright (c) 2015 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 Copyright (c) 2008-2014, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFBURSTTRIE__)
29 #define __COREFOUNDATION_CFBURSTTRIE__ 1
31 #include <CoreFoundation/CFString.h>
32 #include <CoreFoundation/CFDictionary.h>
36 typedef struct _CFBurstTrie
*CFBurstTrieRef
;
37 typedef struct _CFBurstTrieCursor
*CFBurstTrieCursorRef
;
39 typedef CF_OPTIONS(CFOptionFlags
, CFBurstTrieOpts
) {
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.
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
51 kCFBurstTrieReadOnly
= 1<<1,
53 /* kCFBurstTrieBitmapCompression
54 This option can only be used with a read-only trie, and can be used to reduce on disk file size.
56 kCFBurstTrieBitmapCompression
= 1<<2,
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
65 kCFBurstTriePrefixCompression
= 1<<3,
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.
72 kCFBurstTrieSortByKey
= 1 << 4
75 // Value for this option should be a CFNumber which contains an int.
76 #define kCFBurstTrieCreationOptionNameContainerSize CFSTR("ContainerSize")
78 typedef void (*CFBurstTrieTraversalCallback
)(void* context
, const UInt8
* key
, uint32_t keyLength
, uint32_t payload
, Boolean
*stop
);
81 CFBurstTrieRef
CFBurstTrieCreate() CF_AVAILABLE(10_7
, 4_2
);
84 CFBurstTrieRef
CFBurstTrieCreateWithOptions(CFDictionaryRef options
) CF_AVAILABLE(10_8
, 6_0
);
87 CFBurstTrieRef
CFBurstTrieCreateFromFile(CFStringRef path
) CF_AVAILABLE(10_7
, 4_2
);
90 CFBurstTrieRef
CFBurstTrieCreateFromMapBytes(char *mapBase
) CF_AVAILABLE(10_7
, 4_2
);
93 Boolean
CFBurstTrieInsert(CFBurstTrieRef trie
, CFStringRef term
, CFRange termRange
, CFIndex payload
) CF_AVAILABLE(10_7
, 4_2
);
96 Boolean
CFBurstTrieAdd(CFBurstTrieRef trie
, CFStringRef term
, CFRange termRange
, uint32_t payload
) CF_AVAILABLE(10_7
, 5_0
);
100 Boolean
CFBurstTrieInsertCharacters(CFBurstTrieRef trie
, UniChar
*chars
, CFIndex numChars
, CFIndex payload
) CF_AVAILABLE(10_7
, 4_2
);
103 Boolean
CFBurstTrieAddCharacters(CFBurstTrieRef trie
, UniChar
*chars
, CFIndex numChars
, uint32_t payload
) CF_AVAILABLE(10_7
, 5_0
);
107 Boolean
CFBurstTrieInsertUTF8String(CFBurstTrieRef trie
, UInt8
*chars
, CFIndex numChars
, CFIndex payload
) CF_AVAILABLE(10_7
, 4_2
);
110 Boolean
CFBurstTrieAddUTF8String(CFBurstTrieRef trie
, UInt8
*chars
, CFIndex numChars
, uint32_t payload
) CF_AVAILABLE(10_7
, 5_0
);
114 Boolean
CFBurstTrieInsertWithWeight(CFBurstTrieRef trie
, CFStringRef term
, CFRange termRange
, CFIndex weight
, CFIndex payload
) CF_AVAILABLE(10_7
, 4_2
);
117 Boolean
CFBurstTrieAddWithWeight(CFBurstTrieRef trie
, CFStringRef term
, CFRange termRange
, uint32_t weight
, uint32_t payload
) CF_AVAILABLE(10_7
, 5_0
);
121 Boolean
CFBurstTrieInsertCharactersWithWeight(CFBurstTrieRef trie
, UniChar
*chars
, CFIndex numChars
, CFIndex weight
, CFIndex payload
) CF_AVAILABLE(10_7
, 4_2
);
124 Boolean
CFBurstTrieAddCharactersWithWeight(CFBurstTrieRef trie
, UniChar
*chars
, CFIndex numChars
, uint32_t weight
, uint32_t payload
) CF_AVAILABLE(10_7
, 5_0
);
128 Boolean
CFBurstTrieInsertUTF8StringWithWeight(CFBurstTrieRef trie
, UInt8
*chars
, CFIndex numChars
, CFIndex weight
, CFIndex payload
) CF_AVAILABLE(10_7
, 4_2
);
131 Boolean
CFBurstTrieAddUTF8StringWithWeight(CFBurstTrieRef trie
, UInt8
*chars
, CFIndex numChars
, uint32_t weight
, uint32_t payload
) CF_AVAILABLE(10_7
, 5_0
);
135 Boolean
CFBurstTrieFind(CFBurstTrieRef trie
, CFStringRef term
, CFRange termRange
, CFIndex
*payload
) CF_AVAILABLE(10_7
, 4_2
);
138 Boolean
CFBurstTrieContains(CFBurstTrieRef trie
, CFStringRef term
, CFRange termRange
, uint32_t *payload
) CF_AVAILABLE(10_7
, 5_0
);
142 Boolean
CFBurstTrieFindCharacters(CFBurstTrieRef trie
, UniChar
*chars
, CFIndex numChars
, CFIndex
*payload
) CF_AVAILABLE(10_7
, 4_2
);
145 Boolean
CFBurstTrieContainsCharacters(CFBurstTrieRef trie
, UniChar
*chars
, CFIndex numChars
, uint32_t *payload
) CF_AVAILABLE(10_7
, 5_0
);
149 Boolean
CFBurstTrieFindUTF8String(CFBurstTrieRef trie
, UInt8
*key
, CFIndex length
, CFIndex
*payload
) CF_AVAILABLE(10_7
, 4_2
);
152 Boolean
CFBurstTrieContainsUTF8String(CFBurstTrieRef trie
, UInt8
*key
, CFIndex length
, uint32_t *payload
) CF_AVAILABLE(10_7
, 5_0
);
156 Boolean
CFBurstTrieSerialize(CFBurstTrieRef trie
, CFStringRef path
, CFBurstTrieOpts opts
) CF_AVAILABLE(10_7
, 4_2
);
159 Boolean
CFBurstTrieSerializeWithFileDescriptor(CFBurstTrieRef trie
, int fd
, CFBurstTrieOpts opts
) CF_AVAILABLE(10_7
, 4_2
);
162 void CFBurstTrieTraverse(CFBurstTrieRef trie
, void *ctx
, void (*callback
)(void*, const UInt8
*, uint32_t, uint32_t)) CF_AVAILABLE(10_7
, 4_2
);
165 CFIndex
CFBurstTrieGetCount(CFBurstTrieRef trie
) CF_AVAILABLE(10_7
, 4_2
);
168 CFBurstTrieRef
CFBurstTrieRetain(CFBurstTrieRef trie
) CF_AVAILABLE(10_7
, 4_2
);
171 void CFBurstTrieRelease(CFBurstTrieRef trie
) CF_AVAILABLE(10_7
, 4_2
);
174 CFBurstTrieCursorRef
CFBurstTrieCreateCursorForBytes(CFBurstTrieRef trie
, const UInt8
* bytes
, CFIndex length
) CF_AVAILABLE(10_8
, 6_0
);
177 CFBurstTrieCursorRef
CFBurstTrieCursorCreateByCopy(CFBurstTrieCursorRef cursor
) CF_AVAILABLE(10_8
, 6_0
);
180 Boolean
CFBurstTrieSetCursorForBytes(CFBurstTrieRef trie
, CFBurstTrieCursorRef cursor
, const UInt8
* bytes
, CFIndex length
) CF_AVAILABLE(10_8
, 6_0
);
183 Boolean
CFBurstTrieCursorIsEqual(CFBurstTrieCursorRef lhs
, CFBurstTrieCursorRef rhs
) CF_AVAILABLE(10_8
, 6_0
);
186 Boolean
CFBurstTrieCursorAdvanceForBytes(CFBurstTrieCursorRef cursor
, const UInt8
* bytes
, CFIndex length
) CF_AVAILABLE(10_8
, 6_0
);
189 Boolean
CFBurstTrieCursorGetPayload(CFBurstTrieCursorRef cursor
, uint32_t *payload
) CF_AVAILABLE(10_8
, 6_0
);
192 void CFBurstTrieTraverseFromCursor(CFBurstTrieCursorRef cursor
, void *ctx
, CFBurstTrieTraversalCallback callback
) CF_AVAILABLE(10_8
, 6_0
);
195 void CFBurstTrieCursorRelease(CFBurstTrieCursorRef cursor
) CF_AVAILABLE(10_8
, 6_0
);
199 #endif /* __COREFOUNDATION_CFBURSTTRIE__ */