T
Thomas Brunko
Hy,
I'm working on a hash table and came upon a small problem. For a better
explanation I've included an extract of the header file for the hash module:
typedef struct TABLE * TABLE_P;
typedef void* (*APPLY_SINGLE_F)( void * data );
typedef void* (*APPLY_PAIR_F)( void * key, void * value );
/* Allocate memory for the table and initialise it */
TABLE_P table_create();
/* Release memory of the table */
void table_release( TABLE_P *t);
.
. Some functions for table manipulation omited.
.
/* For all (key->value) pairs execute apply(key,value). Returns first
* value with (NULL != apply(key,value)) */
void* table_apply( TABLE_P t, APPLY_PAIR_F apply );
Now I would like to write a function transform:
APPLY_PAIR_F transform( APPLY_SINGLE_F apply );
This function builds from its parameter 'apply' a function that can be used in
the call to 'table_apply'. The result of transform should be a function, that
applies the 'apply' function to the 'value' of a (key->value) pair like this:
void * result_of_transform( void * key, void * value ){
return apply( value );
}
Of course it would be easier to write a function like
void * table_apply_value( TABE_P table, APPLY_SINGLE_F apply );
which applies 'apply' to the values of the table. But I don't want to extend
the interface of my tables if it's not absolutely necessary.
Any suggestions?
Thanks,
Thomas.
I'm working on a hash table and came upon a small problem. For a better
explanation I've included an extract of the header file for the hash module:
typedef struct TABLE * TABLE_P;
typedef void* (*APPLY_SINGLE_F)( void * data );
typedef void* (*APPLY_PAIR_F)( void * key, void * value );
/* Allocate memory for the table and initialise it */
TABLE_P table_create();
/* Release memory of the table */
void table_release( TABLE_P *t);
.
. Some functions for table manipulation omited.
.
/* For all (key->value) pairs execute apply(key,value). Returns first
* value with (NULL != apply(key,value)) */
void* table_apply( TABLE_P t, APPLY_PAIR_F apply );
Now I would like to write a function transform:
APPLY_PAIR_F transform( APPLY_SINGLE_F apply );
This function builds from its parameter 'apply' a function that can be used in
the call to 'table_apply'. The result of transform should be a function, that
applies the 'apply' function to the 'value' of a (key->value) pair like this:
void * result_of_transform( void * key, void * value ){
return apply( value );
}
Of course it would be easier to write a function like
void * table_apply_value( TABE_P table, APPLY_SINGLE_F apply );
which applies 'apply' to the values of the table. But I don't want to extend
the interface of my tables if it's not absolutely necessary.
Any suggestions?
Thanks,
Thomas.