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

#include "array_int.h"


void array_int_init(struct array_int *ai, int n)
{
  ai->count = 0;
  ai->elements = 0;
  ai->array = malloc(n * sizeof(int));
}

void array_int_reset(struct array_int *ai)
{
  ai->count = 0;
  ai->elements = 0;
}

void array_int_add(struct array_int *ai, int i)
{
  (ai->array)[ai->count++] = i;
  (ai->elements)++;
}

void array_int_remove(struct array_int *ai, int i)
{
  assert(ai->count > i);

  (ai->array)[i] = -1;
  (ai->elements)--;
}

int array_int_contains(struct array_int *ai, int i)
{
  assert(ai->count > i);

  return (ai->array)[i] != -1;
}

int array_int_get(struct array_int *ai, int i)
{
  assert((ai->array)[i] > -1);
  assert(ai->count > i);

  return (ai->array)[i];
}

void array_int_delete(struct array_int *ai)
{
  free(ai->array);
}
