<commit_before>//
//  CTArray.c
//  CTObject
//
//  Created by <NAME> on 22/10/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "CTArray.h"

CTArray * CTArrayCreate(CTAllocator * restrict alloc)
{
    CTArray * array = CTAllocatorAllocate(alloc, sizeof(CTArray));
    array->alloc = alloc;
    return array;
}

void CTArrayRelease(CTArray * restrict array)
{
	for (uint64_t i = 0; i < array->count; i++)
    {
        CTObjectRelease(array->elements[i]);
    }
	CTAllocatorDeallocate(array->alloc, array->elements);
	CTAllocatorDeallocate(array->alloc, array);
}

void CTArrayAddEntry(CTArray * restrict array, void * value, uint8_t type)
{
	CTArrayAddEntry2(array, CTObjectCreate(array->alloc, value, type));
}

void CTArrayAddEntry2(CTArray * restrict array, CTObject * restrict value)
{
    uint64_t index = array->count++;
    
	assert(array->elements = CTAllocatorReallocate(array->alloc, array->elements, sizeof(CTArray *) * array->count));
    
    array->elements[index] = value;
}

void CTArrayDeleteEntry(CTArray * restrict array, uint64_t index)
{
    if (array->count > index)
	{
		unsigned shift = 0;
        for (uint64_t i = 0; i < array->count; i++)
        {
            if (i != index)
            {
				array->elements[i - shift] = array->elements[i];
            }
            else
            {
				CTObjectRelease(array->elements[i]);
				shift = 1;
            }
        }
        array->elements = CTAllocatorReallocate(array->alloc, array->elements, sizeof(CTObject *) * --array->count);
	}
}

uint64_t CTArrayIndexOfEntry(CTArray * restrict array, CTObject * restrict value)
{
    for (uint64_t i = 0; i < array->count; i++)
    {
        if (array->elements[i] == value)
        {
            return i;
        }
    }
    return -1;
}

void CTArrayEmpty(CTArray * restrict array)
{
	for (long long i = array->count; i >= 0x0; i--)
    {
        CTArrayDeleteEntry(array, i);
    }
}

CTObject * CTArrayObjectAtIndex(CTArray * restrict array, uint64_t index)
{
	return index < array->count ? array->elements[index] : NULL;
}

uint64_t CTArrayCount(CTArray * restrict array)
{
	return array->count;
}<commit_msg>Changed CTJSON to use CTObjects instead of CTJSONObjects. CTJSONObjects are now non-existent.<commit_after>//
//  CTArray.c
//  CTObject
//
//  Created by <NAME> on 22/10/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "CTArray.h"

CTArray * CTArrayCreate(CTAllocator * restrict alloc)
{
    CTArray * array = CTAllocatorAllocate(alloc, sizeof(CTArray));
    array->alloc = alloc;
    return array;
}

void CTArrayRelease(CTArray * restrict array)
{
	for (uint64_t i = 0; i < array->count; i++)
    {
        CTObjectRelease(array->elements[i]);
    }
	CTAllocatorDeallocate(array->alloc, array->elements);
	CTAllocatorDeallocate(array->alloc, array);
}

void CTArrayAddEntry(CTArray * restrict array, void * value, uint8_t type)
{
	CTArrayAddEntry2(array, CTObjectCreate(array->alloc, value, type));
}

void CTArrayAddEntry2(CTArray * restrict array, CTObject * restrict value)
{
    uint64_t index = array->count++;
    
	assert(array->elements = CTAllocatorReallocate(array->alloc, array->elements, sizeof(CTArray *) * array->count));
    
    array->elements[index] = value;
}

void CTArrayDeleteEntry(CTArray * restrict array, uint64_t index)
{
    if (array->count > index)
	{
        for (uint64_t i = 0; i < array->count; i++)
        {
            if (i != index)
            {
				array->elements[i - (i >= index)] = array->elements[i];
            }
            else
            {
				CTObjectRelease(array->elements[i]);
            }
        }
        array->elements = CTAllocatorReallocate(array->alloc, array->elements, sizeof(CTObject *) * --array->count);
	}
}

uint64_t CTArrayIndexOfEntry(CTArray * restrict array, CTObject * restrict value)
{
    for (uint64_t i = 0; i < array->count; i++)
    {
        if (array->elements[i] == value)
        {
            return i;
        }
    }
    return -1;
}

void CTArrayEmpty(CTArray * restrict array)
{
	for (long long i = array->count; i >= 0; i--)
    {
        CTArrayDeleteEntry(array, i);
    }
}

CTObject * CTArrayObjectAtIndex(CTArray * restrict array, uint64_t index)
{
	return index < array->count ? array->elements[index] : NULL;
}

uint64_t CTArrayCount(CTArray * restrict array)
{
	return array->count;
}
{'fraction_non_alphanumeric': 0.14086687306501547, 'fraction_numerical': 0.015701017249004866, 'mean_word_length': 2.960595446584939, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 76, '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': '6041021', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1489, 'n_words': 343}