home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / tools / ulxfrm / ucmp16.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  7.0 KB  |  223 lines

  1.  
  2. /*
  3. ********************************************************************
  4. * COPYRIGHT: 
  5. * (C) Copyright Taligent, Inc., 1996
  6. * (C) Copyright International Business Machines Corporation, 1996 - 1999
  7. * Licensed Material - Program-Property of IBM - All Rights Reserved. 
  8. * US Government Users Restricted Rights - Use, duplication, or disclosure 
  9. * restricted by GSA ADP Schedule Contract with IBM Corp. 
  10. *
  11. ********************************************************************
  12. */
  13.  
  14. /*
  15.  * ==========================================================================
  16.  * Copyright (c) 1995 Taligent, Inc. All Rights Reserved.
  17.  * @version 1.0 23/10/96
  18.  * @author  Helena Shih
  19.  * Based on Taligent international support for java
  20.  * Modification History : 
  21.  *
  22.  * 05/07/97     helena      Added isBogus()
  23.  * 07/15/98        erm            Synched with Java 1.2 CompactShortArray.java.
  24.  * 07/30/98        erm            Added 07/29/98 code review changes.
  25.  * 04/21/99     Damiba     Port to C/New API faster ucmp16_get
  26.  */
  27.  
  28. #ifndef UCMP16_H
  29. #define UCMP16_H
  30.  
  31.  
  32. #include "utypes.h"
  33.  
  34.  
  35.  
  36. /**
  37.  * class CompactATypeArray : use only on primitive data types
  38.  * Provides a compact way to store information that is indexed by Unicode
  39.  * values, such as character properties, types, keyboard values, etc.This
  40.  * is very useful when you have a block of Unicode data that contains
  41.  * significant values while the rest of the Unicode data is unused in the
  42.  * application or when you have a lot of redundance, such as where all 21,000
  43.  * Han ideographs have the same value.  However, lookup is much faster than a
  44.  * hash table.
  45.  * <P>
  46.  * A compact array of any primitive data type serves two purposes:
  47.  * <UL type = round>
  48.  *     <LI>Fast access of the indexed values.
  49.  *     <LI>Smaller memory footprint.
  50.  * </UL>
  51.  * <P>
  52.  * The index array always points into particular parts of the data array
  53.  * it is initially set up to point at regular block boundaries
  54.  * The following example uses blocks of 4 for simplicity
  55.  * <PRE>
  56.  * Example: Expanded
  57.  * BLOCK  0   1   2   3   4
  58.  * INDEX  0   4   8   12  16 ...
  59.  * ARRAY  abcdeababcdezyabcdea...
  60.  *        |   |   |   |   |   |...
  61.  * </PRE>
  62.  * <P>
  63.  * After compression, the index will point to various places in the data array
  64.  * wherever there is a runs of the same elements as in the original
  65.  * <PRE>
  66.  * Example: Compressed
  67.  * BLOCK  0   1   2   3   4
  68.  * INDEX  0   4   1   8   2 ...
  69.  * ARRAY  abcdeabazyabc...
  70.  * </PRE>
  71.  * <P>
  72.  * If you look at the example, index number 2 in the expanded version points
  73.  * to data position number 8, which has elements "bcde". In the compressed
  74.  * version, index number 2 points to data position 1, which also has "bcde"
  75.  * @see                CompactByteArray
  76.  * @see                CompactIntArray
  77.  * @see                CompactCharArray
  78.  * @see                CompactStringArray
  79.  * @version            $Revision: 1.3 $ 8/25/98
  80.  * @author             Helena Shih
  81.  */
  82.  
  83. typedef struct 
  84. {
  85.   int16_t* fArray;
  86.   uint16_t* fIndex;
  87.   int32_t* fHashes;
  88.   int32_t fCount;
  89.   int16_t fDefaultValue;
  90.   bool_t fCompact;    
  91.   bool_t fBogus;
  92.   int32_t kBlockShift;
  93.   int32_t kBlockMask;
  94. } CompactShortArray;
  95.  
  96.  
  97. U_CAPI const int32_t UCMP16_kMaxUnicode;
  98. U_CAPI const int32_t UCMP16_kUnicodeCount;
  99. U_CAPI const int32_t UCMP16_kBlockShift;
  100. U_CAPI const int32_t UCMP16_kBlockCount;
  101. U_CAPI const int32_t UCMP16_kBlockBytes;
  102. U_CAPI const int32_t UCMP16_kIndexShift;
  103. U_CAPI const int32_t UCMP16_kIndexCount;
  104. U_CAPI const uint32_t UCMP16_kBlockMask;
  105.  
  106. U_CAPI int32_t ucmp16_getkUnicodeCount(void);
  107. U_CAPI int32_t ucmp16_getkBlockCount(void);
  108. U_CAPI int32_t ucmp16_getkIndexCount(void);
  109. /**
  110.  * Construct an empty CompactShortArray.
  111.  * @param defaultValue the default value for all characters not explicitly in the array
  112.  */
  113. U_CAPI  CompactShortArray* ucmp16_open(int16_t defaultValue);
  114.  
  115.  /**
  116.   * Construct a CompactShortArray from a pre-computed index and values array. The values
  117.   * will be adobped by the CompactShortArray. Note: for speed, the compact method will
  118.   * only re-use blocks in the values array that are on a block boundary. The pre-computed
  119.   * arrays passed in to this constructor may re-use blocks at any position in the values
  120.   * array.
  121.   * @param indexArray the index array to be adopted
  122.   * @param newValues the value array to be adobptd
  123.   * @param count the number of entries in the value array
  124.   * @param defaultValue the default value for all characters not explicitly in the array
  125.   * @see compact
  126.   */
  127. U_CAPI  CompactShortArray* ucmp16_openAdopt(uint16_t *indexArray,
  128.                                int16_t *newValues,
  129.                                int32_t count,
  130.                                int16_t defaultValue );
  131.  
  132. U_CAPI  CompactShortArray* ucmp16_openAdoptWithBlockShift(uint16_t *indexArray,
  133.                                      int16_t *newValues,
  134.                                      int32_t count,
  135.                                      int16_t defaultValue,
  136.                                      int32_t blockShift);
  137.  
  138.  
  139. U_CAPI  void ucmp16_close(CompactShortArray* array);
  140.  /**
  141.   * Returns TRUE if the creation of the compact array fails.
  142.   */
  143.  
  144. U_CAPI  bool_t ucmp16_isBogus(const CompactShortArray* array);
  145.  
  146. /**
  147.  *
  148.  * Get the mapped value of a Unicode character.
  149.  * @param index the character to get the mapped value with
  150.  * @return the mapped value of the given character
  151.  */
  152.  
  153. #define ucmp16_get(array, index) (array->fArray[(array->fIndex[(index >> array->kBlockShift)] )+ \
  154.                            (index & array->kBlockMask)])
  155.  
  156. #define ucmp16_getu(array, index) (uint16_t)ucmp16_get(array, index)
  157.  
  158.  
  159. /**
  160.   * Set a new value for a Unicode character.
  161.   * Set automatically expands the array if it is compacted.
  162.   * @param index the character to set the mapped value with
  163.   * @param value the new mapped value
  164.   */
  165. U_CAPI  void ucmp16_set(CompactShortArray *array,
  166.                    UChar index,
  167.                    int16_t value);
  168.  
  169.  
  170.  /**
  171.   *
  172.   * Set new values for a range of Unicode character.
  173.   * @param start the starting offset of the range
  174.   * @param end the ending offset of the range
  175.   * @param value the new mapped value
  176.   */
  177. U_CAPI  void ucmp16_setRange(CompactShortArray* array,
  178.                     UChar start,
  179.                     UChar end, 
  180.                     int16_t value);
  181.  
  182.  
  183. /**
  184.  * Compact the array. For efficency, this method will only re-use
  185.  * blocks in the values array that are on a block bounday. If you
  186.  * want better compaction, you can do your own compaction and use
  187.  * the constructor that lets you pass in the pre-computed arrays.
  188.  */
  189. U_CAPI  void ucmp16_compact(CompactShortArray* array);
  190.  
  191. /**
  192.  * Get the default value.
  193.  */
  194. U_CAPI  int16_t ucmp16_getDefaultValue(const CompactShortArray* array);
  195.  
  196. /**
  197.  *
  198.  * Get the number of elements in the value array.
  199.  * @return the number of elements in the value array.
  200.  */
  201. U_CAPI  uint32_t ucmp16_getCount(const CompactShortArray* array);
  202.  
  203. /**
  204.  *
  205.  * Get the address of the value array.
  206.  * @return the address of the value array
  207.  */
  208. U_CAPI  const int16_t* ucmp16_getArray(const CompactShortArray* array);
  209.  
  210. /**
  211.  *
  212.  * Get the address of the index array.
  213.  * @return the address of the index array
  214.  */
  215. U_CAPI  const uint16_t* ucmp16_getIndex(const CompactShortArray* array);
  216.  
  217.  
  218.  
  219. #endif
  220.  
  221.  
  222.  
  223.