amdgpu/util_hash_table: Add helper function to count the number of entries in hash...
authorJan Vesely <jan.vesely@rutgers.edu>
Fri, 18 May 2018 15:36:20 +0000 (11:36 -0400)
committerJan Vesely <jan.vesely@rutgers.edu>
Fri, 25 May 2018 16:12:00 +0000 (12:12 -0400)
Analogous to the mesa commit of the same name.
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
amdgpu/util_hash_table.c
amdgpu/util_hash_table.h

index 89a8bf9b4e4e4eb34daefed197a0affe14f41621..e06d44159d9a61df33e0b01198e4daaf245182bb 100644 (file)
@@ -237,6 +237,18 @@ drm_private void util_hash_table_foreach(struct util_hash_table *ht,
        }
 }
 
+static void util_hash_table_inc(void *k, void *v, void *d)
+{
+       ++*(size_t *)d;
+}
+
+drm_private size_t util_hash_table_count(struct util_hash_table *ht)
+{
+       size_t count = 0;
+       util_hash_table_foreach(ht, util_hash_table_inc, &count);
+       return count;
+}
+
 drm_private void util_hash_table_destroy(struct util_hash_table *ht)
 {
        struct util_hash_iter iter;
index 5e295a812e17c1cadc0eadbfa06be44372262050..3ab81a122db44d30f23b3c782af13075db844c6d 100644 (file)
@@ -64,6 +64,8 @@ drm_private void util_hash_table_foreach(struct util_hash_table *ht,
                        void (*callback)(void *key, void *value, void *data),
                        void *data);
 
+drm_private size_t util_hash_table_count(struct util_hash_table *ht);
+
 drm_private void util_hash_table_destroy(struct util_hash_table *ht);
 
 #endif /* U_HASH_TABLE_H_ */