data FEATURE add lyd_list_pos() function
diff --git a/src/tree_data.c b/src/tree_data.c
index e3693fb..ef44019 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -3367,3 +3367,25 @@
lyxp_expr_free((struct ly_ctx *)LYD_CTX(ctx_node), exp);
return ret;
}
+
+API uint32_t
+lyd_list_pos(const struct lyd_node *instance)
+{
+ const struct lyd_node *iter = NULL;
+ uint32_t pos = 0;
+
+ if (!instance || !(instance->schema->nodetype & (LYS_LIST | LYS_LEAFLIST))) {
+ return 0;
+ }
+
+ /* data instances are ordered, so we can stop when we found instance of other schema node */
+ for (iter = instance; iter->schema == instance->schema; iter = iter->prev) {
+ if (pos && iter->next == NULL) {
+ /* overrun to the end of the siblings list */
+ break;
+ }
+ ++pos;
+ }
+
+ return pos;
+}