// 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/contmap.h>

void lxContMap_init(lxContMap_t* cv, size_t keysize, size_t valsize)
{
	lxContVector_init(&cv->keys,keysize);
	lxContVector_init(&cv->values,valsize);
}

booln	lxContMap_set(lxContMap_t* cv, void *key, void *val)
{
	if (lxContVector_find(&cv->keys,key) != -1) return LUX_FALSE;

	lxContVector_pushBack(&cv->keys,key);
	lxContVector_pushBack(&cv->values,val);

	return LUX_TRUE;
}
booln	lxContMap_remove(lxContMap_t* cv, void *key)
{
	int idx = lxContVector_find(&cv->keys,key) ;
	if (idx != -1) return LUX_FALSE;

	lxContVector_remove(&cv->keys,idx);
	lxContVector_remove(&cv->values,idx);

	return LUX_TRUE;
}
booln	lxContMap_get(lxContMap_t* cv, void *key, void**outval)
{
	int idx = lxContVector_find(&cv->keys,key);
	if (idx == -1) return LUX_FALSE;

	*outval = lxContVector_at(&cv->values,idx);
	return LUX_TRUE;
}

void	lxContMap_clear(lxContMap_t *cv)
{
	lxContVector_clear(&cv->keys);
	lxContVector_clear(&cv->values);
}
