Add DICT_*_AS macros.

This commit is contained in:
Patrick Pelissier committed 2020-10-15 22:05:18 +02:00
1 parent 0e9af6dfac
commit a23df528e4
2 files changed
+84

No files matched your search

+76
View File
@@ -44,6 +44,21 @@
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
/* Define a dictionary associating the key key_type to the value value_type and its associated functions.
as the given name name_t with its associated functions.
USAGE:
DICT_DEF2_AS(name, name_t, it_t, itref_t, key_type, key_oplist, value_type, value_oplist)
OR
DICT_DEF2_AS(name, name_t, it_t, itref_t, key_type, value_type)
*/
#define DICT_DEF2_AS(name, name_it, it_t, itref_t, key_type, ...) \
M_BEGIN_PROTECTED_CODE \
DICTI_DEF2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, itref_t ), \
(name, key_type, __VA_ARGS__, name_t, it_t, itref_t ) )) \
M_END_PROTECTED_CODE
/* Define a dictionary asssociating the key key_type to the value value_type and its associated functions. /* Define a dictionary asssociating the key key_type to the value value_type and its associated functions.
It stores the computed hash value, avoiding the need of recomputing it but increasing memory It stores the computed hash value, avoiding the need of recomputing it but increasing memory
consumption. consumption.
@@ -60,6 +75,23 @@
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
/* Define a dictionary asssociating the key key_type to the value value_type and its associated functions.
as the given name name_t with its associated functions.
It stores the computed hash value, avoiding the need of recomputing it but increasing memory
consumption.
USAGE:
DICT_STOREHASH_DEF2_AS(name, name_it, it_t, itref_t, key_type[, key_oplist], value_type[, value_oplist])
OR
DICT_STOREHASH_DEF2_AS(name, name_it, it_t, itref_t, key_type[, key_oplist], value_type[, value_oplist])
*/
#define DICT_STOREHASH_DEF2_AS(name, name_it, it_t, itref_t, key_type, ...) \
M_BEGIN_PROTECTED_CODE \
DICTI_SHASH_DEF2_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_it, it_t, itref_t ), \
(name, key_type, __VA_ARGS__, name_it, it_t, itref_t ))) \
M_END_PROTECTED_CODE
/* Define a dictionary associating the key key_type to the value value_type /* Define a dictionary associating the key key_type to the value value_type
with an Open Addressing implementation and its associated functions. with an Open Addressing implementation and its associated functions.
KEY_OPLIST needs the operators OOR_EQUAL & OOR_SET. KEY_OPLIST needs the operators OOR_EQUAL & OOR_SET.
@@ -76,6 +108,23 @@
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
/* Define a dictionary associating the key key_type to the value value_type
with an Open Addressing implementation and its associated functions.
as the given name name_t with its associated functions.
KEY_OPLIST needs the operators OOR_EQUAL & OOR_SET.
USAGE:
DICT_OA_DEF2_AS(name, name_it, it_t, itref_t, key_type, key_oplist, value_type, value_oplist)
OR
DICT_OA_DEF2_AS(name, name_it, it_t, itref_t, key_type, value_type)
*/
#define DICT_OA_DEF2_AS(name, name_it, it_t, itref_t, key_type, ...) \
M_BEGIN_PROTECTED_CODE \
DICTI_OA_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_it, it_t, itref_t ), \
(name, key_type, __VA_ARGS__, name_it, it_t, itref_t ))) \
M_END_PROTECTED_CODE
/* Define a set of the key key_type and its associated functions. /* Define a set of the key key_type and its associated functions.
The set is unordered. The set is unordered.
USAGE: DICT_SET_DEF(name, key_type[, key_oplist]) USAGE: DICT_SET_DEF(name, key_type[, key_oplist])
@@ -88,6 +137,19 @@
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
/* Define a set of the key key_type and its associated functions.
as the given name name_t with its associated functions.
The set is unordered.
USAGE: DICT_SET_DEF_AS(name, name_it, it_t, itref_t, key_type[, key_oplist])
*/
#define DICT_SET_DEF_AS(name, name_it, it_t, itref_t, ...) \
M_BEGIN_PROTECTED_CODE \
DICTI_SET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_it, it_t, itref_t ), \
(name, __VA_ARGS__, name_it, it_t, itref_t ))) \
M_END_PROTECTED_CODE
/* Define a set of the key key_type /* Define a set of the key key_type
with an Open Addressing implementation and its associated functions. with an Open Addressing implementation and its associated functions.
The set is unordered. The set is unordered.
@@ -101,6 +163,20 @@
M_END_PROTECTED_CODE M_END_PROTECTED_CODE
/* Define a set of the key key_type
with an Open Addressing implementation and its associated functions.
as the given name name_t with its associated functions.
The set is unordered.
USAGE: DICT_OASET_DEF_AS(name, name_it, it_t, itref_t, key_type[, key_oplist])
*/
#define DICT_OASET_DEF_AS(name, name_it, it_t, itref_t, ...) \
M_BEGIN_PROTECTED_CODE \
DICTI_OASET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_it, it_t, itref_t ), \
(name, __VA_ARGS__, name_it, it_t, itref_t ))) \
M_END_PROTECTED_CODE
/* Define the oplist of a dictionnary (DICT_DEF2, DICT_STOREHASH_DEF2 or DICT_OA_DEF2). /* Define the oplist of a dictionnary (DICT_DEF2, DICT_STOREHASH_DEF2 or DICT_OA_DEF2).
USAGE: USAGE:
DICT_OPLIST(name, oplist of the key type, oplist of the value type) DICT_OPLIST(name, oplist of the key type, oplist of the value type)
+8
View File
@@ -48,6 +48,14 @@ DICT_OA_DEF2(dict_oa_str, symbol_t, BOUNDED_STRING_OPLIST(symbol), int, M_DEFAUL
DICT_OA_DEF2(dict_oa_bstr, string_t, STRING_OPLIST, int, M_DEFAULT_OPLIST) DICT_OA_DEF2(dict_oa_bstr, string_t, STRING_OPLIST, int, M_DEFAULT_OPLIST)
DICT_OASET_DEF(dict_oa_setstr, string_t, STRING_OPLIST) DICT_OASET_DEF(dict_oa_setstr, string_t, STRING_OPLIST)
DICT_DEF2_AS(dictas_int, DictInt, DictIntIt, DictIntItRef, int, M_DEFAULT_OPLIST, int, M_DEFAULT_OPLIST)
DICT_STOREHASH_DEF2_AS(dictas_str2, DictSInt, DictSIntIt, DictSIntItRef, string_t, STRING_OPLIST, string_t, STRING_OPLIST)
DICT_SET_DEF_AS(dictas_setstr, DictStr, DictStrIt, DictStrItRef, string_t, STRING_OPLIST)
DICT_OA_DEF2_AS(dictas_oa_bstr, DictOAStr, DictOAStrIt, DictOAStrItRef, string_t, STRING_OPLIST, int, M_DEFAULT_OPLIST)
DICT_OASET_DEF_AS(dictas_oa_setstr, DictOASStr, DictOASStrIt, DictOASStrItRef, string_t, STRING_OPLIST)
/* Helper structure */ /* Helper structure */
ARRAY_DEF(array_string, string_t, STRING_OPLIST) ARRAY_DEF(array_string, string_t, STRING_OPLIST)
array_string_t v_str; array_string_t v_str;