home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / colcache.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-07  |  2.6 KB  |  75 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1998                    *
  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. // File colcache.cpp
  16. //
  17. // CollationCache implements a persistent in-memory cache for
  18. // TableCollationData objects.  The goal of CollationCache is to improve
  19. // the memory footprint of a process which may have multiple threads
  20. // loading up the same TableCollation object.  Performance improvement is
  21. // strictly a secondary goal.
  22. //
  23. // Created by: Alan Liu
  24. //
  25. // Modification History:
  26. //
  27. //  Date        Name        Description
  28. //  2/11/97     aliu        Creation.
  29. //  2/12/97     aliu        Modified to work with TableCollationData.
  30. //
  31. //===============================================================================
  32.  
  33. #include "colcache.h"
  34. #include "tcoldata.h"
  35. #include "uhash.h"
  36.  
  37. #ifdef COLLDEBUG
  38. #include <iostream.h>
  39. #endif
  40.  
  41. //--------------------------------------------------------------------------------
  42. // CollationCache implementation
  43. //--------------------------------------------------------------------------------
  44.  
  45. static void deleteTCD(void* TCD)
  46. {
  47.   delete (TableCollationData*)TCD;
  48. }
  49.  
  50. CollationCache::CollationCache()
  51. {
  52.   UErrorCode err = U_ZERO_ERROR;
  53.   fHashtable = uhash_open((UHashFunction) uhash_hashUString, &err);
  54.   uhash_setValueDeleter(fHashtable, deleteTCD);
  55. }
  56.  
  57.  
  58. CollationCache::~CollationCache()
  59. {
  60.   uhash_close(fHashtable);
  61. }
  62.  
  63. void CollationCache::Add(const UnicodeString& key, TableCollationData* value)
  64. {
  65.   UErrorCode err = U_ZERO_ERROR;
  66.   TableCollationData* previous = (TableCollationData*)uhash_putKey(fHashtable, key.hashCode() & 0x7FFFFFFF , value, &err);
  67. }
  68.  
  69. TableCollationData* CollationCache::Find(const UnicodeString& keyString)
  70. {
  71.   return (TableCollationData*)uhash_get(fHashtable,keyString.hashCode() & 0x7FFFFFFF);
  72. }
  73.  
  74. //eof
  75.