summaryrefslogtreecommitdiff
path: root/lib/radix-tree.c
diff options
context:
space:
mode:
authorVinayak Menon <vinmenon@codeaurora.org>2015-07-20 10:53:19 +0530
committerDavid Keitel <dkeitel@codeaurora.org>2016-03-23 21:15:18 -0700
commit6fe144923f51af53706f5f9b12944b241b56148d (patch)
tree29a11675a18dc3df9595f8141a9dd8dc026afd33 /lib/radix-tree.c
parent347c419ead855663663b37da444ce0c7ad3de1aa (diff)
radix-tree: add radix_tree_gang_lookup_index
Add radix_tree_gang_lookup_index to get the radix tree indices along with the pointers. This will be helpful, for e.g. if a radix_tree_delete has to be performed depending on one of the result values. Change-Id: Iab83d027968462aa30da5341fa3f60134b6c1137 Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
Diffstat (limited to 'lib/radix-tree.c')
-rw-r--r--lib/radix-tree.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 6b79e9026e24..534878e6cf11 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1035,6 +1035,49 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
EXPORT_SYMBOL(radix_tree_gang_lookup);
/**
+ * radix_tree_gang_lookup_index - perform multiple lookup on a radix tree
+ * @root: radix tree root
+ * @results: where the results of the lookup are placed
+ * @indices: where their indices should be placed
+ * @first_index: start the lookup from this key
+ * @max_items: place up to this many items at *results
+ *
+ * Performs an index-ascending scan of the tree for present items. Places
+ * them at *@results and returns the number of items which were placed at
+ * *@results. The indices are placed in @indices.
+ *
+ * The implementation is naive.
+ *
+ * Just one difference from radix_tree_gang_lookup, the indices are also
+ * collected along with the results of lookup.
+ */
+unsigned int
+radix_tree_gang_lookup_index(struct radix_tree_root *root, void **results,
+ unsigned long *indices, unsigned long first_index,
+ unsigned int max_items)
+{
+ struct radix_tree_iter iter;
+ void **slot;
+ unsigned int ret = 0;
+
+ if (unlikely(!max_items))
+ return 0;
+
+ radix_tree_for_each_slot(slot, root, &iter, first_index) {
+ results[ret] = indirect_to_ptr(rcu_dereference_raw(*slot));
+ if (!results[ret])
+ continue;
+ if (indices)
+ indices[ret] = iter.index;
+ if (++ret == max_items)
+ break;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(radix_tree_gang_lookup_index);
+
+/**
* radix_tree_gang_lookup_slot - perform multiple slot lookup on radix tree
* @root: radix tree root
* @results: where the results of the lookup are placed