home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / ucmp16.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  6.6 KB  |  213 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 CompactShortArray {
  84.   int16_t* fArray;
  85.   uint16_t* fIndex;
  86.   int32_t* fHashes;
  87.   int32_t fCount;
  88.   int16_t fDefaultValue;
  89.   bool_t fCompact;    
  90.   bool_t fBogus;
  91.   int32_t kBlockShift;
  92.   int32_t kBlockMask;
  93. } CompactShortArray;
  94.  
  95.  
  96. U_CAPI int32_t U_EXPORT2 ucmp16_getkUnicodeCount(void);
  97. U_CAPI int32_t U_EXPORT2 ucmp16_getkBlockCount(void);
  98.  
  99. /**
  100.  * Construct an empty CompactShortArray.
  101.  * @param defaultValue the default value for all characters not explicitly in the array
  102.  */
  103. U_CAPI  CompactShortArray* U_EXPORT2 ucmp16_open(int16_t defaultValue);
  104.  
  105.  /**
  106.   * Construct a CompactShortArray from a pre-computed index and values array. The values
  107.   * will be adobped by the CompactShortArray. Note: for speed, the compact method will
  108.   * only re-use blocks in the values array that are on a block boundary. The pre-computed
  109.   * arrays passed in to this constructor may re-use blocks at any position in the values
  110.   * array.
  111.   * @param indexArray the index array to be adopted
  112.   * @param newValues the value array to be adobptd
  113.   * @param count the number of entries in the value array
  114.   * @param defaultValue the default value for all characters not explicitly in the array
  115.   * @see compact
  116.   */
  117. U_CAPI  CompactShortArray* U_EXPORT2 ucmp16_openAdopt(uint16_t *indexArray,
  118.                             int16_t *newValues,
  119.                             int32_t count,
  120.                             int16_t defaultValue );
  121.  
  122. U_CAPI  CompactShortArray* U_EXPORT2 ucmp16_openAdoptWithBlockShift(uint16_t *indexArray,
  123.                                   int16_t *newValues,
  124.                                   int32_t count,
  125.                                   int16_t defaultValue,
  126.                                   int32_t blockShift);
  127.  
  128.  
  129. U_CAPI  void U_EXPORT2 ucmp16_close(CompactShortArray* array);
  130.  /**
  131.   * Returns TRUE if the creation of the compact array fails.
  132.   */
  133.  
  134. U_CAPI  bool_t U_EXPORT2 ucmp16_isBogus(const CompactShortArray* array);
  135.  
  136. /**
  137.  *
  138.  * Get the mapped value of a Unicode character.
  139.  * @param index the character to get the mapped value with
  140.  * @return the mapped value of the given character
  141.  */
  142.  
  143. #define ucmp16_get(array, index) (array->fArray[(array->fIndex[(index >> array->kBlockShift)] )+ \
  144.                            (index & array->kBlockMask)])
  145.  
  146. #define ucmp16_getu(array, index) (uint16_t)ucmp16_get(array, index)
  147.  
  148.  
  149. /**
  150.   * Set a new value for a Unicode character.
  151.   * Set automatically expands the array if it is compacted.
  152.   * @param index the character to set the mapped value with
  153.   * @param value the new mapped value
  154.   */
  155. U_CAPI  void U_EXPORT2 ucmp16_set(CompactShortArray *array,
  156.                 UChar index,
  157.                 int16_t value);
  158.  
  159.  
  160.  /**
  161.   *
  162.   * Set new values for a range of Unicode character.
  163.   * @param start the starting offset of the range
  164.   * @param end the ending offset of the range
  165.   * @param value the new mapped value
  166.   */
  167. U_CAPI  void U_EXPORT2 ucmp16_setRange(CompactShortArray* array,
  168.                      UChar start,
  169.                      UChar end, 
  170.                      int16_t value);
  171.  
  172.  
  173. /**
  174.  * Compact the array. For efficency, this method will only re-use
  175.  * blocks in the values array that are on a block bounday. If you
  176.  * want better compaction, you can do your own compaction and use
  177.  * the constructor that lets you pass in the pre-computed arrays.
  178.  */
  179. U_CAPI  void U_EXPORT2 ucmp16_compact(CompactShortArray* array);
  180.  
  181. /**
  182.  * Get the default value.
  183.  */
  184. U_CAPI  int16_t U_EXPORT2 ucmp16_getDefaultValue(const CompactShortArray* array);
  185.  
  186. /**
  187.  *
  188.  * Get the number of elements in the value array.
  189.  * @return the number of elements in the value array.
  190.  */
  191. U_CAPI  uint32_t U_EXPORT2 ucmp16_getCount(const CompactShortArray* array);
  192.  
  193. /**
  194.  *
  195.  * Get the address of the value array.
  196.  * @return the address of the value array
  197.  */
  198. U_CAPI  const int16_t* U_EXPORT2 ucmp16_getArray(const CompactShortArray* array);
  199.  
  200. /**
  201.  *
  202.  * Get the address of the index array.
  203.  * @return the address of the index array
  204.  */
  205. U_CAPI  const uint16_t* U_EXPORT2 ucmp16_getIndex(const CompactShortArray* array);
  206.  
  207.  
  208.  
  209. #endif
  210.  
  211.  
  212.  
  213.