summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-07-10 14:24:46 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-07-10 14:40:42 -0400
commit662572ecfea46adc77bca43d26362ecbaddf0690 (patch)
tree2c30fec7eeebe1b698214bcf9105457e3485c477 /src/lib/eina
parentd82a14c3b0290c5be4039afa5d938a424df26f24 (diff)
eina/hash: add direct variants of list append/prepend functions
Summary: this simplifies the process of manipulating lists inside hashes with a non-copied key @feature Depends on D9205 Reviewers: cedric Reviewed By: cedric Subscribers: #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9206
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_hash.c66
-rw-r--r--src/lib/eina/eina_hash.h30
2 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/eina/eina_hash.c b/src/lib/eina/eina_hash.c
index b6465c7..92c37e1 100644
--- a/src/lib/eina/eina_hash.c
+++ b/src/lib/eina/eina_hash.c
@@ -1408,6 +1408,39 @@ eina_hash_list_append(Eina_Hash *hash, const void *key, const void *data)
1408} 1408}
1409 1409
1410EAPI void 1410EAPI void
1411eina_hash_list_direct_append(Eina_Hash *hash, const void *key, const void *data)
1412{
1413 Eina_Hash_Tuple tuple;
1414 Eina_Hash_Head *hash_head;
1415 Eina_Hash_Element *hash_element;
1416 int key_length;
1417 int key_hash;
1418
1419 EINA_SAFETY_ON_NULL_RETURN(hash);
1420 EINA_SAFETY_ON_NULL_RETURN(hash->key_hash_cb);
1421 EINA_SAFETY_ON_NULL_RETURN(key);
1422 EINA_SAFETY_ON_NULL_RETURN(data);
1423 EINA_MAGIC_CHECK_HASH(hash);
1424
1425 _eina_hash_compute(hash, key, &key_length, &key_hash);
1426
1427 tuple.key = key;
1428 tuple.key_length = key_length;
1429 tuple.data = NULL;
1430
1431 hash_element = _eina_hash_find_by_hash(hash, &tuple, key_hash, &hash_head);
1432 if (hash_element)
1433 hash_element->tuple.data = eina_list_append(hash_element->tuple.data, data);
1434 else
1435 eina_hash_add_alloc_by_hash(hash,
1436 key,
1437 key_length,
1438 0,
1439 key_hash,
1440 eina_list_append(NULL, data));
1441}
1442
1443EAPI void
1411eina_hash_list_prepend(Eina_Hash *hash, const void *key, const void *data) 1444eina_hash_list_prepend(Eina_Hash *hash, const void *key, const void *data)
1412{ 1445{
1413 Eina_Hash_Tuple tuple; 1446 Eina_Hash_Tuple tuple;
@@ -1441,6 +1474,39 @@ eina_hash_list_prepend(Eina_Hash *hash, const void *key, const void *data)
1441} 1474}
1442 1475
1443EAPI void 1476EAPI void
1477eina_hash_list_direct_prepend(Eina_Hash *hash, const void *key, const void *data)
1478{
1479 Eina_Hash_Tuple tuple;
1480 Eina_Hash_Head *hash_head;
1481 Eina_Hash_Element *hash_element;
1482 int key_length;
1483 int key_hash;
1484
1485 EINA_SAFETY_ON_NULL_RETURN(hash);
1486 EINA_SAFETY_ON_NULL_RETURN(hash->key_hash_cb);
1487 EINA_SAFETY_ON_NULL_RETURN(key);
1488 EINA_SAFETY_ON_NULL_RETURN(data);
1489 EINA_MAGIC_CHECK_HASH(hash);
1490
1491 _eina_hash_compute(hash, key, &key_length, &key_hash);
1492
1493 tuple.key = key;
1494 tuple.key_length = key_length;
1495 tuple.data = NULL;
1496
1497 hash_element = _eina_hash_find_by_hash(hash, &tuple, key_hash, &hash_head);
1498 if (hash_element)
1499 hash_element->tuple.data = eina_list_prepend(hash_element->tuple.data, data);
1500 else
1501 eina_hash_add_alloc_by_hash(hash,
1502 key,
1503 key_length,
1504 0,
1505 key_hash,
1506 eina_list_append(NULL, data));
1507}
1508
1509EAPI void
1444eina_hash_list_remove(Eina_Hash *hash, const void *key, const void *data) 1510eina_hash_list_remove(Eina_Hash *hash, const void *key, const void *data)
1445{ 1511{
1446 Eina_Hash_Tuple tuple; 1512 Eina_Hash_Tuple tuple;
diff --git a/src/lib/eina/eina_hash.h b/src/lib/eina/eina_hash.h
index 16344cf..cda625b 100644
--- a/src/lib/eina/eina_hash.h
+++ b/src/lib/eina/eina_hash.h
@@ -1036,6 +1036,21 @@ EAPI void eina_hash_foreach(const Eina_Hash *hash,
1036EAPI void eina_hash_list_append(Eina_Hash *hash, const void *key, const void *data) EINA_ARG_NONNULL(1, 2, 3); 1036EAPI void eina_hash_list_append(Eina_Hash *hash, const void *key, const void *data) EINA_ARG_NONNULL(1, 2, 3);
1037 1037
1038/** 1038/**
1039 * @brief Appends data to an #Eina_List inside a hash using eina_hash_direct_add().
1040 *
1041 * This function is identical to the sequence of calling
1042 * eina_hash_find(), eina_list_append(), eina_hash_set(),
1043 * but with one fewer required hash lookup.
1044 *
1045 * @param[in,out] hash The hash table.
1046 * @param[in] key The key associated with the data.
1047 * @param[in] data The data to append to the list.
1048 *
1049 * @since 1.23
1050 */
1051EAPI void eina_hash_list_direct_append(Eina_Hash *hash, const void *key, const void *data) EINA_ARG_NONNULL(1, 2, 3);
1052
1053/**
1039 * @brief Prepends data to an #Eina_List inside a hash. 1054 * @brief Prepends data to an #Eina_List inside a hash.
1040 * 1055 *
1041 * This function is identical to the sequence of calling 1056 * This function is identical to the sequence of calling
@@ -1051,6 +1066,21 @@ EAPI void eina_hash_list_append(Eina_Hash *hash, const void *key, const void *da
1051EAPI void eina_hash_list_prepend(Eina_Hash *hash, const void *key, const void *data) EINA_ARG_NONNULL(1, 2, 3); 1066EAPI void eina_hash_list_prepend(Eina_Hash *hash, const void *key, const void *data) EINA_ARG_NONNULL(1, 2, 3);
1052 1067
1053/** 1068/**
1069 * @brief Prepends data to an #Eina_List inside a hash using eina_hash_direct_add().
1070 *
1071 * This function is identical to the sequence of calling
1072 * eina_hash_find(), eina_list_prepend(), eina_hash_set(),
1073 * but with one fewer required hash lookup.
1074 *
1075 * @param[in,out] hash The hash table.
1076 * @param[in] key The key associated with the data.
1077 * @param[in] data The data to prepend to the list.
1078 *
1079 * @since 1.23
1080 */
1081EAPI void eina_hash_list_direct_prepend(Eina_Hash *hash, const void *key, const void *data) EINA_ARG_NONNULL(1, 2, 3);
1082
1083/**
1054 * @brief Removes data from an #Eina_List inside a hash. 1084 * @brief Removes data from an #Eina_List inside a hash.
1055 * 1085 *
1056 * This function is identical to the sequence of calling 1086 * This function is identical to the sequence of calling