The containers in this library use callback schemes to identify and handle the keys and values given to them.
This has the advantage, that memory management can be handled by the container.
Callback | Description |
---|---|
mulle_container_keycallback_int mulle_container_valuecallback_int |
store any int except mulle_not_an_int (INT_MIN ) |
mulle_container_keycallback_intptr mulle_container_valuecallback_intptr |
store any intptr_t except mulle_not_an_intptr (INTPTR_MIN ) |
mulle_container_keycallback_nonowned_pointer mulle_container_valuecallback_nonowned_pointer |
store any void * except NULL. |
mulle_container_keycallback_nonowned_cstring mulle_container_valuecallback_nonowned_cstring |
store any char * except NULL. |
mulle_container_keycallback_nonowned_pointer_or_null |
store any void * except mulle_not_an_intptr ((void *) INTPTR_MIN ) |
Keys are void *
. All values are possible except mulle_container_not_a_pointer_key
.
Callback | Description |
---|---|
mulle_container_keycallback_owned_pointer mulle_container_valuecallback_owned_pointer |
store any void * |
mulle_container_keycallback_owned_cstring mulle_container_valuecallback_owned_cstring |
store any char * except NULL. Items will be freed when removed. |
Callback | Description |
---|---|
mulle_container_keycallback_copied_cstring mulle_container_valuecallback_copied_cstring |
Store a copy char * except NULL. Items will be freed when removed. |
Keys are int. All values are possible except mulle_not_an_int
.
Keys are intptr_t. All values are possible except mulle_not_an_intptr
.
Keys are char *
. All values are possible except NULL. The key is copied by the container and will be freed eventually.
Keys are char *
. All values are possible except NULL. The key is NOT copied by the container. The caller needs to make sure, that the c-string sticks around.
Keys are char *
. All values are possible except NULL. The key is then owned by the container and will be freed eventually.
Keys are void *
. All values are possible except NULL.
Keys are void *
. All values are possible except NULL. The key is then owned by the container and will be freed eventually.
The difference to
mulle_container_keycallback_owned_cstring
is in.hash
and.describe
.
Keys are void *
. All values are possible except mulle_container_not_a_pointer_key
.
Keys are void *
. All values are possible except mulle_container_not_a_pointer_key
. The key is then owned by the container and will be freed by the container, when it is not used anymore.
struct mulle_container_keycallback
{
uintptr_t (*hash)( struct mulle_container_keycallback *callback, void *p);
int (*is_equal)( struct mulle_container_keycallback *callback, void *p, void *q);
void *(*retain)( struct mulle_container_keycallback *callback, void *p, struct mulle_allocator *allocator);
void (*release)( struct mulle_container_keycallback *callback, void *p, struct mulle_allocator *allocator);
void *(*describe)( struct mulle_container_keycallback *callback, void *p, struct mulle_allocator *allocator);
void *not_a_key_marker;
void *userinfo;
};
This struct is mostly a collection of function pointers. The paramter p
indicated the key
as passed to the container. The allocator
is the mulle-allocator to be used for memory management of this key. Note that the first parameter is the callback
itself, which can be useful to access the userinfo
.
Field | Description |
---|---|
.hash |
is used to derive a uintptr_t hash from p . |
.is_equal |
is used to test two keys p and q for equality (1: equals). |
.retain |
is an operation to transfer ownership of p to the container using allocator . |
.release |
is an operation to yield ownership of p from the container using allocator . |
.describe |
is debugging operation that returns a UTF8 string created with allocator . |
.not_a_key_marker |
if the container desires to store 0/nil, this value will be used as a marke for an empty slot |
.userinfo |
a place to store something for the user |
struct mulle_container_valuecallback
{
void *(*retain)( struct mulle_container_valuecallback *callback, void *p, struct mulle_allocator *allocator);
void (*release)( struct mulle_container_valuecallback *callback, void *p, struct mulle_allocator *allocator);
void *(*describe)( struct mulle_container_valuecallback *callback, void *p, struct mulle_allocator *allocator);
void *userinfo;
};
This is basically a reduced version of mulle_container_keycallback
for values.
Field | Description |
---|---|
.retain |
is an operation to transfer ownership of p to the container using allocator . |
.release |
is an operation to yield ownership of p from the container using allocator . |
.describe |
is debugging operation that returns a UTF8 string created with allocator . |
.userinfo |
a place to store something for the user |
struct mulle_container_keyvaluecallback
{
struct mulle_container_keycallback keycallback;
struct mulle_container_valuecallback valuecallback;
};
A combination of both structs.
This macro is defined as INT_MIN
(currently).
This macro is defined as INTPTR_MIN
(currently).
This macro is defined as UINTPTR_MAX
(currently).
mulle_container_callback_self
function typed for mulle_container_keycallback
.
mulle_container_callback_self
function typed for mulle_container_valuecallback
.
mulle_container_keycallback_nop
function typed for mulle_container_keycallback
.
mulle_container_valuecallback_nop
function typed for mulle_container_valuecallback
.
mulle_container_keycallback_nop
function typed for mulle_container_keycallback
.
mulle_container_valuecallback_nop
function typed for mulle_container_valuecallback
.
Predefined functions useful for constructing callback structs.
void *mulle_container_callback_self( void *ignore, void *p, struct mulle_allocator *a)
Returns p
. Useful in .retain.
void mulle_container_callback_nop( void *ignore, void *p, struct mulle_allocator *a)
Does nothing. Useful in .release.
void *mulle_container_callback_no_value( void *ignore, void *p, struct mulle_allocator *allocator);
Returns 0/nil. Useful in .retain.
uintptr_t mulle_container_keycallback_pointer_hash( struct mulle_container_keycallback *callback, void *p);
Create a hash value from p
directly (using mulle_pointer_hash
).
int mulle_container_keycallback_pointer_is_equal( struct mulle_container_keycallback *callback, void *a, void *b);
Compare for pointer equality (a == b
)
void _mulle_container_keycallback_pointer_free( struct mulle_container_keycallback *callback, void *p, struct mulle_allocator *allocator);
Free p
using allocator
(mulle_allocator_free( allocator, p)
)
void mulle_container_valuecallback_pointer_free( struct mulle_container_keycallback *callback, void *p, struct mulle_allocator *allocator);
Free p
using allocator
(mulle_allocator_free( allocator, p)
)
A selection of callbacks has been predefined for convenience
All the following globals are of type struct mulle_container_keycallback
.
Keys are int. All values are possible except mulle_not_an_int
.
Keys are intptr_t. All values are possible except mulle_not_an_intptr
.
Keys are char *
. All values are possible except NULL. The key is copied by the container and will be freed eventually.
Keys are char *
. All values are possible except NULL. The key is NOT copied by the container. The caller needs to make sure, that the c-string sticks around.
Keys are char *
. All values are possible except NULL. The key is then owned by the container and will be freed eventually.
Keys are void *
. All values are possible except NULL.
Keys are void *
. All values are possible except NULL. The key is then owned by the container and will be freed eventually.
Keys are void *
. All values are possible except mulle_container_not_a_pointer_key
.
Keys are void *
. All values are possible except mulle_container_not_a_pointer_key
. The key is then owned by the container and will be freed by the container, when it is not used anymore.
All the following globals are of type struct mulle_container_valuecallback
.
Values are int.
Values are intptr_t.
Values are char *
. The value is copied by the container and will be freed eventually.
Values are char *
. The value is not copied by the container, but will be freed eventually.
Values are char *
.
Values are void *
.
Values are void *
. The value will be freed eventually.