<commit_before>/* EINA - EFL data type library
 * Copyright (C) 2002-2008 <NAME>, <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_LIST_H_
#define EINA_LIST_H_

#include <stdlib.h>

#include "eina_config.h"

#include "eina_types.h"
#include "eina_iterator.h"
#include "eina_accessor.h"
#include "eina_magic.h"

/**
 * @addtogroup Eina_Data_Types_Group Data Types
 *
 * @{
 */

/**
 * @addtogroup Eina_Containers_Group Containers
 *
 * @{
 */

/**
 * @defgroup Eina_List_Group List
 *
 * @{
 */

/**
 * @typedef Eina_List
 * Type for a generic single linked list.
 */
typedef struct _Eina_List Eina_List;

typedef struct _Eina_List_Accounting Eina_List_Accounting;

/**
 * @struct _Eina_List
 * Type for a generic single linked list.
 */
struct _Eina_List /** A linked list node */
{
   EINA_MAGIC;

   void      *data; /**< Pointer to list element payload */
   Eina_List *next; /**< Next member in the list */
   Eina_List *prev; /**< Previous member in the list */
   struct _Eina_List_Accounting *accounting; /**< Private list accounting info - don't touch */
};

struct _Eina_List_Accounting
{
   EINA_MAGIC;

   Eina_List *last;
   unsigned int count;
};


EAPI int eina_list_init(void);
EAPI int eina_list_shutdown(void);

EAPI Eina_List *eina_list_append (Eina_List *list, const void *data);
EAPI Eina_List *eina_list_prepend (Eina_List *list, const void *data);
EAPI Eina_List *eina_list_append_relative (Eina_List *list, const void *data, const void *relative);
EAPI Eina_List *eina_list_append_relative_list (Eina_List *list, const void *data, Eina_List *relative);
EAPI Eina_List *eina_list_prepend_relative (Eina_List *list, const void *data, const void *relative);
EAPI Eina_List *eina_list_prepend_relative_list (Eina_List *list, const void *data, Eina_List *relative);
EAPI Eina_List *eina_list_remove (Eina_List *list, const void *data);
EAPI Eina_List *eina_list_remove_list (Eina_List *list, Eina_List *remove_list);
EAPI Eina_List *eina_list_promote_list (Eina_List *list, Eina_List *move_list);
EAPI void *eina_list_data_find(const Eina_List *list, const void *data);
EAPI Eina_List *eina_list_data_find_list (const Eina_List *list, const void *data);
EAPI Eina_List *eina_list_free (Eina_List *list);
EAPI void *eina_list_nth(const Eina_List *list, unsigned int n);
EAPI Eina_List *eina_list_nth_list (const Eina_List *list, unsigned int n);
EAPI Eina_List *eina_list_reverse (Eina_List *list);
EAPI Eina_List *eina_list_sort (Eina_List *list, unsigned int size, Eina_Compare_Cb func);
EAPI Eina_List *eina_list_merge (Eina_List *left, Eina_List *right);
EAPI Eina_List *eina_list_sorted_merge(Eina_List *left, Eina_List *right, Eina_Compare_Cb func);


static inline Eina_List *eina_list_last (const Eina_List *list);
static inline Eina_List *eina_list_next (const Eina_List *list);
static inline Eina_List *eina_list_prev (const Eina_List *list);
static inline void *eina_list_data_get(const Eina_List *list);
static inline unsigned int eina_list_count(const Eina_List *list);

EAPI Eina_Iterator *eina_list_iterator_new(const Eina_List *list);
EAPI Eina_Accessor *eina_list_accessor_new(const Eina_List *list);

/**
 * @def EINA_LIST_FOREACH
 * @brief Macro to iterate over a list easily.
 *
 * @param list The list to iterate over.
 * @param l A list that is used as loop index.
 * @param data The data.
 *
 * This macro allow the iteration over @p list in an easy way. It
 * iterates from the first element to the last one. @p data is the
 * data of each element of the list. @p l is an #Eina_List that is
 * used as counter.
 *
 * This macro can be used for freeing the data of alist, like in
 * the following example:
 *
 * @code
 * Eina_List *list;
 * Eina_List *l;
 * char       *data;
 *
 * // list is already filled,
 * // its elements are just duplicated strings,
 * // EINA_LIST_FOREACH will be used to free those strings
 *
 * EINA_LIST_FOREACH(list, l, data)
 *   free(data);
 * @endcode
 */
#define EINA_LIST_FOREACH(list, l, data) for (l = list, data = eina_list_data_get(l); l; l = eina_list_next(l), data = eina_list_data_get(l))

#include "eina_inline_list.x"

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */

#endif /* EINA_LIST_H_ */<commit_msg>Add safe Eina list walk function.<commit_after>/* EINA - EFL data type library
 * Copyright (C) 2002-2008 <NAME>, <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_LIST_H_
#define EINA_LIST_H_

#include <stdlib.h>

#include "eina_config.h"

#include "eina_types.h"
#include "eina_iterator.h"
#include "eina_accessor.h"
#include "eina_magic.h"

/**
 * @addtogroup Eina_Data_Types_Group Data Types
 *
 * @{
 */

/**
 * @addtogroup Eina_Containers_Group Containers
 *
 * @{
 */

/**
 * @defgroup Eina_List_Group List
 *
 * @{
 */

/**
 * @typedef Eina_List
 * Type for a generic single linked list.
 */
typedef struct _Eina_List Eina_List;

typedef struct _Eina_List_Accounting Eina_List_Accounting;

/**
 * @struct _Eina_List
 * Type for a generic single linked list.
 */
struct _Eina_List /** A linked list node */
{
   EINA_MAGIC;

   void      *data; /**< Pointer to list element payload */
   Eina_List *next; /**< Next member in the list */
   Eina_List *prev; /**< Previous member in the list */
   struct _Eina_List_Accounting *accounting; /**< Private list accounting info - don't touch */
};

struct _Eina_List_Accounting
{
   EINA_MAGIC;

   Eina_List *last;
   unsigned int count;
};


EAPI int eina_list_init(void);
EAPI int eina_list_shutdown(void);

EAPI Eina_List *eina_list_append (Eina_List *list, const void *data);
EAPI Eina_List *eina_list_prepend (Eina_List *list, const void *data);
EAPI Eina_List *eina_list_append_relative (Eina_List *list, const void *data, const void *relative);
EAPI Eina_List *eina_list_append_relative_list (Eina_List *list, const void *data, Eina_List *relative);
EAPI Eina_List *eina_list_prepend_relative (Eina_List *list, const void *data, const void *relative);
EAPI Eina_List *eina_list_prepend_relative_list (Eina_List *list, const void *data, Eina_List *relative);
EAPI Eina_List *eina_list_remove (Eina_List *list, const void *data);
EAPI Eina_List *eina_list_remove_list (Eina_List *list, Eina_List *remove_list);
EAPI Eina_List *eina_list_promote_list (Eina_List *list, Eina_List *move_list);
EAPI void *eina_list_data_find(const Eina_List *list, const void *data);
EAPI Eina_List *eina_list_data_find_list (const Eina_List *list, const void *data);
EAPI Eina_List *eina_list_free (Eina_List *list);
EAPI void *eina_list_nth(const Eina_List *list, unsigned int n);
EAPI Eina_List *eina_list_nth_list (const Eina_List *list, unsigned int n);
EAPI Eina_List *eina_list_reverse (Eina_List *list);
EAPI Eina_List *eina_list_sort (Eina_List *list, unsigned int size, Eina_Compare_Cb func);
EAPI Eina_List *eina_list_merge (Eina_List *left, Eina_List *right);
EAPI Eina_List *eina_list_sorted_merge(Eina_List *left, Eina_List *right, Eina_Compare_Cb func);


static inline Eina_List *eina_list_last (const Eina_List *list);
static inline Eina_List *eina_list_next (const Eina_List *list);
static inline Eina_List *eina_list_prev (const Eina_List *list);
static inline void *eina_list_data_get(const Eina_List *list);
static inline unsigned int eina_list_count(const Eina_List *list);

EAPI Eina_Iterator *eina_list_iterator_new(const Eina_List *list);
EAPI Eina_Accessor *eina_list_accessor_new(const Eina_List *list);

/**
 * @def EINA_LIST_FOREACH
 * @brief Macro to iterate over a list easily.
 *
 * @param list The list to iterate over.
 * @param l A list that is used as loop index.
 * @param data The data.
 *
 * This macro allow the iteration over @p list in an easy way. It
 * iterates from the first element to the last one. @p data is the
 * data of each element of the list. @p l is an #Eina_List that is
 * used as counter.
 *
 * This macro can be used for freeing the data of alist, like in
 * the following example:
 *
 * @code
 * Eina_List *list;
 * Eina_List *l;
 * char       *data;
 *
 * // list is already filled,
 * // its elements are just duplicated strings,
 * // EINA_LIST_FOREACH will be used to free those strings
 *
 * EINA_LIST_FOREACH(list, l, data)
 *   free(data);
 * @endcode
 *
 * @warning do not delete list nodes, specially the current node, while
 *          iterating. If you wish to do so, use EINA_LIST_FOREACH_SAFE().
 */
#define EINA_LIST_FOREACH(list, l, data) for (l = list, data = eina_list_data_get(l); l; l = eina_list_next(l), data = eina_list_data_get(l))

/**
 * @def EINA_LIST_FOREACH_SAFE
 * @brief Macro to iterate over a list easily, supporting deletion.
 *
 * @param list The list to iterate over.
 * @param l A list that is used as loop index.
 * @param l_next A second list that is used as loop next index.
 * @param data The data.
 *
 * This macro allow the iteration over @p list in an easy way. It
 * iterates from the first element to the last one. @p data is the
 * data of each element of the list. @p l is an #Eina_List that is
 * used as counter.
 *
 * This is the safe version, which stores the next pointer in @p l_next
 * before proceeding, so deletion of @b current node is safe. If you wish
 * to remove anything else, remember to set @p l_next accordingly.
 *
 * This macro can be used for freeing list nodes, like in
 * the following example:
 *
 * @code
 * Eina_List *list;
 * Eina_List *l;
 * Eina_List *l_next;
 * char       *data;
 *
 * // list is already filled,
 * // its elements are just duplicated strings,
 * // EINA_LIST_FOREACH_SAFE will be used to free elements that match "key".
 *
 * EINA_LIST_FOREACH_SAFE(list, l, l_next, data)
 *   if (strcmp(data, "key") == 0) {
 *      free(data);
 *      list = eina_list_remove_list(list, l);
 *   }
 * @endcode
 */
#define EINA_LIST_FOREACH_SAFE(list, l, l_next, data) for (l = list, l_next = eina_list_next(l), data = eina_list_data_get(l); l; l = l_next, l_next = eina_list_next(l), data = eina_list_data_get(l))


#include "eina_inline_list.x"

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */

#endif /* EINA_LIST_H_ */
{'fraction_non_alphanumeric': 0.09952187001947937, 'fraction_numerical': 0.0018593943686913406, 'mean_word_length': 4.41726618705036, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3675938', 'n_tokens_mistral': 4015, 'n_tokens_neox': 3921, 'n_words': 1320}