


#include "element.h"

#include "quadMesh.h"

#include "../vector2.h"

#include "../int.h"


template<T>
class vector{

	int capacity 		= 10;

	int total 			= 0;

	T * items 			= malloc( 10000000 );

	int length()
	{

		return this->total;

	}

	T get( int index )
	{

		return this->items[index];

	}

	void set( int index, T item )
	{

		if ( index >= 0 && index < this->total ){

			this->items[ index ] = item;

		}

	}

	void resize( int capacity )
	{

		T * items = realloc( this->items, sizeof( T ) * capacity );


		this->items 	= items;

		this->capacity 	= capacity;

	}

	void add( T item )
	{

		if ( this->capacity == this->total ){

			this->resize( this->capacity * 2 );
	
		}

		this->items[ this->total++ ] = item;

	}

	void delete( int index )
	{

		//this->items[index] = NULL;

		for ( int i = index; i < this->total - 1; i++ ) {

			this->items[i] = this->items[i + 1];

			//this->items[i + 1] = NULL;

		}



		// bug preprocessor + operator on pointer of vector2 or vector3.
		//memmove( this->items + index, this->items + index + 1, ( ( this->total - index ) - 1) * ( sizeof( T ) ) );


		this->total--;

		//if ( this->total > 0 && this->total == this->capacity / 4 ){

		//	this->resize( this->capacity / 2 );

		//}

	}



	int array_push( T item ) {

		this->add( item );
		
		return  this->total;

	}

	void unshift( T item ) {

		int length	= this->total;

		this->total++;

		if ( this->capacity == this->total ){

			this->resize( this->capacity * 2 );

		}

		for ( int i = length - 1; i >= 0; --i ) {

			this->items[ i + 1 ] = this->items[ i ];

		}

		this->items[ 0 ] = item;

	}
/*
	bool includes() {

		//#if TEMPLATE_1

	}
*/

/*
	T pop() {

		int length			= this->total;

		int lastIndex		= length - 1;

		T lastItem		= this->get( lastIndex );

		this->delete( lastIndex );

		return lastItem;

	}
*/

}

/*

template<>
class <char *>vector{

	includes( char * value ) {

		int count = this->items->length();

		for (int i = 0; i < count; ++i)
		{
			
			char * current = this->items->get( i );

			if(	current == value ) {
		
				return true;

			} 

		}
	
		return false;

	}

}


template<>
class <int>vector{

	bool includes( int value ) {

		int count = this->items->length();

		for (int i = 0; i < count; ++i)
		{
			
			int current = this->items->get( i );

			if(	current == value ) {
		
				return true;

			} 

		}
	
		return false;

	}

}

*/