
unit Filter
{
	public const uint16 ID = 0;
	
	//[i] linkconst_int32_3 Number;
	public const uint32 Number = 0;
	
	[int32*Number] Buffer;
	int8 CurrentIndex;
	
	[int32*Number] tempBuffer;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		CurrentIndex = 0;
	}
	//---------------------------------------------------
	//[i] function_void add_data int32;
	public void add_data( int32 d )
	{
		Buffer[CurrentIndex] = d;
		CurrentIndex + 1;
		CurrentIndex % (int8)(int16)Number;
	}
	//---------------------------------------------------
	//[i] function_int32 get_data;
	public int32 get_data()
	{
		uint8 n = (uint8)(uint16)(uint)Number;
		for( uint8 i = 0; i < n - 1; i + 1 ) {
			for( uint8 j = n - 1; j > i; j - 1 ) {
				if( Buffer[j] < Buffer[j - 1] ) {
					int32 d = Buffer[j];
					Buffer[j] = Buffer[j - 1];
					Buffer[j - 1] = d;
				}
			}
		}
		if( n % 2 == 0 ) {
			return (Buffer[ (n)/2 - 1 ] + Buffer[ (n)/2 ]) / 2;
		}
		else {
			return Buffer[ (n-1)/2 ];
		}
	}
}






