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

  1. /*
  2. ********************************************************************
  3. * COPYRIGHT: 
  4. * (C) Copyright Taligent, Inc., 1996
  5. * (C) Copyright International Business Machines Corporation, 1999
  6. * Licensed Material - Program-Property of IBM - All Rights Reserved. 
  7. * US Government Users Restricted Rights - Use, duplication, or disclosure 
  8. * restricted by GSA ADP Schedule Contract with IBM Corp. 
  9. *
  10. ********************************************************************
  11. */
  12.  
  13. /*
  14.  * ==========================================================================
  15.  * Copyright (c) 1995 Taligent, Inc. All Rights Reserved.
  16.  * @version 1.0 23/10/96
  17.  * @author  Helena Shih
  18.  * Based on Taligent international support for java
  19.  * Modification History : 
  20.  *
  21.  *  Date        Name        Description
  22.  *  2/5/97      aliu        Added CompactIntArray streamIn and streamOut methods.
  23.  * 05/07/97     helena      Added isBogus()
  24.  * 04/26/99     Madhu       Ported to C for C Implementation
  25.  */
  26.  
  27. #ifndef UCMP32_H
  28. #define UCMP32_H
  29.  
  30.  
  31. #include "utypes.h"
  32.  
  33. #include "filestrm.h"
  34.  
  35.  /**
  36.  * class CompactATypeArray : use only on primitive data types
  37.  * Provides a compact way to store information that is indexed by Unicode
  38.  * values, such as character properties, types, keyboard values, etc.This
  39.  * is very useful when you have a block of Unicode data that contains
  40.  * significant values while the rest of the Unicode data is unused in the
  41.  * application or when you have a lot of redundance, such as where all 21,000
  42.  * Han ideographs have the same value.  However, lookup is much faster than a
  43.  * hash table.
  44.  * <P>
  45.  * A compact array of any primitive data type serves two purposes:
  46.  * <UL type = round>
  47.  *     <LI>Fast access of the indexed values.
  48.  *     <LI>Smaller memory footprint.
  49.  * </UL>
  50.  * <P>
  51.  * The index array always points into particular parts of the data array
  52.  * it is initially set up to point at regular block boundaries
  53.  * The following example uses blocks of 4 for simplicity
  54.  * <PRE>
  55.  * Example: Expanded
  56.  * BLOCK  0   1   2   3   4
  57.  * INDEX  0   4   8   12  16 ...
  58.  * ARRAY  abcdeababcdezyabcdea...
  59.  *        |   |   |   |   |   |...
  60.  * </PRE>
  61.  * <P>
  62.  * After compression, the index will point to various places in the data array
  63.  * wherever there is a runs of the same elements as in the original
  64.  * <PRE>
  65.  * Example: Compressed
  66.  * BLOCK  0   1   2   3   4
  67.  * INDEX  0   4   1   8   2 ...
  68.  * ARRAY  abcdeabazyabc...
  69.  * </PRE>
  70.  * <P>
  71.  * If you look at the example, index number 2 in the expanded version points
  72.  * to data position number 8, which has elements "bcde". In the compressed
  73.  * version, index number 2 points to data position 1, which also has "bcde"
  74.  * @see                CompactByteArray
  75.  * @see                CompactIntArray
  76.  * @see                CompactCharArray
  77.  * @see                CompactStringArray
  78.  * @version            $Revision: 1.3 $ 8/25/98
  79.  * @author             Helena Shih
  80.  */
  81. /*====================================*/
  82. /*CompactIntArray
  83.  * Provides a compact way to store information that is indexed by Unicode values,
  84.  * such as character properties, types, keyboard values, etc.
  85.  * The ATypes are used by value, so should be small, integers or pointers.
  86.  *====================================
  87.  */
  88. typedef struct{
  89.     int32_t* fArray;
  90.     uint16_t* fIndex;
  91.     int32_t fCount;
  92.     bool_t fCompact;    
  93.     bool_t fBogus;
  94. } CompactIntArray;
  95.  
  96.     U_CAPI int32_t U_EXPORT2 ucmp32_getkUnicodeCount(void);
  97.     U_CAPI int32_t U_EXPORT2 ucmp32_getkBlockCount(void);
  98.  
  99.     
  100. /**
  101.  *
  102.  * Construct an empty CompactIntArray.
  103.  * @param defaultValue the default value for all characters not explicitly in the array
  104.  */
  105. U_CAPI CompactIntArray* U_EXPORT2 ucmp32_open(int32_t defaultValue);
  106.  
  107.  /**
  108.   * Construct a CompactIntArray from a pre-computed index and values array. The values
  109.   * will be adobped by the CompactIntArray. Note: for speed, the compact method will
  110.   * only re-use blocks in the values array that are on a block boundary. The pre-computed
  111.   * arrays passed in to this constructor may re-use blocks at any position in the values
  112.   * array.
  113.   * @param indexArray the index array to be adopted
  114.   * @param newValues the value array to be adobptd
  115.   * @param count the number of entries in the value array
  116.   * @see compact
  117.   */
  118. U_CAPI CompactIntArray* U_EXPORT2 ucmp32_openAdopt(uint16_t *indexArray,
  119.                           int32_t *newValues,
  120.                           int32_t count);
  121.  
  122. U_CAPI void U_EXPORT2 ucmp32_close(CompactIntArray* array);
  123.  
  124. /**
  125.   * Returns TRUE if the creation of the compact array fails.
  126.   */
  127.  
  128. U_CAPI  bool_t U_EXPORT2 ucmp32_isBogus(const CompactIntArray* array);
  129. /**
  130.   *
  131.   * Get the mapped value of a Unicode character.
  132.   * @param index the character to get the mapped value with
  133.   * @return the mapped value of the given character
  134.   */
  135. U_CAPI int32_t U_EXPORT2 ucmp32_get(CompactIntArray* array, uint16_t index); 
  136. U_CAPI uint32_t U_EXPORT2 ucmp32_getu(CompactIntArray* array, uint16_t index); 
  137.  
  138. /**
  139.   * Set a new value for a Unicode character.
  140.   * Set automatically expands the array if it is compacted.
  141.   * @param index the character to set the mapped value with
  142.   * @param value the new mapped value
  143.   */
  144. U_CAPI  void U_EXPORT2 ucmp32_set(CompactIntArray *array,
  145.                   UChar index,
  146.                   int32_t value);
  147.  
  148.  /**
  149.   *
  150.   * Set new values for a range of Unicode character.
  151.   * @param start the starting offset of the range
  152.   * @param end the ending offset of the range
  153.   * @param value the new mapped value
  154.   */
  155. U_CAPI  void U_EXPORT2 ucmp32_setRange(CompactIntArray* array,
  156.                    UChar start,
  157.                    UChar end, 
  158.                    int32_t value);
  159.  
  160. /**
  161.  * Compact the array. The value of cycle determines how large the overlap can be.
  162.  * A cycle of 1 is the most compacted, but takes the most time to do.
  163.  * If values stored in the array tend to repeat in cycles of, say, 16,
  164.  * then using that will be faster than cycle = 1, and get almost the
  165.  * same compression.
  166.  */
  167. U_CAPI  void U_EXPORT2 ucmp32_compact(CompactIntArray* array, int32_t cycle);
  168. /**
  169.  * Expands the compacted array.
  170.  * Takes the array back to a 65536 element array
  171.  */
  172.  
  173. U_CAPI  void U_EXPORT2 ucmp32_expand(CompactIntArray* array);
  174. /**
  175.  *
  176.  * Get the number of elements in the value array.
  177.  * @return the number of elements in the value array.
  178.  */
  179. U_CAPI  uint32_t U_EXPORT2 ucmp32_getCount(const CompactIntArray* array);
  180.  
  181. /**
  182.  *
  183.  * Get the address of the value array.
  184.  * @return the address of the value array
  185.  */
  186. U_CAPI  const int32_t* U_EXPORT2 ucmp32_getArray(const CompactIntArray* array);
  187.  
  188. /**
  189.  *
  190.  * Get the address of the index array.
  191.  * @return the address of the index array
  192.  */
  193. U_CAPI  const uint16_t* U_EXPORT2 ucmp32_getIndex(const CompactIntArray* array);
  194.  
  195. U_CAPI void U_EXPORT2 ucmp32_streamIn( CompactIntArray* array, FileStream* is);
  196. U_CAPI void U_EXPORT2 ucmp32_streamOut(CompactIntArray* array, FileStream* os);
  197.  
  198.  
  199.  
  200.  
  201. #endif
  202.  
  203.  
  204.  
  205.  
  206.  
  207.