Add HASH functions for array & list

This commit is contained in:
Patrick Pelissier committed 2017-02-21 21:57:28 +01:00
1 parent 0f0cc0680d
commit ddbc001415
2 files changed
+38 -3

No files matched your search

+19 -1
View File
@@ -77,6 +77,7 @@
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C3(array_, name, _out_str)),) \
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C3(array_, name, _in_str)),) \
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C3(array_, type, _equal_p)),) \
,M_IF_METHOD(HASH, oplist)(HASH(M_C3(array_, type, _hash)),) \
)
// Compute alloc from size.
@@ -633,8 +634,25 @@
} \
, /* no equal */ ) \
\
M_IF_METHOD(HASH, oplist)( \
static inline size_t \
M_C3(array_, name, _hash)(/*const*/ M_C3(array_, name,_t) array) \
{ \
assert (array != NULL); \
M_HASH_DECL(hash); \
M_C3(array_it_, name, _t) it; \
for(M_C3(array_, name, _it)(it, array) ; \
!M_C3(array_, name, _end_p)(it); \
M_C3(array_, name, _next)(it)) { \
const type *item = M_C3(array_, name, _cref)(it); \
size_t hi = M_GET_HASH oplist (*item); \
M_HASH_UP(hash, hi); \
} \
return hash; \
} \
, /* no hash */ ) \
\
// TODO: Conditional HASH if HASH is present
// TODO: 'remove' interface is different in list & array ==> erase for iterator & pop for size_t
#endif
+19 -2
View File
@@ -76,6 +76,7 @@
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C3(list_, name, _out_str)),) \
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C3(list_, name, _in_str)),) \
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C3(list_, name, _equal_p)),) \
,M_IF_METHOD(HASH, oplist)(HASH(M_C3(list_, type, _hash)),) \
)
#define LISTI_DEF2(name, type, oplist) \
@@ -553,7 +554,23 @@
} \
, /* no equal */ ) \
\
M_IF_METHOD(HASH, oplist)( \
static inline size_t \
M_C3(list_, name, _hash)(/*const*/ M_C3(list_, name,_t) list) \
{ \
assert (list != NULL); \
M_HASH_DECL(hash); \
M_C3(list_it_, name, _t) it; \
for(M_C3(list_, name, _it)(it, list) ; \
!M_C3(list_, name, _end_p)(it); \
M_C3(list_, name, _next)(it)) { \
const type *item = M_C3(list_, name, _cref)(it); \
size_t hi = M_GET_HASH oplist (*item); \
M_HASH_UP(hash, hi); \
} \
return hash; \
} \
, /* no hash */ ) \
\
// TODO: Conditional HASH if HASH is present
#endif