// Copyright (C) 2004-2009 Christoph Kubisch & Eike Decker
// This file is part of the "Luxinia Engine".
// For conditions of distribution and use, see copyright notice in luxiniapublicsdk.txt

#include <luxcore/arraymisc.h>

int lxArrayFindOrAdd8(uint8 *data, int *inoutCnt, uint8 value, int maxCnt)
{
	int i = 0;
	while (i < *inoutCnt){
		if (data[i]==value)
			return i;
		i++;
	}
	if (*inoutCnt < maxCnt){
		data[i] = value;
		inoutCnt[0]++;
		return i;
	}
	return -1;
}

int lxArrayFindOrAdd16(uint16 *data, int *inoutCnt, uint16 value, int maxCnt)
{
	int i = 0;
	while (i < *inoutCnt){
		if (data[i]==value)
			return i;
		i++;
	}
	if (*inoutCnt < maxCnt){
		data[i] = value;
		inoutCnt[0]++;
		return i;
	}
	return -1;
}

int lxArrayFindOrAdd32(uint32 *data, int *inoutCnt, uint32 value, int maxCnt)
{
	int i = 0;
	while (i < *inoutCnt){
		if (data[i]==value)
			return i;
		i++;
	}
	if (*inoutCnt < maxCnt){
		data[i] = value;
		inoutCnt[0]++;
		return i;
	}
	return -1;
}

int lxArrayFindOrAddFloat(float *data, int *inoutCnt, float value, int maxCnt)
{
	int i = 0;
	while (i < *inoutCnt){
		if (data[i]==value)
			return i;
		i++;
	}
	if (*inoutCnt < maxCnt){
		data[i] = value;
		inoutCnt[0]++;
		return i;
	}
	return -1;
}

int lxArrayFindOrAddPtr(void **data, int *inoutCnt, void *value, int maxCnt)
{
	int i = 0;
	while (i < *inoutCnt){
		if (data[i]==value)
			return i;
		i++;
	}
	if (*inoutCnt < maxCnt){
		data[i] = value;
		inoutCnt[0]++;
		return i;
	}
	return -1;
}