<commit_before>/** @file deque.c
 *  @brief A deque library.
 *
 *  Implemented as a doubly linked list, we malloc a node every time we insert
 *  a new element into the deque and free the node that wraps around the
 *  front or back element when we call <tt>deque_removeb</tt> or
 *  <tt>deque_removef</tt>.
 *
 *  @author <NAME>
 */

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

static dnode *init_node(void *elem);

void deque_init(deque *deq) {
    assert(deq != NULL);

    deq->front = NULL;
    deq->back = NULL;
    deq->len = 0;
}

void deque_clear(deque *deq) {
    dnode *dead, *node;

    assert(deq != NULL);

    node = deq->front;
    while (node != NULL) {
        dead = node;
        node = node->next;
        free(dead);
    }
    deq->len = 0;
    deq->front = NULL;
    deq->back = NULL;
}

void deque_insertb(deque *deq, void *elem) {
    dnode *new;

    assert(deq != NULL);
    assert(elem != NULL);

    new = init_node(elem);

    new->prev = deq->back;
    new->next = NULL;
    deq->back = new;
    if (deq->front == NULL)
        deq->front = new;
    else
        new->prev->next = new;
    ++(deq->len);
}

void deque_insertf(deque *deq, void *elem) {
    dnode *new;

    assert(deq != NULL);
    assert(elem != NULL);

    new = init_node(elem);

    new->next = deq->front;
    new->prev = NULL;
    deq->front = new;
    if (deq->back == NULL)
        deq->back = new;
    else
        new->next->prev = new;
    ++(deq->len);
}

void *deque_peekb(deque *deq) {
    assert(deq != NULL);

    if (deq->back != NULL)
        return NULL;
    return deq->back->elem;
}

void *deque_peekf(deque *deq) {
    assert(deq != NULL);

    if (deq->front == NULL)
        return NULL;
    return deq->front->elem;
}
<commit_msg>Fixed != that should've been an == in deque_peekb<commit_after>/** @file deque.c
 *  @brief A deque library.
 *
 *  Implemented as a doubly linked list, we malloc a node every time we insert
 *  a new element into the deque and free the node that wraps around the
 *  front or back element when we call <tt>deque_removeb</tt> or
 *  <tt>deque_removef</tt>.
 *
 *  @author <NAME>
 */

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

static dnode *init_node(void *elem);

void deque_init(deque *deq) {
    assert(deq != NULL);

    deq->front = NULL;
    deq->back = NULL;
    deq->len = 0;
}

void deque_clear(deque *deq) {
    dnode *dead, *node;

    assert(deq != NULL);

    node = deq->front;
    while (node != NULL) {
        dead = node;
        node = node->next;
        free(dead);
    }
    deq->len = 0;
    deq->front = NULL;
    deq->back = NULL;
}

void deque_insertb(deque *deq, void *elem) {
    dnode *new;

    assert(deq != NULL);
    assert(elem != NULL);

    new = init_node(elem);

    new->prev = deq->back;
    new->next = NULL;
    deq->back = new;
    if (deq->front == NULL)
        deq->front = new;
    else
        new->prev->next = new;
    ++(deq->len);
}

void deque_insertf(deque *deq, void *elem) {
    dnode *new;

    assert(deq != NULL);
    assert(elem != NULL);

    new = init_node(elem);

    new->next = deq->front;
    new->prev = NULL;
    deq->front = new;
    if (deq->back == NULL)
        deq->back = new;
    else
        new->next->prev = new;
    ++(deq->len);
}

void *deque_peekb(deque *deq) {
    assert(deq != NULL);

    if (deq->back == NULL)
        return NULL;
    return deq->back->elem;
}

void *deque_peekf(deque *deq) {
    assert(deq != NULL);

    if (deq->front == NULL)
        return NULL;
    return deq->front->elem;
}

{'fraction_non_alphanumeric': 0.16088416340235032, 'fraction_numerical': 0.001119194180190263, 'mean_word_length': 2.350515463917526, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 81, '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': '1730095', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1358, 'n_words': 350}