<commit_before>/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * queue.c
 *
 */

#include <stdlib.h>
#include <string.h>

#include "queue.h"
#include "util.h"

#define EXTRA_SPACE 8
#define EXTRA_SPACE_HEAD 8

void
queue_init(Queue *q)
{
  q->alloc = q->elements = 0;
  q->count = q->left = 0;
}

void
queue_init_clone(Queue *t, Queue *s)
{
  if (!s->elements)
    {
      t->alloc = t->elements = 0;
      t->count = t->left = 0;
      return;
    }
  t->alloc = t->elements = sat_malloc2(s->count + EXTRA_SPACE, sizeof(Id));
  if (s->count)
    memcpy(t->alloc, s->elements, s->count * sizeof(Id));
  t->count = s->count;
  t->left = EXTRA_SPACE;
}

void
queue_init_buffer(Queue *q, Id *buf, int size)
{
  q->alloc = 0;
  q->elements = buf;
  q->count = 0;
  q->left = size;
}

void
queue_free(Queue *q)
{
  if (q->alloc)
    sat_free(q->alloc);
  q->alloc = q->elements = 0;
  q->count = q->left = 0;
}

void
queue_alloc_one(Queue *q)
{
  if (!q->alloc)
    {
      q->alloc = sat_malloc2(q->count + EXTRA_SPACE, sizeof(Id));
      if (q->count)
	memcpy(q->alloc, q->elements, q->count * sizeof(Id));
      q->elements = q->alloc;
      q->left = EXTRA_SPACE;
    }
  else if (q->alloc != q->elements)
    {
      int l = q->elements - q->alloc;
      if (q->count)
        memmove(q->alloc, q->elements, q->count * sizeof(Id));
      q->elements -= l;
      q->left += l;
    }
  else
    {
      q->elements = q->alloc = sat_realloc2(q->alloc, q->count + EXTRA_SPACE, sizeof(Id));
      q->left = EXTRA_SPACE;
    }
}

/* make room for an element in front of queue */
void
queue_alloc_one_head(Queue *q)
{
  int l;
  if (!q->alloc || !q->left)
    queue_alloc_one(q);
  l = q->left > EXTRA_SPACE_HEAD ? EXTRA_SPACE_HEAD : q->left;
  if (q->count);
    memmove(q->elements + l, q->elements, q->count * sizeof(Id));
  q->elements += l;<commit_msg>- remove stray semicolon. duh<commit_after>/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * queue.c
 *
 */

#include <stdlib.h>
#include <string.h>

#include "queue.h"
#include "util.h"

#define EXTRA_SPACE 8
#define EXTRA_SPACE_HEAD 8

void
queue_init(Queue *q)
{
  q->alloc = q->elements = 0;
  q->count = q->left = 0;
}

void
queue_init_clone(Queue *t, Queue *s)
{
  if (!s->elements)
    {
      t->alloc = t->elements = 0;
      t->count = t->left = 0;
      return;
    }
  t->alloc = t->elements = sat_malloc2(s->count + EXTRA_SPACE, sizeof(Id));
  if (s->count)
    memcpy(t->alloc, s->elements, s->count * sizeof(Id));
  t->count = s->count;
  t->left = EXTRA_SPACE;
}

void
queue_init_buffer(Queue *q, Id *buf, int size)
{
  q->alloc = 0;
  q->elements = buf;
  q->count = 0;
  q->left = size;
}

void
queue_free(Queue *q)
{
  if (q->alloc)
    sat_free(q->alloc);
  q->alloc = q->elements = 0;
  q->count = q->left = 0;
}

void
queue_alloc_one(Queue *q)
{
  if (!q->alloc)
    {
      q->alloc = sat_malloc2(q->count + EXTRA_SPACE, sizeof(Id));
      if (q->count)
	memcpy(q->alloc, q->elements, q->count * sizeof(Id));
      q->elements = q->alloc;
      q->left = EXTRA_SPACE;
    }
  else if (q->alloc != q->elements)
    {
      int l = q->elements - q->alloc;
      if (q->count)
        memmove(q->alloc, q->elements, q->count * sizeof(Id));
      q->elements -= l;
      q->left += l;
    }
  else
    {
      q->elements = q->alloc = sat_realloc2(q->alloc, q->count + EXTRA_SPACE, sizeof(Id));
      q->left = EXTRA_SPACE;
    }
}

/* make room for an element in front of queue */
void
queue_alloc_one_head(Queue *q)
{
  int l;
  if (!q->alloc || !q->left)
    queue_alloc_one(q);
  l = q->left > EXTRA_SPACE_HEAD ? EXTRA_SPACE_HEAD : q->left;
  if (q->count)
    memmove(q->elements + l, q->elements, q->count * sizeof(Id));
  q->elements += l;
{'fraction_non_alphanumeric': 0.18546942952161677, 'fraction_numerical': 0.008697876694806856, 'mean_word_length': 2.692162417374882, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 135, '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': '5468302', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1556, 'n_words': 357}