Browse Source

Add functions for iterating a list from the end

Samuel Thibault 8 years ago
parent
commit
0540b09a19
1 changed files with 21 additions and 1 deletions
  1. 21 1
      src/common/list.h

+ 21 - 1
src/common/list.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2012, 2015-2016  Université de Bordeaux
+ * Copyright (C) 2009-2012, 2015-2017  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2016  CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -73,6 +73,12 @@
  *   struct FOO*	FOO_list_end(struct FOO_list*);
  *     * retourne l'élément suivant de la liste
  *   struct FOO*	FOO_list_next(struct FOO*)
+ *     * retourne le dernier élément de la liste
+ *   struct FOO*	FOO_list_last(struct FOO_list*);
+ *     * retourne la valeur à tester en début de liste
+ *   struct FOO*	FOO_list_first(struct FOO_list*);
+ *     * retourne l'élément précédent de la liste
+ *   struct FOO*	FOO_list_prev(struct FOO*)
  *     * retourne la taille de la liste
  *   int		FOO_list_size(struct FOO_list*)
  *     * retourne la position de l'élément dans la liste (indexé à partir de 0)
@@ -108,6 +114,14 @@
  *  {
  *    printf("a=%d; b=%d\n", i->a, i->b);
  *  }
+ *  - itérateur de liste :
+ *  struct ma_structure * i;
+ *  for(i  = ma_structure_list_last(l);
+ *      i != ma_structure_list_alpha(l);
+ *      i  = ma_structure_list_prev(i))
+ *  {
+ *    printf("a=%d; b=%d\n", i->a, i->b);
+ *  }
  * *********************************************************
  */
 
@@ -185,6 +199,12 @@
     { return NULL; } \
   /** @internal */static inline struct ENAME *ENAME##_list_next(const struct ENAME *i) \
     { return i->_next; } \
+  /** @internal */static inline struct ENAME *ENAME##_list_last(const struct ENAME##_list *l) \
+    { return l->_tail; } \
+  /** @internal */static inline struct ENAME *ENAME##_list_alpha(const struct ENAME##_list *l STARPU_ATTRIBUTE_UNUSED) \
+    { return NULL; } \
+  /** @internal */static inline struct ENAME *ENAME##_list_prev(const struct ENAME *i) \
+    { return i->_prev; } \
   /** @internal */static inline int ENAME##_list_ismember(const struct ENAME##_list *l, const struct ENAME *e) \
     { struct ENAME *i=l->_head; while(i!=NULL){ if (i == e) return 1; i=i->_next; } return 0; } \
   /** @internal */static inline int ENAME##_list_member(const struct ENAME##_list *l, const struct ENAME *e) \