LibCapy - dict

Generic dictionary (implemented as a hash table).

Macros:

Iterator for generic dict structure. Declaration macro for an iterator structure named 'name' ## Iterator, associated to a dict named 'name'

Create an iterator on a generic dictionary

Input argument(s):

dict: the generic dict on which to iterate

Output and side effect(s):

Return the iterator

Allocate memory and create an iterator on a generic dict

Input argument(s):

dict: the dictionary on which to iterate

Output and side effect(s):

Return the iterator

Free the memory used by an iterator.

Input argument(s):

that: the iterator to free

Free the memory used by a pointer to an iterator and reset '*that' to NULL

Input argument(s):

that: a pointer to the iterator to free

Reset the iterator

Output and side effect(s):

Return the first element of the iteration

Move the iterator to the next element

Output and side effect(s):

Return the next element of the iteration

Check if the iterator is on a valid element

Output and side effect(s):

Return true if the iterator is on a valid element, else false

Get the current element of the iteration

Output and side effect(s):

Return a pointer to the current element

Definition macro calling all the submacros at once for an iterator on an dictionary structure named 'name'

Generic dict structure. Declaration macro for a dict structure named 'name', containing entries with keys of type 'char*' and values of type 'type'

Generic dict structure. Definition macro for a dict structure named 'name', containing entries with keys of type 'char*' and values of type 'type' Create a dictionary

Input argument(s):

sizeHash: size of the hash table
defaultVal: default value returned by 'get' for an unknown key

Output and side effect(s):

Return an empty dictionary containing elements of type 'type'

Allocate memory for a new dictionary and create it

Input argument(s):

sizeHash: size of the hash table
defaultVal: default value returned by 'get' for an unknown key

Output and side effect(s):

Return a dictionary containing elements of type 'type'

Exception(s):

May raise CapyExc_MallocFailed.

Clone a dictionary

Output and side effect(s):

Return a clone of the dictionary

Exception(s):

May raise CapyExc_MallocFailed.

Free the memory used by a dictionary. The memory eventually used by the value of the entries must be freed by the user. The key of the entries are automatically freed.

Input argument(s):

that: the dictionary to free

Free the memory used by a pointer to a dictionary and reset '*that' to NULL. The memory eventually used by the value of the entries must be freed by the user. The key of the entries are automatically freed.

Input argument(s):

that: a pointer to the dictionary to free

Get the number of entries in the dictionary

Output and side effect(s):

Return the number of entries

Get the size of the hash table of the dictionary

Output and side effect(s):

Return the size of the hash

Get a value of the dictionary

Input argument(s):

key: the key of the element to get

Output and side effect(s):

Return the value

Exception(s):

May raise CapyExc_MallocFailed.

Get a pointer to a value of the dictionary

Input argument(s):

key: the key of the element to get, if there is no element for this key, create a new one initialised with the default value

Output and side effect(s):

Return the pointer to the element

Remove an entry from the dictionary

Input argument(s):

key: the key of the element to remove

Output and side effect(s):

The entry is removed if it exists, else nothing is done. The user is responsible for freeing the memory used by the entry value if any.

Set a value of the dictionary

Input argument(s):

key: the key of the entry to set
val: the value to set

Exception(s):

May raise CapyExc_MallocFailed.

Initialise the iterator of the dictionary, must be called after the creation of the dictionary when it is created with Create(), Alloc() automatically initialise the iterator.

Set the default value used when an entry is automatically added

Input argument(s):

val: the default value

Check if a key exists in the dictionary

Input argument(s):

key: the key to check

Output and side effect(s):

Return true if the key exists, else false

Set the hash function

Input argument(s):

hash: the hash function

Definition macro calling all the submacros at once for a dictionary structure named 'name', containing elements of type 'type'

Enumerations:

None.

Typedefs:

None.

Functions:

None.

2021-12-23
in LibCapy,
85 views
Copyright 2021-2024 Baillehache Pascal