Exemple #1
0
oexUINT CBin::Threshold( oexINT nType, oexUINT uOffset, oexUINT uSamples, oexUINT uE, oexDOUBLE dUpper, oexDOUBLE dUpperDef, oexDOUBLE dLower, oexDOUBLE dLowerDef )
{_STT();
	// Get element size
	oexUINT uESize = obj::StaticSize( nType );
	if ( !uESize )
		return 0;

	// Starting in the buffer?
	if ( ( uOffset + uESize ) >= getUsed() )
		return 0;

	// Boundry limit samples
	oexUINT uMaxSamples = ( getUsed() - uOffset ) / uESize;
	if ( !uSamples || uSamples > uMaxSamples )
		uSamples = uMaxSamples;

	switch( nType )
	{
		OEX_CBIN_TH_TYPE( tInt8, CHAR, uE );
		OEX_CBIN_TH_TYPE( tUInt8, UCHAR, uE );
		OEX_CBIN_TH_TYPE( tInt16, SHORT, uE );
		OEX_CBIN_TH_TYPE( tUInt16, USHORT, uE );
		OEX_CBIN_TH_TYPE( tInt32, INT, uE );
		OEX_CBIN_TH_TYPE( tUInt32, UINT, uE );
		OEX_CBIN_TH_TYPE( tInt64, INT64, uE );
		OEX_CBIN_TH_TYPE( tUInt64, UINT64, uE );
		OEX_CBIN_TH_TYPE( tFloat, FLOAT, uE );
		OEX_CBIN_TH_TYPE( tDouble, DOUBLE, uE );

		default : break;

	} // end switch

	return uESize;
}
bool SynopsisMD2::evict_lleaf(int lvl,int idx,int left_child,
		int leaf_idx,bool left,bool right,int target_size)
{

	prev_victim.idx = idx;
	prev_victim.lvl = lvl;
	bool merged = false;
	string action;
	//print_clock();

	if(!mergeEqual && (getUsed(lvl+1,leaf_idx)>0 || getUsed(lvl+1,leaf_idx+1)>0) && (right != left))
  	{

		//cout<<"decrementing"<<endl;
		decrementUsed(lvl+1,leaf_idx);
		decrementUsed(lvl+1,leaf_idx+1);
		action="decrementing";
  	}

  	else /* they are equal, or mergeable [because none of them is used] */
  	{

  		if(!mergeEqual || (mergeEqual && left==right))
  		{
			merge(lvl,left_child,idx);
			action="merging";
			merged =true;

			//levels->at(lvl).prefix = 0;
			//levels->at(lvl).idx = 0;

			/*int offset = getLeafOffset(lvl,idx);
			if(!getLeaf(lvl,idx,offset)) // if it's a zero leaf
				incrementUsed(lvl,offset); //parents used thingey
			else
				setUsed(lvl,offset,0);*/
  		}
  	}

	stringstream ss;
	//print_clock();
	ss<<"after leaf "<<action<<" : size ="<<num_bits<<" clock:"<<prev_victim.lvl<<","<<prev_victim.idx;
	//takeSnapshot(ss.str());

	if(num_bits>target_size)
		return false;
	else
		return true;

}
Exemple #3
0
simplest::Simple simplest::Simple::create()  {
    if(instanceCount() == 0)
        return Simple();
    Simple result = popFreeSimple();
    if(!result.isValid())
    {
        if(getUsed() >= instanceCount())
            reallocInstances(instanceCount() << 1);
        result = Simple(getUsed());
        setUsed(getUsed() + 1);
    }
    result.reset();
    result.onCreate();
    return result;
}
Exemple #4
0
testlist::Parent testlist::Parent::create()  {
    if(instanceCount() == 0)
        return Parent();
    Parent result = popFreeParent();
    if(!result.isValid())
    {
        if(getUsed() >= instanceCount())
            reallocInstances(instanceCount() << 1);
        result = Parent(getUsed());
        setUsed(getUsed() + 1);
    }
    result.reset();
    result.onCreate();
    return result;
}
Exemple #5
0
testlist::Child testlist::Child::create()  {
    if(instanceCount() == 0)
        return Child();
    Child result = popFreeChild();
    if(!result.isValid())
    {
        if(getUsed() >= instanceCount())
            reallocInstances(instanceCount() << 1);
        result = Child(getUsed());
        setUsed(getUsed() + 1);
    }
    result.reset();
    result.onCreate();
    return result;
}
Exemple #6
0
CBin::t_size CBin::Randomize( int nStart, int nEnd )
{
	if ( nStart < 0 )
		nStart = 0;

	if ( nEnd <= 0 )
		nEnd = getUsed();
	else if  ( nEnd > getUsed() )
		nEnd = getUsed();

	if ( nStart >= nEnd )
		return 0;

	os::CSys::Rand( _Ptr( nStart ), nEnd - nStart );

	return nEnd - nStart;
}
Exemple #7
0
CBin::t_size CBin::Copy( CBin *x_p )
{_STT();

	// Just ensuring our internal buffer is unshared?
	if ( !x_p )
	{
		// Where's the buffer we're dealing with?
		t_size nUsed = getUsed();
		const CBin::t_byte* ptr = Ptr();

		// Valid buffer?
		if ( 0 >= nUsed || !ptr )
		{	Destroy();
			return 0;
		} // end if

		// User ptr buffer?
		if ( m_ptr )
			m_buf.MemCpy( ptr, nUsed ), FreePtr();

		// Make a copy of shared pointer
		else
		{	t_buffer buf;
			buf.MemCpy( ptr, nUsed );
			m_buf.Assume( buf );
		} // end else if

		// Restore used count
		m_nUsed = nUsed;
		m_nOffset = 0;

		return nUsed;

	} // end if

	// Valid buffer?
	if ( !x_p->Ptr() || !x_p->getUsed() )
	{	Destroy();
		return 0;
	} // end if

	// Lose Ptr buffer if any
	FreePtr();
	m_nUsed = x_p->getUsed();

	// Ptr buffer?
	m_buf.MemCpy( x_p->Ptr(), m_nUsed );

	return m_nUsed;
}
Exemple #8
0
CBin::t_size CBin::Insert( CBin::t_size x_nBytes, CBin::t_size x_nOffset = 0 )
{_STT();

	if ( !x_nBytes )
		return 0;

	// Is it past the end?
	if ( !getUsed() || x_nOffset >= getUsed() )
	{
		// Resize the buffer
		Resize( x_nOffset + x_nBytes );

		// Zero space between end of buffer and offset
		t_size over = x_nOffset - getUsed();
		if ( over ) oexZeroMemory( _Ptr( getUsed() ), over );

		// Update used value
		setUsed( x_nOffset + x_nBytes );

		return getUsed();

	} // end if

	// Allocate space
	Resize( getUsed() + x_nBytes );

	// Move block ( can't use memcpy because blocks overlap )
	t_size copy = getUsed() - x_nOffset;
    if ( copy )
    {   t_byte *dst = _Ptr( x_nOffset + x_nBytes + copy - 1 ), *src = _Ptr( x_nOffset + copy - 1 );
        while ( copy-- ) *dst-- = *src--;
    } // end if

	// Set new size
	setUsed( getUsed() + x_nBytes );

	return getUsed();
}
Exemple #9
0
CBin::t_size CBin::LShift( CBin::t_size x_nBytes )
{_STT();

	// Anything to do?
	if ( !x_nBytes && !m_nOffset )
		return 0;

	// All of it?
	if ( x_nBytes >= getUsed() )
	{	FreePtr();
		return 0;
	} // end if

	// Account for the offset
	x_nBytes += m_nOffset;
	m_nOffset = 0;

	// Are we doing any work?
	if ( !x_nBytes )
		return m_nUsed;

	// Copy Ptr buffer if needed
	if ( m_ptr )
	{
		// What's the new size?
		m_nUsed -= x_nBytes;
		if ( !m_buf.OexNew( m_nUsed ).Ptr() )
			return 0;

		// Copy to private buffer
		m_buf.MemCpy( &m_ptr[ x_nBytes ], m_nUsed );

	} // end if
	else
	{
		// Just shift the buffer
		m_buf.LShift( x_nBytes, m_nUsed - x_nBytes ),
		m_nUsed -= x_nBytes;

	} // end else

	return m_nUsed;
}
void QuadSynopsis::buildGraph(int lvl,int idx,vector<int> low, vector<int> high,string & graph)
{
	stringstream ss;
	int leaf_offset;
	ss<<"id"<<id<<"node"<<lvl<<"idx"<<idx;


	string fillcolor ="white";
	string style = "filled";
	bool isClock = false;
	bool isCurr = false;
	if(lvl == prev_victim.lvl && idx == prev_victim.idx)
	{
		//fillcolor="#B4CDCD"; // awlays keep track of the clock //
		isClock = true;
	}

	//isClock = false;

	if(lvl == curr_leaf.lvl && idx == curr_leaf.idx)
		{
			//fillcolor="#B4CDCD"; // awlays keep track of the clock //
			isCurr = true;
		}

	if(isLeaf(lvl,idx))
	{


		bool val = getLeaf(lvl,idx);

		if(val)
			fillcolor="green";
		else
			fillcolor="tomato";

		//if(isClock)
		//					fillcolor="#B4CDCD";
		if(isCurr)
			fillcolor="yellow";


		if(low[0]<0)
		{
			fillcolor = "gray";
			ss<<"[style="<<style<<",fillcolor=\""<<fillcolor<<"\",color=black,label = \"";
					ss<<"[ UNUSED ] ";
					unused++;

		}
		else
		{
			int used_val = getUsed(lvl,getLeafOffset(lvl,idx));

			ss<<"[style="<<style<<",fillcolor=\""<<fillcolor<<"\",color=black,label = \"";
			ss<<"[ "<<getVector(low)<<","<<getVector(high)<<"]";// used ="<<used_val;
			//if(val)
			//	ss<<" [HAZ]";
			//if(isClock)
			//					ss<<", CLOCK";
			if(low.size() ==1)
			{
				int len = high[0]-low[0]+1;
				ss<<", len = "<<len;
			}
		}


		ss<<"\"];\n";
		graph+= ss.str();

	}
	else //we need the kids too
	{

		vector< vector<int> > lowb= getChildrenLowerBounds(low,high);
		vector< vector<int> > highb = getChildrenUpperBounds(low,high);

		int first_child = getFirstChild(lvl,idx);
		//if(isClock)
		//			fillcolor="#B4CDCD";
		if(isCurr)
				fillcolor="yellow";
		ss<<"[style="<<style<<",fillcolor=\""<<fillcolor<<"\",label = \"";
		ss<<"[ "<<getVector(low)<<","<<getVector(high)<<"]";
		//if(isClock)
			//		ss<<", CLOCK";
		ss<<"\"];\n";
		//connect it to its kids :))
		//"node1" -> "node2";

		for(int i=0;i<lowb.size();i++)
                ss<<"\"id"<<id<<"node"<<lvl<<"idx"<<idx<<"\" -> \"id"<<id<<"node"<<lvl+1<<"idx"<<first_child+i<<"\";\n";

		graph+= ss.str();

		for(int i=0;i<lowb.size();i++)

			buildGraph(lvl+1,first_child+i,lowb[i],highb[i],graph);



	}


}
Exemple #11
0
CStr8 CBin::uncompress()
{_STT();
	return oexUncompress( CStr8( Ptr(), getUsed() ) );
}
Exemple #12
0
CStr8 CBin::base16_decode()
{_STT();
	return CBase16::Decode( Ptr(), getUsed() );
}
Exemple #13
0
CStr8 CBin::base64_encode()
{_STT();
	return CBase64::Encode( Ptr(), getUsed() );
}
Exemple #14
0
oexUINT CBin::GroupAvg( oexINT nType, oexUINT uOffset, oexUINT uInterval, oexUINT uGroups, CBin &bin, oexINT nFlags )
{
	// Sanity check
	if ( 0 >= uGroups || !getUsed() )
		return 0;

	// Get skip value
	oexUINT uSkip = nFlags & 0x0f;
	if ( uSkip >= uGroups )
		uSkip = 0;

	// Get element size
	oexUINT uESize = obj::StaticSize( nType );
	if ( !uESize )
		return 0;

	// Total samples
	oexUINT uSamples = getUsed() / uESize;
	if ( uSamples < uInterval )
		return 0;

	// How many samples per group
	oexUINT nSamplesPerGroup = ( uInterval - uSkip ) / ( uGroups - uSkip );
	if ( !nSamplesPerGroup )
		return 0;

	// Allocate memory
	oexUINT uBytes = uGroups * uESize;
	if ( bin.Size() < uBytes )
		if ( !bin.Allocate( uBytes ) )
			return oexFALSE;

	// Allocate an array to hold the counts
	TMem< oexUINT > aCnts;
	if ( !aCnts.OexNew( uGroups ).Ptr() )
		return oexFALSE;

	// Memory to hold acc
	TMem< oexLONGDOUBLE > aAcc;
	if ( !aAcc.OexNew( uGroups ).Ptr() )
		return oexFALSE;

	// Initialize group averages
	for ( oexUINT i = 0; i < uGroups; i++ )
		aAcc[ i ] = 0, aCnts[ i ] = 0;

	// Accumulate all samples
	while( ( uOffset + uInterval ) < uSamples )
	{
		// Accumulate samples in this interval
		for ( oexUINT s = 0; s < uInterval; s++ )
		{
			// Get the value
			oexLONGDOUBLE dV;
			switch( nType )
			{	case obj::tInt : dV = getINT( uOffset + s ); break;
				case obj::tFloat : dV = getFLOAT( uOffset + s ); break;
				case obj::tDouble : dV = getDOUBLE( uOffset + s ); break;
				default : dV = 0;
			} // end switch

			// Range check and add
//			if ( 1000000 > oex::cmn::Abs( dV ) && .0000001 < oex::cmn::Abs( dV ) )

			if ( s < uSkip )
				aAcc[ s ] = dV, aCnts[ s ]++;
			else
			{	oexUINT o = uSkip + s / nSamplesPerGroup;
				if ( o >= uGroups ) o = uGroups - 1;
				aAcc[ o ] += dV; aCnts[ o ]++;
			} // end else

		} // end for

		uOffset += uInterval;

	} // end while

	// Calculate averages
	switch( nType )
	{
		case obj::tInt :
			for ( oexUINT g = 0; g < uGroups; g++ )
				bin.setINT( g, aCnts[ g ] ? oexINT( aAcc[ g ] / aCnts[ g ] ) : 0 );
			break;

		case obj::tFloat :
			for ( oexUINT g = 0; g < uGroups; g++ )
				bin.setFLOAT( g, aCnts[ g ] ? oexFLOAT( aAcc[ g ] / aCnts[ g ] ) : 0 );
			break;

		case obj::tDouble :
			for ( oexUINT g = 0; g < uGroups; g++ )
				bin.setDOUBLE( g, aCnts[ g ] ? oexDOUBLE( aAcc[ g ] / aCnts[ g ] ) : 0 );
			break;

		default :
			return 0;

	} // end switch

	// Number of bytes we used
	bin.setUsed( uBytes );

	return uOffset;
}
Exemple #15
0
int
main (int argc, char *argv[])
{
  AVIHDR avihdr;
  FILE *fin;
  int optchar;
  int flags = 0x00;
  static char strused[5], strdesc[5];
  char *ptrused = NULL, *ptrdesc = NULL;
  char MAGIC[] = { 'R', 'I', 'F', 'F' };

  memset (&avihdr, 0, AVILEN);	/*init avihdr just in case! */
  opterr = 0;

  puts
	("cfourcc 0.1.3.1 - (stupid) console fourcc changer\nCopyright (C) 2014 Mohammad Hafiz <*****@*****.**>\nLicensed under the terms of the GNU General Public License version 2 (or later)\n");


  while ((optchar = getopt (argc, argv, "d:u:ihf::")) != -1) {
	switch (optchar) {
	case 'i':
/*				printf("print info\n");*/
	  flags |= FLAG_INFO;
	  break;
	
	case 'f':
	  flags |= FLAG_FORCE;
	  break;

	case 'd':
	  flags |= FLAG_DESC;
	  ptrdesc = (char *) strdup (optarg);
	  break;

	case 'u':
	  flags |= FLAG_USED;
	  ptrused = (char *) strdup (optarg);
	  break;

	case '?':

/*				flags|=FLAG_HELP;*/
	  /*usage(); */
	  break;

	case 'h':
	  flags |= FLAG_HELP;
	  usage ();

	  puts ("\t-h\t\t Prints this help ;)");
	  puts ("\t-i\t\t Prints FOURCC information (default)");
	  puts ("\t-f\t\t Force changing FOURCC on unsupported file (dangerous)");
	  puts ("\t-u CODE\t\t Sets FOURCC \'used\' codec");
	  puts ("\t-d CODE\t\t Sets FOURCC \'description\' codec\n");
	  puts ("\t ** refer to \'codeclist.txt\' documentation for a list of FOURCC\n\n");
	  break;


	default:
	  return 0x0;
	}
  }

  if (!((optind > 0) && (optchar = -1) && (argv[optind] != NULL))) {
	if ((flags & FLAG_HELP) != FLAG_HELP)
	  usage ();
	return 0x0f;
  }

  fin = fopen (argv[optind], "rb");
  if (fin == NULL) {
	fprintf (stderr, "Error : Cannot access %s\n", argv[optind]);
	return 0x01;
  }

  if (fread (avihdr, sizeof (char), AVILEN, fin) < AVILEN) {
	fprintf (stderr, "Error : Read end unexpectedly, incomplete file?\n");
	return 0x02;
  }
  fclose (fin);

  /*lazy verifier! */
  if (memcmp (avihdr, MAGIC, 4) && !(flags & FLAG_FORCE) ) {
	fprintf (stderr, "Error : Probably not a supported AVI or media file\n");
	return 0x03;
  }

  if (flags == 0x0 || ( (flags & FLAG_INFO) == FLAG_INFO)) {	/*default behaviour */


	getDesc (avihdr, strdesc);
	getUsed (avihdr, strused);

	printf ("FOURCC of \'%s\' :\nDescription : %s\nUse : %s\n\n",
			argv[optind], strdesc, strused);
	return 0x00;


  }

  if (((flags & FLAG_USED) == FLAG_USED)
	  || ((flags & FLAG_DESC) == FLAG_DESC)) {

	fin = fopen (argv[optind], "r+b");
	if (fin == NULL) {
	  fprintf (stderr, "Error : Cannot access %s for writing\n",
			   argv[optind]);
	  return 0x01;
	}
	if (flags & FLAG_USED)
	  setUsed (avihdr, ptrused);

	if (flags & FLAG_DESC)
	  setDesc (avihdr, ptrdesc);

	fseek (fin, 0, SEEK_SET);
	fwrite (avihdr, sizeof (char), AVILEN, fin);
	fflush (fin);
	fclose (fin);

	puts ("Attempting to change FOURCC value...\n");

  }

  puts ("Done.\n");

  return 0;

}
void SynopsisMD2::merge(int parent_lvl, int left_idx, int parent_idx)
{
  int lvl = parent_lvl;

  bool updateClock = false;

  if(lvl+1 == prev_victim.lvl && (prev_victim.idx == left_idx || prev_victim.idx == left_idx+1))
	updateClock = true;
  int right_idx = left_idx + 1;

  assert(isLeaf(lvl+1,left_idx) && isLeaf(lvl+1,right_idx));

  int leaf_idx;
  bool left = getLeaf(lvl+1,left_idx,leaf_idx,true);
  int right_leaf = leaf_idx + 1;
  bool right = getLeaf(lvl+1,left_idx+1);
  bool merged_val = left | right;
  int used_val = getUsed(lvl+1,leaf_idx) + getUsed(lvl+1,right_leaf);

/*#if defined(DOTRACE) && defined(TRACEMERGE)
	vector<pair<int,int> > special_nodes;
				pair<int,int> p,l,r;
				p.first =parent_lvl;
				p.second = parent_idx;
				r.first = parent_lvl +1;
				r.second = right_idx;
				l.first = parent_lvl +1;
				l.second = left_idx;
				special_nodes.push_back(p);
				special_nodes.push_back(l);
				special_nodes.push_back(r);
				takeSnapshot(special_nodes,TRACEMERGE);

#endif*/


  removeValue(lvl+1,left_idx);
  removeValue(lvl+1,left_idx); //this is not a mistake
  for(int i=0;i<dim_bits;i++)
	  removeValue(lvl+1,left_idx); //removing dimension bits :)

  removeLeafValue(lvl+1,leaf_idx);
  removeLeafValue(lvl+1,leaf_idx);//this is not a mistake
  setValue(lvl,parent_idx,false); //parent is turned into a leaf node
#ifdef SYNDEBUG
  assert(isLeaf(lvl,parent_idx));
#endif
  int leaf_offset = getLeafOffset(lvl,parent_idx);
  insertLeafValue(lvl,leaf_offset ,merged_val); //used will initially be zero or N/A

 // if(!merged_val) //if it is an empty leaf, adjust its used counter
  {
	  setUsed(lvl,leaf_offset,used_val);
  }


	num_bits = num_bits - (3+dim_bits) - (used_bit_size*1);


  //if we merged a prev.victim -> the prev victim is the parent
  if(updateClock)
  {
	prev_victim.lvl = lvl;
	prev_victim.idx = parent_idx;

  }

}