static UHashtable* _uhash_create(UHashFunction *keyHash, UKeyComparator *keyComp, int32_t primeIndex, UErrorCode *status) { UHashtable *result; if (U_FAILURE(*status)) return NULL; U_ASSERT(keyHash != NULL); U_ASSERT(keyComp != NULL); result = (UHashtable*) uprv_malloc(sizeof(UHashtable)); if (result == NULL) { *status = U_MEMORY_ALLOCATION_ERROR; return NULL; } result->keyHasher = keyHash; result->keyComparator = keyComp; result->keyDeleter = NULL; result->valueDeleter = NULL; _uhash_internalSetResizePolicy(result, U_GROW); _uhash_allocate(result, primeIndex, status); if (U_FAILURE(*status)) { uprv_free(result); return NULL; } return result; }
U_CAPI void U_EXPORT2 uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy) { _uhash_internalSetResizePolicy(hash, policy); hash->lowWaterMark = (int32_t)(hash->length * hash->lowWaterRatio); hash->highWaterMark = (int32_t)(hash->length * hash->highWaterRatio); _uhash_rehash(hash); }
static UHashtable* _uhash_init(UHashtable *result, UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, int32_t primeIndex, UErrorCode *status) { if (U_FAILURE(*status)) return NULL; U_ASSERT(keyHash != NULL); U_ASSERT(keyComp != NULL); result->keyHasher = keyHash; result->keyComparator = keyComp; result->valueComparator = valueComp; result->keyDeleter = NULL; result->valueDeleter = NULL; result->allocated = FALSE; _uhash_internalSetResizePolicy(result, U_GROW); _uhash_allocate(result, primeIndex, status); if (U_FAILURE(*status)) { return NULL; } return result; }
U_CAPI void U_EXPORT2 uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy) { UErrorCode status = U_ZERO_ERROR; _uhash_internalSetResizePolicy(hash, policy); hash->lowWaterMark = (int32_t)(hash->length * hash->lowWaterRatio); hash->highWaterMark = (int32_t)(hash->length * hash->highWaterRatio); _uhash_rehash(hash, &status); }