sl@0: /* sl@0: ******************************************************************** sl@0: * COPYRIGHT: sl@0: * Copyright (c) 1996-2004, International Business Machines Corporation and sl@0: * others. All Rights Reserved. sl@0: ******************************************************************** sl@0: */ sl@0: sl@0: sl@0: sl@0: #ifndef UCMP8_H sl@0: #define UCMP8_H sl@0: sl@0: /* 32-bits. sl@0: Bump this whenever the internal structure changes. sl@0: */ sl@0: #define ICU_UCMP8_VERSION 0x01260000 sl@0: sl@0: #include "unicode/utypes.h" sl@0: sl@0: /*==================================== sl@0: * class CompactByteArray sl@0: * Provides a compact way to store information that is indexed by Unicode values, sl@0: * such as character properties, types, keyboard values, etc. sl@0: * The ATypes are used by value, so should be small, integers or pointers. sl@0: *==================================== sl@0: */ sl@0: sl@0: U_CAPI int32_t U_EXPORT2 ucmp8_getkUnicodeCount(void); sl@0: U_CAPI int32_t U_EXPORT2 ucmp8_getkBlockCount(void); sl@0: sl@0: typedef struct CompactByteArray { sl@0: uint32_t fStructSize; sl@0: int8_t* fArray; sl@0: uint16_t* fIndex; sl@0: int32_t fCount; sl@0: UBool fCompact; sl@0: UBool fBogus; sl@0: UBool fAlias; sl@0: UBool fIAmOwned; /* don't free CBA on close */ sl@0: } CompactByteArray; sl@0: sl@0: #define UCMP8_kUnicodeCount 65536 sl@0: #define UCMP8_kBlockShift 7 sl@0: #define UCMP8_kBlockCount (1<fArray[(array->fIndex[index >> UCMP8_kBlockShift] & 0xFFFF) + (index & UCMP8_kBlockMask)]) sl@0: sl@0: #define ucmp8_getu(array,index) (uint8_t)ucmp8_get(array,index) sl@0: sl@0: sl@0: /** sl@0: * Set a new value for a Unicode character. sl@0: * Set automatically expands the array if it is compacted. sl@0: * sl@0: * @param array the CompactByteArray to be set sl@0: * @param character the character to set the mapped value with sl@0: * @param value the new mapped value sl@0: */ sl@0: U_CAPI void U_EXPORT2 ucmp8_set(CompactByteArray* array, sl@0: UChar character, sl@0: int8_t value); sl@0: sl@0: /** sl@0: * Set new values for a range of Unicode character. sl@0: * sl@0: * @param array the CompactByteArray to be set sl@0: * @param start the starting offset of the range sl@0: * @param end the ending offset of the range sl@0: * @param value the new mapped value sl@0: */ sl@0: U_CAPI void U_EXPORT2 ucmp8_setRange(CompactByteArray* array, sl@0: UChar start, sl@0: UChar end, sl@0: int8_t value); sl@0: sl@0: U_CAPI int32_t U_EXPORT2 ucmp8_getCount(const CompactByteArray* array); sl@0: U_CAPI const int8_t* U_EXPORT2 ucmp8_getArray(const CompactByteArray* array); sl@0: U_CAPI const uint16_t* U_EXPORT2 ucmp8_getIndex(const CompactByteArray* array); sl@0: sl@0: /** sl@0: * Compact the array. sl@0: * The value of cycle determines how large the overlap can be. sl@0: * A cycle of 1 is the most compacted, but takes the most time to do. sl@0: * If values stored in the array tend to repeat in cycles of, say, 16, sl@0: * then using that will be faster than cycle = 1, and get almost the sl@0: * same compression. sl@0: * @param array The CompactByteArray to be compacted sl@0: * @param cycle The value determines how large the overlap can be. sl@0: */ sl@0: U_CAPI void U_EXPORT2 ucmp8_compact(CompactByteArray* array, sl@0: uint32_t cycle); sl@0: sl@0: /** Expanded takes the array back to a 65536 element array sl@0: * @param array The CompactByteArray to be expanded sl@0: */ sl@0: U_CAPI void U_EXPORT2 ucmp8_expand(CompactByteArray* array); sl@0: sl@0: /** sl@0: * Flatten into a memory structure. Pass in NULL to pre-flight to get the required size. sl@0: * @internal sl@0: */ sl@0: U_CAPI uint32_t U_EXPORT2 ucmp8_flattenMem(const CompactByteArray* array, uint8_t *MS); sl@0: sl@0: /* initializes an existing CBA from memory. Will cause ucmp8_close() to not deallocate anything. */ sl@0: U_CAPI void U_EXPORT2 ucmp8_initFromData(CompactByteArray* array, const uint8_t **source, UErrorCode *status); sl@0: sl@0: #endif sl@0: