ICU4C 79
Loading...
Searching...
No Matches
bytestriebuilder.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5* Copyright (C) 2010-2016, International Business Machines
6* Corporation and others. All Rights Reserved.
7*******************************************************************************
8* file name: bytestriebuilder.h
9* encoding: UTF-8
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 2010sep25
14* created by: Markus W. Scherer
15*/
16
21
22#ifndef __BYTESTRIEBUILDER_H__
23#define __BYTESTRIEBUILDER_H__
24
25#include "unicode/utypes.h"
26
27#if U_SHOW_CPLUSPLUS_API
28
29#include "unicode/bytestrie.h"
30#include "unicode/stringpiece.h"
32
33class BytesTrieTest;
34
35U_NAMESPACE_BEGIN
36
37class BytesTrieElement;
38class CharString;
45class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder {
46public:
53
59
74 BytesTrieBuilder& add(StringPiece s, int32_t value, UErrorCode& errorCode) U_LIFETIME_BOUND;
75
94 BytesTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
95
120 UErrorCode& errorCode) U_LIFETIME_BOUND;
121
128 BytesTrieBuilder& clear() U_LIFETIME_BOUND;
129
130private:
131 friend class ::BytesTrieTest;
132
133 BytesTrieBuilder(const BytesTrieBuilder &other) = delete; // no copy constructor
134 BytesTrieBuilder &operator=(const BytesTrieBuilder &other) = delete; // no assignment operator
135
136 void buildBytes(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
137
138 virtual int32_t getElementStringLength(int32_t i) const override;
139 virtual char16_t getElementUnit(int32_t i, int32_t byteIndex) const override;
140 virtual int32_t getElementValue(int32_t i) const override;
141
142 virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t byteIndex) const override;
143
144 virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t byteIndex) const override;
145 virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const override;
146 virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const override;
147
148 virtual UBool matchNodesCanHaveValues() const override { return false; }
149
150 virtual int32_t getMaxBranchLinearSubNodeLength() const override { return BytesTrie::kMaxBranchLinearSubNodeLength; }
151 virtual int32_t getMinLinearMatch() const override { return BytesTrie::kMinLinearMatch; }
152 virtual int32_t getMaxLinearMatchLength() const override { return BytesTrie::kMaxLinearMatchLength; }
153
154 class BTLinearMatchNode : public LinearMatchNode {
155 public:
156 BTLinearMatchNode(const char *units, int32_t len, Node *nextNode);
157 virtual bool operator==(const Node &other) const override;
158 virtual void write(StringTrieBuilder &builder) override;
159 private:
160 const char *s;
161 };
162
163 virtual Node *createLinearMatchNode(int32_t i, int32_t byteIndex, int32_t length,
164 Node *nextNode) const override;
165
166 UBool ensureCapacity(int32_t length);
167 virtual int32_t write(int32_t byte) override;
168 int32_t write(const char *b, int32_t length);
169 virtual int32_t writeElementUnits(int32_t i, int32_t byteIndex, int32_t length) override;
170 virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal) override;
171 virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node) override;
172 virtual int32_t writeDeltaTo(int32_t jumpTarget) override;
173 static int32_t internalEncodeDelta(int32_t i, char intBytes[]);
174
175 CharString *strings; // Pointer not object so we need not #include internal charstr.h.
176 BytesTrieElement *elements;
177 int32_t elementsCapacity;
178 int32_t elementsLength;
179
180 // Byte serialization of the trie.
181 // Grows from the back: bytesLength measures from the end of the buffer!
182 char *bytes;
183 int32_t bytesCapacity;
184 int32_t bytesLength;
185};
186
187U_NAMESPACE_END
188
189#endif /* U_SHOW_CPLUSPLUS_API */
190
191#endif // __BYTESTRIEBUILDER_H__
C++ API: Trie for mapping byte sequences to integer values.
BytesTrieBuilder(UErrorCode &errorCode)
Constructs an empty builder.
StringPiece buildStringPiece(UStringTrieBuildOption buildOption, UErrorCode &errorCode) U_LIFETIME_BOUND
Builds a BytesTrie for the add()ed data and byte-serializes it.
virtual ~BytesTrieBuilder()
Destructor.
BytesTrieBuilder & clear() U_LIFETIME_BOUND
Removes all (byte sequence, value) pairs.
BytesTrie * build(UStringTrieBuildOption buildOption, UErrorCode &errorCode)
Builds a BytesTrie for the add()ed data.
BytesTrieBuilder & add(StringPiece s, int32_t value, UErrorCode &errorCode) U_LIFETIME_BOUND
Adds a (byte sequence, value) pair.
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: StringPiece: Read-only byte string wrapper class.
C++ API: Builder API for trie builders.
UStringTrieBuildOption
Build options for BytesTrieBuilder and CharsTrieBuilder.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315