Example #1
0
/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0637
@SYMTestCaseDesc        Streaming conversions test
@SYMTestPriority        Medium
@SYMTestActions         Test the database definition and enquiry functions 
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void Test()
	{
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0637 Build without transactions "));
	CreateDatabaseL();
	TUint time1,size1;
	BuildTable(KRecords,EFalse,time1,size1);
	CloseDatabaseL();
	test.Next(_L("Build with transactions"));
	CreateDatabaseL();
	TUint time2,size2;
	BuildTable(KRecords,ETrue,time2,size2);
	test.Printf(_L("Transaction performance: time %4.2f, size %4.2f\n"),TReal(time1)/TReal(time2),TReal(size1)/TReal(size2));
	test.Next(_L("Build Int index"));
	Execute(_L("create unique index int on table (int)"));
	test.Next(_L("Break index"));
	BreakIndex();
	test.Next(_L("Build Text index"));
	Execute(_L("create unique index text on table (text)"));
	test.Next(_L("Recover"));
	test (TheDatabase.IsDamaged());
	CloseDatabaseL();
	OpenDatabase();
	test (TheDatabase.IsDamaged());
	Recover();
	test.Next(_L("Drop table"));
	Execute(_L("drop table table"));
	CloseDatabaseL();
	}
Example #2
0
AmEvent* ArpUncertainChorusFilter::HandleToolEvent(	AmEvent* event, const am_filter_params* params,
        const am_tool_filter_params* toolParams)
{
    if (event && mHolder) event->SetNextFilter(mHolder->FirstConnection() );
    if (!event || !toolParams) return event;
    if (event->Type() == event->NOTEON_TYPE) {
        AmNoteOn*	e = dynamic_cast<AmNoteOn*>(event);
        if (!e) return event;
        BuildTable(e->Note(), toolParams);
        for (uint32 k = 0; k < NOTE_SIZE; k++) {
            if (mNotes[k] ) {
                AmNoteOn*	e2 = dynamic_cast<AmNoteOn*>(e->Copy() );
                if (e2) {
                    e2->SetNote(k);
                    e->AppendEvent(e2);
                }
            }
        }
    } else if (event->Type() == event->NOTEOFF_TYPE) {
        AmNoteOff*	e = dynamic_cast<AmNoteOff*>(event);
        if (!e) return event;
        BuildTable(e->Note(), toolParams);
        for (uint32 k = 0; k < NOTE_SIZE; k++) {
            if (mNotes[k] ) {
                AmNoteOff*	e2 = dynamic_cast<AmNoteOff*>(e->Copy() );
                if (e2) {
                    e2->SetNote(k);
                    e->AppendEvent(e2);
                }
            }
        }
    }

    return event;
}
Example #3
0
void HuffmanEncoder::BuildTable(HuffmanNode* root, std::string code)
{
    if (root->GetLeftChild() == NULL)
    {
        root->SetCode(code);
        huffmanTable.insert(std::pair<char, std::string>(root->GetLetter(), code));
        return;
    }
    else
    {
        BuildTable(root->GetLeftChild(), code + std::string(1, (char)0));
        BuildTable(root->GetRightChild(), code + std::string(1, (char)1));
    }
}
Example #4
0
unsigned long EncryptText(unsigned long N, unsigned long E, char * szText, unsigned long ulText, unsigned long *ucEncrypted)
{
	//M^E = X (mod (N))
	//Construct a table that is relatively prime to N (Up to 26 chars for english alphabet.. just for this example....
	ASCIITable Table[26] = {{0}};

	unsigned long i = 0;
	unsigned long EncryptedCount = 0;

	BuildTable(N, Table);


	for(i ;i < ulText; i ++)
	{
		unsigned char CharacterCode = *(unsigned char*)((unsigned long)szText + i);
		unsigned long X = 0;
		for(X; X < 26; X++)
		{
			if (Table[X].Character == CharacterCode)
			{
				*(unsigned long*)(ucEncrypted + i) = Power(Table[X].Code,E) % N;
				EncryptedCount++;
				break;
			}
		}
	}

	return EncryptedCount;
}
Example #5
0
ArclengthTable::ArclengthTable(QVector<QVector3D> *points) :
    points(points),
    numTableEntries(points->size())
{
    indices = new int[numTableEntries];
    parametricEntries = new float[numTableEntries];
    arclengths = new float[numTableEntries];

    BuildTable();
}
Example #6
0
CRawDib::CRawDib()
{
	m_nWWid = 65535;
	m_nWPos = 32768;

	m_pRawDataMatrix = new BYTE[ImageMatrixSize]; //3072*3072*2
	memset(m_pRawDataMatrix,0,ImageMatrixSize);

	m_pRawData = NULL;
	BuildTable(2.2F);
}
Example #7
0
File: board.cpp Project: fkp/src
// Copy constructor
Board::Board(const Board * boardToCopy)
{
  // All we need to do is copy each of the squares in this board to our own
  for(int y=0; y<Common::NoNumbers; y++)
  {
    for(int x=0; x<Common::NoNumbers; x++)
    {
      _theSquares[x][y] = new Square(boardToCopy->_theSquares[x][y]);
    }
  }

  BuildTable();
}
Example #8
0
// 輸出檔案
int GmodelExp::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options) 
{
	// Set a global prompt display switch
	showPrompts = suppressPrompts ? FALSE : TRUE;
	exportSelected = (options & SCENE_EXPORT_SELECTED) ? TRUE : FALSE;

	// Grab the interface pointer.
	ip = i;

	if(showPrompts)
	{
		// Prompt the user with our dialogbox, and get all the options.
		if (!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_GMODELEXPORT_DLG),
			ip->GetMAXHWnd(), ExportDlgProc, (LPARAM)this)) 
		{
			return 1;
		}
	}

	// Open the stream
	m_pFile = _tfopen(name,_T("wt"));
	if ( !m_pFile ) 
	{
		return 0;
	}

	// Startup the progress bar.
	ip->ProgressStart(GetString(IDS_PROGRESS_MSG), TRUE, fn, NULL);

	// Get node & material list
	BuildTable();

	// Export file header
	ExportHeader();

	// Material
	//if ( m_bExportMaterial )
	ExportMaterial();

	// Mesh
	//if ( m_bExportMesh )
	ExportMesh();

	// Done :) Finish the progress bar.
	ip->ProgressEnd();

	// Close the stream
	fclose(m_pFile);

	return 1;
}
//______________________________________________________________________________
void HtmlObjTable::Build()
{
	// Build HTML code.
	
	fHtml = "<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",
	
	BuildTitle();
	if (fExpand && (fNFields > 0) && (fNValues > 0)) {
		BuildLabels();
		BuildTable();
	}
	
	fHtml += "</table>";
}
Example #10
0
/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0579
@SYMTestCaseDesc        Tests the database definition and enquiry functions
@SYMTestPriority        Medium
@SYMTestActions        	Executes the index and bookmark tests
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void BigTestL()
	{
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0579 Table "));
	CreateDatabaseL();
	BuildTable(KRecords);
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
	TheTable.EndL();
	IterateL(TheTable.EPrevious);
	TheTable.BeginningL();
	IterateL(TheTable.ENext);
	TheTable.EndL();
	IterateL(TheTable.EPrevious);
	TheTable.Close();
	test.Next(_L("Int32 Index"));
	CDbKey *key=CDbKey::NewLC();
	key->AddL(KColumnInt);
	key->MakeUnique();
	TestIndex(KIndexInt,*key);
	test.Next(_L("Text[200] Index"));
	key->Clear();
	key->AddL(KColumnText);
	key->MakeUnique();
	TestIndex(KIndexText,*key);
	test.Next(_L("Bookmarks"));
	TestBookmark();
	test.Next(_L("Int32 Index"));
#ifndef __TOOLS2__
	TheTimer.Start(_L("drop"));
#endif
	test(TheDatabase.DropIndex(KIndexInt,KTableName)==KErrNone);
#ifndef __TOOLS2__
	TheTimer.Stop();
#endif
	key->Clear();
	key->AddL(KColumnInt);
	key->MakeUnique();
	TestIndex(KIndexInt,*key);
	CleanupStack::PopAndDestroy();
	test.Next(_L("Break & Recover"));
	BreakIndex();
	Recover();
	test.Next(_L("Drop Indexes"));
	DropIndexes();
	test.Next(_L("Delete all records"));
	DeleteTable();
	CloseDatabaseL();
	test.End();
	}
Example #11
0
void
ComputerScoring (int player)
{
  int i;
  int best;
  int bestv;

  NumberOfRolls = 3;		/* in case skipped middle */

  BuildTable (player);

  best = 0;

  bestv = -99;

  for (i = NUM_FIELDS - 1; i >= 0; --i) {
    if (player % 2) {
      if (bc_table[i] > bestv) {
	best = i;

	bestv = bc_table[i];
      }
    }

    else {
      if (bc_table[i] >= bestv) {
	best = i;

	bestv = bc_table[i];
      }
    }

    if (DisplayComputerThoughts) {
      fprintf (stderr, "<<BEST>> %s : VALUE = %d\n",
	       _(FieldLabels[best]),
	       bc_table[best]);
    }

  }

  if (DisplayComputerThoughts)
      fprintf (stderr, "I choose category %d as best %d score name %s\n",
               best, bc_table[best], _(FieldLabels[best]));

  play_score (player, best);

}
Example #12
0
int svpn_server_init_client(struct svpn_server *psc, const char* userlist)
{
	FILE* fin;
	char tmpstr[128];
	unsigned char pmd5[16];
	int tmpint, id;

	if((fin = fopen(userlist, "r")) == NULL)
		return -1;

	memset(psc->clients, 0, sizeof(psc->clients));

	while (1)
	{
		if (fscanf(fin, "%s", tmpstr) <= 0)
			break;
		if (strcasecmp(tmpstr, "user") != 0)
			goto skipline;

		// read id
		if (fscanf(fin, "%d", &id) <= 0)
			goto skipline;
		if (psc->clients[id] != NULL)
		{
			mprintf(LERROR, "User ID duplicated");
			goto skipline;
		}
		// read password
		if (fscanf(fin, "%s", tmpstr) <= 0)
			goto skipline;
		// OK
		psc->clients[id] = 
			(struct svpn_client_node*)malloc(sizeof(struct svpn_client_node));
		MD5Fast(tmpstr, strlen(tmpstr), pmd5);
		BuildTable(&(psc->clients[id]->table), pmd5, id);

		mprintf(LINFO, "User #%d added", id);

skipline:
		fgets(tmpstr, sizeof(tmpstr), fin);
	}

	fclose(fin);
	return 0;
}
Example #13
0
int main()
{
	scanf("%d", &N);

	//clock_t start = clock();
	BuildTable(HASH - 1);

	Fibonacci(N - 1, rez1);
	Fibonacci(N + 1, rez2);
	BigAdd(rez1, rez2);

	printf("%d", rez1[rez1[0]]);
	for (int i = rez1[0] - 1; i > 0; i--)
		printf(FMT, rez1[i]);
	printf("\n");

	//clock_t end = clock();

	//printf("Time = %.4lf\n", (double)(end - start)/CLK_TCK);

	return 0;
}
Example #14
0
int ComputerScoring(const player &p)
{
	int i;
	int best;
	int bestv;

	BuildTable(p, 2);

	best = 0;

	bestv = -99;

	for (i = NUM_FIELDS-1; i >= 0; --i) {
			if (bc_table[i].value > bestv)
			{
				best = i;

				bestv = bc_table[i].value;
			}
        }

	return best;
}
Example #15
0
void
ComputerRolling(const player &p, int NumberOfRolls)
{
	int i;
	int best;
	int bestv;

	BuildTable(p, NumberOfRolls);
        
	best = 0;
        
	bestv = -99;
        
	for (i = NUM_FIELDS-1; i >= 0; --i)
		if (bc_table[i].value >= bestv) {
                        best = i;
                        
                        bestv = bc_table[i].value;
                }

        for (i=0; i<5; i++)
                DiceValues[i].sel = bc_table[best].rerolls[i];
}
Example #16
0
struct svpn_client *svpn_init(char *addr, unsigned short port,
		unsigned char *md5, long long timestamp) {

	struct svpn_client *psc = (struct svpn_client*) malloc(sizeof(struct svpn_client));
	struct sigaction sact;
	memset(&sact, 0, sizeof(struct sigaction));
	memset(psc, 0, sizeof(struct svpn_client));

	BuildTable(&(psc->table), md5, timestamp);


	// init socket
	if(svpn_sock_create(psc, addr, port) < 0) {
		free(psc);
		psc = NULL;
		goto out;
	}


	// init tunnel
	psc->tun_fd = svpn_tun_create(psc->dev_name);
	if(psc->tun_fd < 0) {
		close(psc->sock_fd);
		free(psc);
		psc = NULL;
		goto out;
	}


	//signal(SIGUSR1, svpn_sig_handler);
	sact.sa_handler = svpn_sig_handler;
	sact.sa_flags &= ~SA_RESTART;
	sigaction(SIGUSR1, &sact, &(psc->old_act));

out:
	return psc;
}
Example #17
0
unsigned long DecryptText(unsigned long N, unsigned long D, unsigned long* ucEncrypted, unsigned long ulEncrypted, char * szBuffer)
{
	//X^D = M (mod(N))
	unsigned long i = 0;
	ASCIITable Table[26] = {{0}};
	BuildTable(N,Table);

	for(i; i < ulEncrypted; i ++)
	{
		unsigned long long ulCode = Power(ucEncrypted[i],D) % N;

		unsigned long X = 0;

		for (X; X < sizeof(Table); X++)
		{
			if (Table[X].Code == ulCode)
			{
				*(char*)((unsigned long)(szBuffer) + i) = Table[X].Character;
				break;
			}
		}
	}
	return ulEncrypted;
}
Example #18
0
void
ComputerRolling (int player)
{
  int i;
  int best;
  int bestv;
  int num_options = 1;
  int die_comp[NUMBER_OF_DICE];
  double best_score;
  int ii, jj, kk;

  for (i = 0; i < NUMBER_OF_DICE; i++) {
      die_comp[i] = num_options;
      num_options *= 2;
  }

  double avg_score[num_options];
  DiceInfo sav_DiceValues[NUMBER_OF_DICE];
  memset (avg_score, 0, sizeof (avg_score));
  memcpy (sav_DiceValues, DiceValues, sizeof (sav_DiceValues));

  for (ii = 0; ii < num_options; ii++) {
      for (jj = 0; jj < NUM_TRIALS; jj++) {
          DiceInfo loc_info[NUMBER_OF_DICE];
          memcpy (loc_info, sav_DiceValues, sizeof (loc_info));
          for (kk = 0; kk < NUMBER_OF_DICE; kk++) {
              if (die_comp[kk] & ii) {
                  loc_info[kk].val = RollDie ();
              }
          }
          memcpy (DiceValues, loc_info, sizeof (sav_DiceValues));
          BuildTable (player);
          bestv = -99;
          for (i = NUM_FIELDS - 1; i >= 0; i--) {
              if (bc_table[i] >= bestv) {
                  bestv = bc_table[i];
              }
          }
          avg_score[ii] += bestv;
      }
      avg_score[ii] /= NUM_TRIALS;
      if (DisplayComputerThoughts) printf ("Set avg score for %d to %f\n", ii, avg_score[ii]);
  }

  best  = 0;
  best_score = -99;
  for (ii = 0; ii < num_options; ii++) {
      if (avg_score[ii] >= best_score) {
          best = ii;
          best_score = avg_score[ii];
      }
  }
  if (DisplayComputerThoughts) printf ("Best choice is %d val %f for dice ", best, best_score);

  /* Restore DiceValues */
  memcpy (DiceValues, sav_DiceValues, sizeof (sav_DiceValues));
  for (ii = 0; ii < NUMBER_OF_DICE; ii++) {
      if (die_comp[ii] & best) {
          DiceValues[ii].sel = 1;
          if (DisplayComputerThoughts)
	      printf ("Reset to roll die %d value %d bit %d comp %d test %d\n", ii, DiceValues[ii].val, ii, best, ii & best);
      }
      else {
          DiceValues[ii].sel = 0;
          if (DisplayComputerThoughts)
	      printf ("Reset NOT to roll die %d value %d bit %d comp %d test %d\n",
		      ii, DiceValues[ii].val, ii, best, ii & best);
      }
  }
}
Example #19
0
void CClassification::EnterTask()
{
#ifndef _WINDOWS // ------- Don't compile on windows -----

	Uint32 unIntervalTicks;
	
	Bool bLed2 = FALSE;
	ledLight( 2, FALSE );
	
	// Initialize the conveyor device driver and register the trigger semaphore.
	convInit( );
	SEM_new( &m_semTrigger, 0 );
	
	convRegisterSemTrigger( &m_semTrigger, &m_bTrigger );	
	
	// Reset statstics
	GetStats( NULL, TRUE );

	// Initialize the high res timer
	timeInit();
	
	// Pre-calculate the maximum wait time for the semaphore.
	unIntervalTicks = hlpMsToTicks( 1000 * MAXWAIT_SECONDS );
	
	// Open the interlink UART channel and configure it.
	m_hPPUSerial = serOpen( INTERLINK_UART_CHAN, sizeof( ClassificationTable ) *4 );
	assertLog( m_hPPUSerial != NULL );
	serConfigChannel( m_hPPUSerial, 115000, FALSE, FALSE, FALSE );	
	
	// Initialize the jet controller
	TSK_sleep( 2000 );
	CJetControl::Instance()->Init();
	
	// Start watchdog and set it to twice the time of our maximum interval.
	m_unWatchId = CWatchdog::Instance()->AddToWatch( "Classification", MAXWAIT_SECONDS * 2 );
	CWatchdog::Instance()->EnableWatch( m_unWatchId, TRUE );
	
	while( 1 )
	{
			
		// Wait for a trigger signal, timeout at some time to reset watchdog
		if ( SEM_pend( &m_semTrigger, unIntervalTicks ) )
		{
			// Succesfully received a trigger
			ledLight( 2, bLed2 );
			bLed2 = !bLed2;			
						
			// Get the trigger time as exact as possible.
			Uint32 unCurTime = convGetLastTriggerTime();
						
			// Increment our trigger counter.
			m_unCurrentTriggerPulse++;
			// dbgLog( "Entering Trigger %d", m_unCurrentTriggerPulse );
			
			// Store that trigger in the stats. This increments the number of possible potatoes by the number
			// of lanes.
			m_sClassificationStats.unNumPossible += m_nNumLanes;
			
			// See if we're in service mode and handle it.
			if ( m_csmServiceMode != CSM_NORMAL )
			{
				if (   (m_csmServiceMode == CSM_ADJUST_SMALL_EJECTION_PARAMS )
					|| (m_csmServiceMode == CSM_ADJUST_MEDIUM_EJECTION_PARAMS )
					|| (m_csmServiceMode == CSM_ADJUST_LARGE_EJECTION_PARAMS ) )
					ServiceGenParamAdjustCommands( unCurTime );
			}
			else
			{		
				// If not in service mode, see if we've got any due ejections to make and generate
				// the commands for it.
				EjectionTable * pTable;
				
				// See if any ejections are due and generate the jetcontrol commands, which are then
				// sent to the jet control.
				pTable = GetDueEjectionTable();
				if ( pTable != NULL )
				{
					// Generate ejection commands, but only if we're in classification mode.
					if ( m_eOperationMode == OP_CLASSIFICATION )
					{
						GenerateEjectionCommands( pTable, unCurTime );
					}
					ReleaseEjectionTable( pTable );
				}
							
				// Now we have to classify the potatoes and create the ejection table for the current
				// line. Only build the table if we've got a reference to the global potato table
				if ( m_pPotatoTable != NULL )
				{												
					// Build the local classification table (i.e. the per-frame classification)
					BuildTable( &m_LocalClassificationTable,  m_pPotatoTable );
					
					// Only exchange tables if we're in classification mode.
					if ( m_eOperationMode == OP_CLASSIFICATION )
					{					
						// Exchange the table with the other DSP
						if ( ExchangeTables( &m_LocalClassificationTable, &m_ForeignClassificationTable ) == TRUE )
						{
							MergeTables( &m_LocalClassificationTable, &m_ForeignClassificationTable );
						}
					}
						
					// Classify the potatoes using a new ejection table. This, we'll
					// have to do even in calibration mode, because of the statistics
					// for the GUI.
					pTable = GetNewEjectionTable( m_nNumTriggerPulsesDelay );
					if ( pTable != NULL )
					{
						ClassifyPotatoes( & m_LocalClassificationTable, &m_ForeignClassificationTable, pTable );
					}	
					
				} // if potatoobject table accessible
				
			} // if not in servicemode
			
		} // if trigger occured
		
		else
		{
			// Clean the objects list from time to time, if we don't receive trigger signals for
			// a long time. This prevents the number of objects from growing to big.
			CleanObjects( m_pPotatoTable );	
			
			// Check for service operation
			if ( m_csmServiceMode == CSM_CHECK_JETS )
				ServiceGenJetCheckCommands();	
						
		}
		
		// See if any of the strictness values changed and apply it to the properties
		if (   m_propSplitStrictness.HasChanged()
			|| m_propShapeStrictness.HasChanged()
			|| m_propGreenStrictness.HasChanged()
			|| m_propColorStrictness.HasChanged() )
		{
			ApplyStrictness();		
		}
		
		// Signal the watchdog.
		CWatchdog::Instance()->SignalAlive( m_unWatchId );	
		
	} // while(1)

#endif // ------------------------------------------------

}
Example #20
0
File: board.cpp Project: fkp/src
bool Board::InitFromXMLFile(const char * fileName)
{
  bool toReturn = false;
  xmlDocPtr doc;
  xmlXPathContextPtr xpathCtx; 
  xmlXPathObjectPtr xpathObj; 
  int ret;

  // Init libxml
  xmlInitParser();
  LIBXML_TEST_VERSION

  assert(fileName);
  assert(XPathExpression);

  // Load XML document
  doc = xmlParseFile(fileName);

  if (doc == NULL)
  {
    cout << "Error: unable to parse file " << fileName << endl;
    return false;
  }

  // Create xpath evaluation context
  xpathCtx = xmlXPathNewContext(doc);
  if(xpathCtx == NULL)
  {
    cout << "Error: unable to create new XPath context" << endl;
    xmlFreeDoc(doc); 
    return false;
  }
    
  // Evaluate xpath expression
  xpathObj = xmlXPathEvalExpression(BAD_CAST XPathExpression, xpathCtx);
  if(xpathObj == NULL)
  {
    cout << "Error: unable to evaluate xpath expression " << XPathExpression << endl;
    xmlXPathFreeContext(xpathCtx); 
    xmlFreeDoc(doc); 
    return false;
  }

  // Process the nodes in the file
  toReturn = ProcessNodes(xpathObj->nodesetval, stdout);

  // Cleanup
  xmlXPathFreeObject(xpathObj);
  xmlXPathFreeContext(xpathCtx); 
  xmlFreeDoc(doc); 
    
  // Shutdown libxml
  xmlCleanupParser();
    
  // This is to debug memory for regression tests
  xmlMemoryDump();

  // Build the UI table with the squares we have
  BuildTable();

  return toReturn;
}