<commit_before>#include "shotgun.h"
#include "heap.h"
#include <stdlib.h>
#include <string.h>

rheap heap_new(int size) {
  rheap h = (rheap)malloc(sizeof(struct heap));
  memset((void*)h, 0, sizeof(struct heap));
  h->size = size;
  heap_allocate_memory(h);
  return h;
}

int heap_deallocate(rheap h) {
  if(!heap_allocated_p(h)) {
    return FALSE;
  }
  if(h->address) {
    free((void*)(h->address));
  }
  h->size = 0;
  h->address = 0;
  h->current = 0;
  /* Maybe free() here? */
  return TRUE;
}

int heap_allocate_memory(rheap h) {
  h->address = (address)malloc(h->size);
  if(!h->address) {
    return FALSE;
  }
  h->scan = h->address;
  memset((void*)(h->address), 0, h->size);
  h->last = h->address + h->size;
  return heap_reset(h);
}

int heap_reset(rheap h) {
  h->current = h->address;
  h->scan = h->current;
  return TRUE;
}

int heap_contains_p(rheap h, address addr) {

  if(addr < h->address) return FALSE;
  if(addr >= h->address + h->size) return FALSE;
  return TRUE;
}

int heap_allocated_p(rheap h) {
  return h->address > 0;
}

address heap_allocate(rheap h, int size) {
  address addr;
  /* maybe raise exception here? */
  assert(heap_enough_space_p(h, size));
  addr = (address)h->current;
  assert(addr < h->last);
  memset((void*)addr, 0, size);
  h->current += size;
  
  return addr;
}

int heap_enough_space_p(rheap h, unsigned int size) {
  if(h->current + size > h->last) return FALSE;
  return TRUE;
}

int heap_enough_fields_p(rheap h, int fields) {
  int size;
  
  size = (HEADER_SIZE + fields) * REFSIZE;
  
  if(h->current + size > h->last) return FALSE;<commit_msg>Fix last checkin<commit_after>#include "shotgun.h"
#include "heap.h"
#include <stdlib.h>
#include <string.h>

rheap heap_new(int size) {
  rheap h = (rheap)malloc(sizeof(struct heap));
  memset((void*)h, 0, sizeof(struct heap));
  h->size = size;
  heap_allocate_memory(h);
  return h;
}

int heap_deallocate(rheap h) {
  if(!heap_allocated_p(h)) {
    return FALSE;
  }
  if(h->address) {
    free((void*)(h->address));
  }
  h->size = 0;
  h->address = 0;
  h->current = 0;
  /* Maybe free() here? */
  return TRUE;
}

int heap_allocate_memory(rheap h) {
  h->address = (address)malloc(h->size);
  if(!h->address) {
    return FALSE;
  }
  h->scan = h->address;
  memset((void*)(h->address), 0, h->size);
  h->last = h->address + h->size;
  return heap_reset(h);
}

int heap_reset(rheap h) {
  h->current = h->address;
  h->scan = h->current;
  return TRUE;
}

int heap_contains_p(rheap h, address addr) {

  if(addr < h->address) return FALSE;
  if(addr >= h->address + h->size) return FALSE;
  return TRUE;
}

int heap_allocated_p(rheap h) {
  return h->address > 0;
}

address heap_allocate(rheap h, int size) {
  address addr;
  /* maybe raise exception here? */
  assert(heap_enough_space_p(h, size));
  addr = (address)h->current;
  assert(addr < h->last);
  memset((void*)addr, 0, size);
  h->current += size;
  
  return addr;
}

int heap_enough_space_p(rheap h, int size) {
  if (size < 0) abort();
  if(h->current + size > h->last) return FALSE;
  return TRUE;
}

int heap_enough_fields_p(rheap h, int fields) {
  int size;
  
  size = (HEADER_SIZE + fields) * REFSIZE;
  
  if(h->current + size > h->last) return FALSE;
{'fraction_non_alphanumeric': 0.17195685670261943, 'fraction_numerical': 0.004622496147919877, 'mean_word_length': 3.6042553191489364, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 77, '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': '2440287', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1265, 'n_words': 294}