1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2002-2010, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: propsvec.h
12 * tab size: 8 (not used)
15 * created on: 2002feb22
16 * created by: Markus W. Scherer
18 * Store bits (Unicode character properties) in bit set vectors.
21 #ifndef __UPROPSVEC_H__
22 #define __UPROPSVEC_H__
24 #include "unicode/utypes.h"
31 * Unicode Properties Vectors associated with code point ranges.
33 * Rows of uint32_t integers in a contiguous array store
34 * the range limits and the properties vectors.
36 * Logically, each row has a certain number of uint32_t values,
37 * which is set via the upvec_open() "columns" parameter.
39 * Internally, two additional columns are stored.
40 * In each internal row,
41 * row[0] contains the start code point and
42 * row[1] contains the limit code point,
43 * which is the start of the next range.
45 * Initially, there is only one "normal" row for
46 * range [0..0x110000[ with values 0.
47 * There are additional rows for special purposes, see UPVEC_FIRST_SPECIAL_CP.
49 * It would be possible to store only one range boundary per row,
50 * but self-contained rows allow to later sort them by contents.
53 typedef struct UPropsVectors UPropsVectors
;
56 * Special pseudo code points for storing the initialValue and the errorValue,
57 * which are used to initialize a UTrie2 or similar.
59 #define UPVEC_FIRST_SPECIAL_CP 0x110000
60 #define UPVEC_INITIAL_VALUE_CP 0x110000
61 #define UPVEC_ERROR_VALUE_CP 0x110001
62 #define UPVEC_MAX_CP 0x110001
65 * Special pseudo code point used in upvec_compact() signalling the end of
66 * delivering special values and the beginning of delivering real ones.
67 * Stable value, unlike UPVEC_MAX_CP which might grow over time.
69 #define UPVEC_START_REAL_VALUES_CP 0x200000
72 * Open a UPropsVectors object.
73 * @param columns Number of value integers (uint32_t) per row.
75 U_CAPI UPropsVectors
* U_EXPORT2
76 upvec_open(int32_t columns
, UErrorCode
*pErrorCode
);
79 upvec_close(UPropsVectors
*pv
);
82 * In rows for code points [start..end], select the column,
83 * reset the mask bits and set the value bits (ANDed with the mask).
85 * Will set U_NO_WRITE_PERMISSION if called after upvec_compact().
88 upvec_setValue(UPropsVectors
*pv
,
89 UChar32 start
, UChar32 end
,
91 uint32_t value
, uint32_t mask
,
92 UErrorCode
*pErrorCode
);
95 * Logically const but must not be used on the same pv concurrently!
96 * Always returns 0 if called after upvec_compact().
98 U_CAPI
uint32_t U_EXPORT2
99 upvec_getValue(const UPropsVectors
*pv
, UChar32 c
, int32_t column
);
102 * pRangeStart and pRangeEnd can be NULL.
103 * @return NULL if rowIndex out of range and for illegal arguments,
104 * or if called after upvec_compact()
106 U_CAPI
uint32_t * U_EXPORT2
107 upvec_getRow(const UPropsVectors
*pv
, int32_t rowIndex
,
108 UChar32
*pRangeStart
, UChar32
*pRangeEnd
);
111 * Compact the vectors:
112 * - modify the memory
113 * - keep only unique vectors
114 * - store them contiguously from the beginning of the memory
115 * - for each (non-unique) row, call the handler function
117 * The handler's rowIndex is the index of the row in the compacted
119 * (Therefore, it starts at 0 increases in increments of the columns value.)
121 * In a first phase, only special values are delivered (each exactly once),
122 * with start==end both equalling a special pseudo code point.
123 * Then the handler is called once more with start==end==UPVEC_START_REAL_VALUES_CP
124 * where rowIndex is the length of the compacted array,
125 * and the row is arbitrary (but not NULL).
126 * Then, in the second phase, the handler is called for each row of real values.
128 typedef void U_CALLCONV
129 UPVecCompactHandler(void *context
,
130 UChar32 start
, UChar32 end
,
131 int32_t rowIndex
, uint32_t *row
, int32_t columns
,
132 UErrorCode
*pErrorCode
);
134 U_CAPI
void U_EXPORT2
135 upvec_compact(UPropsVectors
*pv
, UPVecCompactHandler
*handler
, void *context
, UErrorCode
*pErrorCode
);
138 * Get the vectors array after calling upvec_compact().
139 * The caller must not modify nor release the returned array.
140 * Returns NULL if called before upvec_compact().
142 U_CAPI
const uint32_t * U_EXPORT2
143 upvec_getArray(const UPropsVectors
*pv
, int32_t *pRows
, int32_t *pColumns
);
146 * Get a clone of the vectors array after calling upvec_compact().
147 * The caller owns the returned array and must uprv_free() it.
148 * Returns NULL if called before upvec_compact().
150 U_CAPI
uint32_t * U_EXPORT2
151 upvec_cloneArray(const UPropsVectors
*pv
,
152 int32_t *pRows
, int32_t *pColumns
, UErrorCode
*pErrorCode
);
155 * Call upvec_compact(), create a 16-bit UTrie2 with indexes into the compacted
156 * vectors array, and freeze the trie.
158 U_CAPI UTrie2
* U_EXPORT2
159 upvec_compactToUTrie2WithRowIndexes(UPropsVectors
*pv
, UErrorCode
*pErrorCode
);
161 struct UPVecToUTrie2Context
{
163 int32_t initialValue
;
167 typedef struct UPVecToUTrie2Context UPVecToUTrie2Context
;
169 /* context=UPVecToUTrie2Context, creates the trie and stores the rowIndex values */
170 U_CAPI
void U_CALLCONV
171 upvec_compactToUTrie2Handler(void *context
,
172 UChar32 start
, UChar32 end
,
173 int32_t rowIndex
, uint32_t *row
, int32_t columns
,
174 UErrorCode
*pErrorCode
);