[base] Add iterators for FT_Hash.

* src/base/fthash.c (ft_hash_num_iterator, ft_hash_str_iterator): New
  functions.
* include/freetype/internal/fthash.h: Updated.
This commit is contained in:
Werner Lemberg
2025-06-02 16:16:06 +02:00
parent 58be4879c5
commit 820df38734
2 changed files with 75 additions and 0 deletions

View File

@@ -125,6 +125,17 @@ FT_BEGIN_HEADER
ft_hash_num_lookup( FT_Int num,
FT_Hash hash );
FT_Bool
ft_hash_num_iterator( FT_UInt *idx,
FT_Int *key,
size_t *value,
FT_Hash hash );
FT_Bool
ft_hash_str_iterator( FT_UInt *idx,
const char* *key,
size_t *value,
FT_Hash hash );
FT_END_HEADER

View File

@@ -335,4 +335,68 @@
}
FT_Bool
ft_hash_num_iterator( FT_UInt *idx,
FT_Int *key,
size_t *value,
FT_Hash hash )
{
FT_Hashnode nn = NULL;
while ( 1 )
{
if ( *idx >= hash->size )
return 0;
nn = hash->table[*idx];
if ( nn )
break;
(*idx)++;
}
if ( key )
*key = nn->key.num;
if ( value )
*value = nn->data;
(*idx)++;
return 1;
}
FT_Bool
ft_hash_str_iterator( FT_UInt *idx,
const char* *key,
size_t *value,
FT_Hash hash )
{
FT_Hashnode nn = NULL;
while ( 1 )
{
if ( *idx >= hash->size )
return 0;
nn = hash->table[*idx];
if ( nn )
break;
(*idx)++;
}
if ( key )
*key = nn->key.str;
if ( value )
*value = nn->data;
(*idx)++;
return 1;
}
/* END */