<commit_before>/**
 * @file  pqueue.cpp
 *
 * @brief Priority queue source.
 */

#include <stdlib.h>
#include <assert.h>

#include "pqueue.h"

/**
 * @brief Constructor.
 */
pqueue::pqueue()
{
    p_llist = new llist;

    num_items = 0;
}

/**
 * @brief Destructor.
 */
pqueue::~pqueue()
{
    delete p_llist;
}

/**
 * @brief Enqueue value in ascending order.
 *
 * @param[in] value: Value.
 */
void pqueue::enqueue(int value)
{
    struct llist_node *p_node;

    p_node = p_llist->p_head;

    while (p_node != NULL)
    {
        if (value < p_node->value)
        {
            break;
        }

        p_node = p_node->p_next;
    }

    if (p_node == NULL)
    {
        p_llist->add_tail(value);
    }
    else
    {
        p_llist->add_before(p_node, value);
    }

    num_items++;
}

/**
 * @brief Dequeue value.
 *
 * @retval Value at head of priority queue.
 */
int pqueue::dequeue()
{
    int value;

    assert(num_items > 0);

    value = p_llist->p_head->value;

    p_llist->delete_head();

    return value;
}

/**
 * @brief Is queue empty?<commit_msg>Fix bug in priority queue dequeue() function.<commit_after>/**
 * @file  pqueue.cpp
 *
 * @brief Priority queue source.
 */

#include <stdlib.h>
#include <assert.h>

#include "pqueue.h"

/**
 * @brief Constructor.
 */
pqueue::pqueue()
{
    p_llist = new llist;

    num_items = 0;
}

/**
 * @brief Destructor.
 */
pqueue::~pqueue()
{
    delete p_llist;
}

/**
 * @brief Enqueue value in ascending order.
 *
 * @param[in] value: Value.
 */
void pqueue::enqueue(int value)
{
    struct llist_node *p_node;

    p_node = p_llist->p_head;

    while (p_node != NULL)
    {
        if (value < p_node->value)
        {
            break;
        }

        p_node = p_node->p_next;
    }

    if (p_node == NULL)
    {
        p_llist->add_tail(value);
    }
    else
    {
        p_llist->add_before(p_node, value);
    }

    num_items++;
}

/**
 * @brief Dequeue value.
 *
 * @retval Value at head of priority queue.
 */
int pqueue::dequeue()
{
    int value;

    assert(num_items > 0);

    value = p_llist->p_head->value;

    p_llist->delete_head();

    num_items--;

    return value;
}

/**
 * @brief Is queue empty?
{'fraction_non_alphanumeric': 0.1565059144676979, 'fraction_numerical': 0.0018198362147406734, 'mean_word_length': 2.196220930232558, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '5345656', 'n_tokens_mistral': 870, 'n_tokens_neox': 836, 'n_words': 176}