]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[list] Add get Nth node function
authorCharlie Brej <cbrej@cs.man.ac.uk>
Sat, 28 Nov 2009 23:31:11 +0000 (23:31 +0000)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Sat, 28 Nov 2009 23:31:11 +0000 (23:31 +0000)
Gets the Nth node in the list. If the index is outside the range, it will
return NULL

src/libply/ply-list.c
src/libply/ply-list.h

index b5806b1f451d8276069a2cfcf4630e345936a97c..32d65d91878e2ca0a24d2197fe8667099fcd5116 100644 (file)
@@ -264,6 +264,22 @@ ply_list_get_last_node (ply_list_t *list)
   return list->last_node;
 }
 
+ply_list_node_t *
+ply_list_get_nth_node (ply_list_t *list,
+                       int         index)
+{
+  ply_list_node_t *node;
+  if (index < 0)
+    return NULL;
+  if (index >= list->number_of_nodes)
+    return NULL;
+  while (index--)
+    {
+      node = node->next;
+    }
+  return node;
+}
+
 ply_list_node_t *
 ply_list_get_next_node (ply_list_t     *list,
                        ply_list_node_t *node)
index ce75b7cd24fd75405e7070af983b91fedf6ce33f..65739c4107d8e521c90038d7d19e6e6c5494fa1b 100644 (file)
@@ -50,7 +50,9 @@ void ply_list_sort_stable (ply_list_t              *list,
                            ply_list_compare_func_t *compare);
 ply_list_node_t *ply_list_get_first_node (ply_list_t *list);
 ply_list_node_t *ply_list_get_last_node (ply_list_t *list);
-ply_list_node_t *ply_list_get_next_node (ply_list_t  *list,
+ply_list_node_t *ply_list_get_nth_node (ply_list_t *list,
+                                        int         index);
+ply_list_node_t *ply_list_get_next_node (ply_list_t      *list,
                                          ply_list_node_t *node);
 void *ply_list_node_get_data (ply_list_node_t *node);
 void ply_list_node_set_data (ply_list_node_t *node, void *data);