2000-03-28 22:04:39 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
|
|
|
* Copyright (C) 1997-2001, International Business Machines
|
2000-03-28 22:04:39 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-03-28 22:04:39 +00:00
|
|
|
* Date Name Description
|
|
|
|
* 03/22/00 aliu Creation.
|
2001-07-06 19:53:12 +00:00
|
|
|
* 07/06/01 aliu Modified to support int32_t keys on
|
|
|
|
* platforms with sizeof(void*) < 32.
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-03-28 22:04:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uhash.h"
|
2001-08-01 17:37:37 +00:00
|
|
|
#include "hash.h"
|
|
|
|
#include "uvector.h"
|
2000-03-28 22:04:39 +00:00
|
|
|
#include "unicode/unistr.h"
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* PUBLIC UnicodeString support functions for UHashtable
|
|
|
|
********************************************************************/
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-10-16 18:31:13 +00:00
|
|
|
uhash_hashUnicodeString(const UHashTok key) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-07-06 19:53:12 +00:00
|
|
|
const UnicodeString *str = (const UnicodeString*) key.pointer;
|
|
|
|
return (str == NULL) ? 0 : str->hashCode();
|
2000-03-28 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2001-10-16 18:31:13 +00:00
|
|
|
uhash_hashCaselessUnicodeString(const UHashTok key) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-07-06 19:53:12 +00:00
|
|
|
const UnicodeString *str = (const UnicodeString*) key.pointer;
|
|
|
|
if (str == NULL) {
|
2001-06-20 22:37:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Inefficient; a better way would be to have a hash function in
|
|
|
|
// UnicodeString that does case folding on the fly.
|
2001-07-06 19:53:12 +00:00
|
|
|
UnicodeString copy(*str);
|
2001-06-20 22:37:40 +00:00
|
|
|
return copy.foldCase().hashCode();
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2000-03-28 22:04:39 +00:00
|
|
|
uhash_deleteUnicodeString(void *obj) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2000-03-28 22:04:39 +00:00
|
|
|
delete (UnicodeString*) obj;
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2001-10-16 18:31:13 +00:00
|
|
|
uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-07-06 19:53:12 +00:00
|
|
|
const UnicodeString *str1 = (const UnicodeString*) key1.pointer;
|
|
|
|
const UnicodeString *str2 = (const UnicodeString*) key2.pointer;
|
|
|
|
if (str1 == str2) {
|
2000-03-28 22:04:39 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2001-07-06 19:53:12 +00:00
|
|
|
if (str1 == NULL || str2 == NULL) {
|
2000-03-28 22:04:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-06 19:53:12 +00:00
|
|
|
return *str1 == *str2;
|
2000-03-28 22:04:39 +00:00
|
|
|
}
|
2001-06-20 22:37:40 +00:00
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
2001-10-16 18:31:13 +00:00
|
|
|
uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-07-06 19:53:12 +00:00
|
|
|
const UnicodeString *str1 = (const UnicodeString*) key1.pointer;
|
|
|
|
const UnicodeString *str2 = (const UnicodeString*) key2.pointer;
|
|
|
|
if (str1 == str2) {
|
2001-06-20 22:37:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2001-07-06 19:53:12 +00:00
|
|
|
if (str1 == NULL || str2 == NULL) {
|
2001-06-20 22:37:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-06 19:53:12 +00:00
|
|
|
return str1->caseCompare(*str2, U_FOLD_CASE_DEFAULT) == 0;
|
2001-06-20 22:37:40 +00:00
|
|
|
}
|
2001-08-01 17:37:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deleter for Hashtable objects.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-08-01 17:37:37 +00:00
|
|
|
uhash_deleteHashtable(void *obj) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-08-01 17:37:37 +00:00
|
|
|
delete (Hashtable*) obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deleter for UVector objects.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-08-01 17:37:37 +00:00
|
|
|
uhash_deleteUVector(void *obj) {
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_USE
|
2001-08-01 17:37:37 +00:00
|
|
|
delete (UVector*) obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
//eof
|