<commit_before>/**
 * @file
 * @brief TODO documentation for prioq_impl.h -- <NAME>
 *
 * @date Sep 15, 2011
 * @author <NAME>
 */

#ifndef UTIL_PRIOQ_IMPL_H_
#define UTIL_PRIOQ_IMPL_H_

#define __prioq_check(expr) \
	__extension__ ({                        \
		typeof(expr) __prioq_expr = (expr); \
		assert(__prioq_expr != NULL);       \
		__prioq_expr;                       \
	})

#define __prioq_link_safe_cast(link, type, m_link) \
	__extension__ ({ \
		struct prioq_link *__prioq_link__ = (link); \
		__prioq_link__ \
				? prioq_element(__prioq_link__, type, m_link) \
				: NULL; \
	})

static inline void prioq_enqueue_link(struct prioq_link *new_link,
		prioq_comparator_t link_comparator, struct prioq *prioq) {
	struct prioq_link *next, *found = NULL;
	int comparison = 0;

	assert(new_link && link_comparator && prioq);

	list_for_each_entry(next, &prioq->prio_list, prio_link)
	{
		if ((comparison = link_comparator(next, new_link)) <= 0) {
			found = next;
			break;
		}
	}

	// TODO May be extract the following into a non-inline function. -- Eldar
	if (!found) {
		/* All of the existing elements (if any) have higher priority. */
		list_add_tail(&new_link->prio_link, &prioq->prio_list);

	} else if (comparison <= 0) {
		/* Found a chain with lower priority. */
		list_add(&new_link->prio_link, &found->prio_link);

	} else {
		/* Found a chain with the same priority. */
		list_add_tail(&new_link->elem_link, &found->elem_link);
<commit_msg>Fix comparison sign in prioq_enqueue_link<commit_after>/**
 * @file
 * @brief TODO documentation for prioq_impl.h -- <NAME>
 *
 * @date Sep 15, 2011
 * @author <NAME>
 */

#ifndef UTIL_PRIOQ_IMPL_H_
#define UTIL_PRIOQ_IMPL_H_

#define __prioq_check(expr) \
	__extension__ ({                        \
		typeof(expr) __prioq_expr = (expr); \
		assert(__prioq_expr != NULL);       \
		__prioq_expr;                       \
	})

#define __prioq_link_safe_cast(link, type, m_link) \
	__extension__ ({ \
		struct prioq_link *__prioq_link__ = (link); \
		__prioq_link__ \
				? prioq_element(__prioq_link__, type, m_link) \
				: NULL; \
	})

static inline void prioq_enqueue_link(struct prioq_link *new_link,
		prioq_comparator_t link_comparator, struct prioq *prioq) {
	struct prioq_link *next, *found = NULL;
	int comparison = 0;

	assert(new_link && link_comparator && prioq);

	list_for_each_entry(next, &prioq->prio_list, prio_link)
	{
		if ((comparison = link_comparator(next, new_link)) <= 0) {
			found = next;
			break;
		}
	}

	// TODO May be extract the following into a non-inline function. -- Eldar
	if (!found) {
		/* All of the existing elements (if any) have higher priority. */
		list_add_tail(&new_link->prio_link, &prioq->prio_list);
		assert(list_empty(&new_link->elem_link));

	} else if (comparison < 0) {
		/* Found a chain with lower priority. */
		list_add(&new_link->prio_link, &found->prio_link);
		assert(list_empty(&new_link->elem_link));

	} else {
		/* Found a chain with the same priority. */
		list_add_tail(&new_link->elem_link, &found->elem_link);

{'fraction_non_alphanumeric': 0.1286607436656795, 'fraction_numerical': 0.005923000987166831, 'mean_word_length': 3.4640234948604993, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5286579', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1159, 'n_words': 248}