[base] Add no-overwrite hash insert functions.

* src/base/fthash.c (ft_hash_num_insert_no_overwrite,
  ft_hash_str_insert_no_overwrite): New functions.
* include/freetype/internal/fthash.h: Updated.
This commit is contained in:
Werner Lemberg
2025-06-12 23:15:22 +02:00
parent 820df38734
commit 2ab0357d38
2 changed files with 47 additions and 4 deletions

View File

@@ -117,6 +117,18 @@ FT_BEGIN_HEADER
FT_Hash hash,
FT_Memory memory );
FT_Error
ft_hash_str_insert_no_overwrite( const char* key,
size_t data,
FT_Hash hash,
FT_Memory memory );
FT_Error
ft_hash_num_insert_no_overwrite( FT_Int num,
size_t data,
FT_Hash hash,
FT_Memory memory );
size_t*
ft_hash_str_lookup( const char* key,
FT_Hash hash );

View File

@@ -233,7 +233,8 @@
hash_insert( FT_Hashkey key,
size_t data,
FT_Hash hash,
FT_Memory memory )
FT_Memory memory,
FT_Bool overwrite )
{
FT_Hashnode nn;
FT_Hashnode* bp = hash_bucket( key, hash );
@@ -259,7 +260,7 @@
hash->used++;
}
else
else if ( overwrite )
nn->data = data;
Exit:
@@ -278,7 +279,7 @@
hk.str = key;
return hash_insert( hk, data, hash, memory );
return hash_insert( hk, data, hash, memory, TRUE );
}
@@ -293,7 +294,37 @@
hk.num = num;
return hash_insert( hk, data, hash, memory );
return hash_insert( hk, data, hash, memory, TRUE );
}
FT_Error
ft_hash_str_insert_no_overwrite( const char* key,
size_t data,
FT_Hash hash,
FT_Memory memory )
{
FT_Hashkey hk;
hk.str = key;
return hash_insert( hk, data, hash, memory, FALSE );
}
FT_Error
ft_hash_num_insert_no_overwrite( FT_Int num,
size_t data,
FT_Hash hash,
FT_Memory memory )
{
FT_Hashkey hk;
hk.num = num;
return hash_insert( hk, data, hash, memory, FALSE );
}