<commit_before>// 5 may 2015
#include <string.h>
#include "out/ui.h"
#include "uipriv.h"

struct ptrArray *newPtrArray(void)
{
	return uiNew(struct ptrArray);
}

void ptrArrayDestroy(struct ptrArray *p)
{
	if (p->len != 0)
		complain("attempt to destroy ptrarray %p while it still has pointers inside", p);
	if (p->ptrs != NULL)			// array was created but nothing was ever put inside
		uiFree(p->ptrs);
	uiFree(p);
}

#define grow 32

void ptrArrayAppend(struct ptrArray *p, void *d)
{
	if (p->len >= p->cap) {
		p->cap += grow;
		p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]");
	}
	p->ptrs[p->len] = d;
	p->len++;
}

void ptrArrayInsertBefore(struct ptrArray *p, uintmax_t i, void *d)
{
	if (i >= p->len)
		complain("index out of range in ptrArrayInsertBefore()");
	if (p->len >= p->cap) {
		p->cap += grow;
		p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]");
	}
	// thanks to ValleyBell
	memmove(&(p->ptrs[i + 1]), &(p->ptrs[i]), (p->len - i) * sizeof (void *));
	p->ptrs[i] = d;
	p->len++;
}

void ptrArrayDelete(struct ptrArray *p, uintmax_t i)<commit_msg>Important change: ptrArrayAppend() is now implemented in terms of ptrArrayInsertBefore(). ptrArrayInsertBefore() can safely insert at the first invalid index; ValleyBell helped ensure this. tabAppend() will also be implemented this way; boxAppend() might be if uiBoxInsertBefore() becomes a thing. We can rename InsertBefore() to InsertAt() now too.<commit_after>// 5 may 2015
#include <string.h>
#include "out/ui.h"
#include "uipriv.h"

struct ptrArray *newPtrArray(void)
{
	return uiNew(struct ptrArray);
}

void ptrArrayDestroy(struct ptrArray *p)
{
	if (p->len != 0)
		complain("attempt to destroy ptrarray %p while it still has pointers inside", p);
	if (p->ptrs != NULL)			// array was created but nothing was ever put inside
		uiFree(p->ptrs);
	uiFree(p);
}

#define grow 32

void ptrArrayAppend(struct ptrArray *p, void *d)
{
	ptrArrayInsertBefore(p, p->len, d);
}

void ptrArrayInsertBefore(struct ptrArray *p, uintmax_t i, void *d)
{
	if (i > p->len)
		complain("index out of range in ptrArrayInsertBefore()");
	if (p->len >= p->cap) {
		p->cap += grow;
		p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]");
	}
	// thanks to ValleyBell
	memmove(&(p->ptrs[i + 1]), &(p->ptrs[i]), (p->len - i) * sizeof (void *));
	p->ptrs[i] = d;
	p->len++;
}

void ptrArrayDelete(struct ptrArray *p, uintmax_t i)
{'fraction_non_alphanumeric': 0.1763985300122499, 'fraction_numerical': 0.007349938750510413, 'mean_word_length': 4.201698513800425, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '1823621', 'n_tokens_mistral': 955, 'n_tokens_neox': 915, 'n_words': 274}