예제 #1
0
// OK
// Probleme avec le return temp ajoute un '%' à la fin.
// Ce n'est pas un problème d'affichage.
// Si l'on fait un simple return arbre2 dans la fonction on se retrouve aussi avec ce '%'. Problème non corrigé.
Arbre* fusion(Arbre* arbre1, Arbre* arbre2)
{
    Arbre * temp = arbre2;
    if(arbre2 != NULL && arbre1 != NULL)
    {
        // On recherche pour voir si la valeur arbre 1 est dans l'arbre 2
        if (chercher(arbre2,arbre1->valeur) == NULL)
        {
            // Dans le cas non on l'insère
            inserer(arbre2, arbre1->valeur);
        }
        
        // On fait de même pour l'arbre gauche et droite
        arbre2 = fusion(arbre1->gauche, arbre2);
        
        arbre2 = fusion(arbre1->droit, arbre2);
        temp = arbre2;
	}
    else
    {
        if (arbre2 == NULL )
        {
            temp = arbre1;
        }
        else if (arbre1 == NULL)
        {
            temp = arbre2;
        }
    }
    return temp;
}
예제 #2
0
//k temporary table, t initial table
//k,t are both global
void fusion(int l,int r){
	int mid,p,q,i;
	if (r>l){
		mid=(r+l)/2;
		fusion(l,mid);
		fusion(mid+1,r);
		p=l;q=mid+1;i=l;
//merge:
		while (p<=mid && q<=r){
			if (t[p]<t[q]){
				k[i]=t[p];i++;p++;
			}
			else{
				k[i]=t[q];i++;q++;
			}
		}
		if (p<=mid){
			for (int j=p;j<mid+1;j++){
				k[i]=t[j];i++;
			}
		}
		else{
			for(int j=q;j<r+1;j++){
				k[i]=t[j];i++;
			}
		}
		for (i=l;i<r+1;i++){
			t[i]=k[i];
		}
	}
}
예제 #3
0
void tri_fusion(int* result, int it, int* arr,  int size){
#ifdef DEBUG
	printf("tri_fusion(int*, %d, int*, %d)\n", it, size);
#endif

	if(size == 1){
		result[it] = arr[it];
		return;
	}


	int size1 = size/2;
	int size2;

	if(size % 2 == 0){
		size2 = size1;
	}else{
		size2 = size1 + 1;
	}

	int it1 = it;
	int end1 = it1 + size1;
	int it2 = end1;
	int end2 = it2 + size2;

	tri_fusion(result, it1, arr, size1);
	tri_fusion(result, it2, arr, size2);

	for(int i = 0; i < size; ++i)
		arr[i + it] = result[i + it];

	fusion(result, it, arr, it1, end1, it2, end2);
}
예제 #4
0
void triFusionAux(int tableau[], const int debut, const int fin)
{
	if (debut != fin) // condition d'arrêt
	{
		int milieu = (debut + fin) / 2;
		triFusionAux(tableau, debut, milieu); // trie partie1
		triFusionAux(tableau, milieu + 1, fin); // trie partie2
		fusion(tableau, debut, milieu, fin); // fusion des deux parties
	}
}
unsigned int tri_fusion(int *tab, int l, int r) {
  unsigned int cpt = 0;
  if (l < r) {
    int m = l+(r-l)/2;
    cpt = tri_fusion(tab, l, m);
    cpt += tri_fusion(tab, m+1, r);
    cpt += fusion(tab, l, m, r);
  }
  return cpt;
}
예제 #6
0
void mem_free_aux(void *adr_courante, uint8_t puiss)
{
    
    //on regarde si le buddy est libre
    void * adr_buddy = get_adr_buddy(adr_courante, puiss);
    //il nous faut deux pointeurs décalés pour enlever un élément de la 
    //liste sans la détruire
    void * adr_parcours_tzl = tzl[puiss];
    void * adr_parcours_suivant_tzl = get_adr_suivant(adr_parcours_tzl);
    while((adr_parcours_tzl != NULL) && (adr_parcours_tzl != adr_buddy ) 
            && (adr_parcours_suivant_tzl != adr_buddy))
    {
        adr_parcours_tzl = get_adr_suivant(adr_parcours_tzl); 
        if(adr_parcours_tzl != NULL)
            adr_parcours_suivant_tzl = get_adr_suivant(adr_parcours_tzl);
    }
    //ici, on a trois cas possibles:
    //1. adr_parcours_tzl est null, dans ce cas, le buddy est non-libre
    //et on ajoute simplement la zone libre à tzl[puiss]
    //2. le buddy se trouve à adr_parcours_tzl, i.e. en tête de la liste
    //tzl[puiss], on l'enlève et on fait la fusion
    //3 le buddy se trouve à adr_parcours_suivant_tzl, on l'enlève de la 
    //liste et on fait la fusion
    if(adr_parcours_tzl == NULL)
    {
        set_header(adr_courante, puiss, tzl[puiss]);
        tzl[puiss] = adr_courante;
    } else if(adr_parcours_tzl == adr_buddy)
    {
        tzl[puiss] = adr_parcours_suivant_tzl; 
        void * adr_fusionnee_avec_buddy = fusion(adr_courante, adr_buddy, 
                puiss+1);
        mem_free_aux(adr_fusionnee_avec_buddy, puiss+1);
    } else if(adr_parcours_suivant_tzl == adr_buddy)
    {
        set_header(adr_parcours_tzl, puiss, get_adr_suivant(adr_buddy));
        void * adr_fusionnee_avec_buddy = fusion(adr_courante, adr_buddy, 
                puiss+1);
        mem_free_aux(adr_fusionnee_avec_buddy, puiss+1);
    } 
}
예제 #7
0
 void tri_fusion(objet *t,int d,int f)
 {
  	int m;
 if(d<f)
 {
 	 m=(d+f)/2;
 	  tri_fusion(t,d,m);
 	  tri_fusion(t,m+1,f);
 	  fusion(t,d,m,f);

 }
  }
예제 #8
0
파일: mm_alloc.c 프로젝트: lesego-reezy/hw3
void mm_free(void* ptr)
{
#ifdef MM_USE_STUBS
    free(ptr);
#else
    s_block_ptr b;
    if (valid_addr(ptr)){
        b = get_block(ptr);
        b->free = 1;
        if(b->prev && b->prev->free) b = fusion(b->prev);
        if(b->next){
            fusion(b);
        }
        else{
            if(b->prev) b->prev->next = NULL;
            else base = NULL;
            brk(b);
        }
    }
    //#error Not implemented.
#endif
}
예제 #9
0
void bf_free (void * ptr ){
  t_block b;
  if (valid_addr(ptr)){
    //we get the block address		      
    b = get_block(ptr);
    b->free = 1;
    //fusion with previous if possible	       
    if (b->prev && b->prev->free)
      b = fusion(b->prev);
    //then try to fusion with next	       
    if(b->next)
      fusion(b);
    else
      //if we're the last block, we release memory                                      
      if(b->prev)
	b->prev->next = NULL;
      else
	//no more block                                                                                                                                                            
	base = NULL;
    brk(b);//put break at chunk position                                                                                                                                         
  }
}
예제 #10
0
Image imageCollee (Image image1, Image image2, ListePoints decalage)
{
	Image imageFinale;
	int teinteMax;
	int* size;
	int** matImageFinale;
	char* type;
	if(strcmp(image1.type,"P2")==0 && strcmp(image2.type,"P2")==0) type="P2";
	if(strcmp(image1.type,"P3")==0 && strcmp(image2.type,"P3")==0) type="P3";
	teinteMax=max(image1.teinteMax,image2.teinteMax);
	size=taille(&decalage,image1.height,image2.height,image1.width,image2.width);
	matImageFinale=fusion(&decalage, size[0], size[1],image1,image2);
	imageFinale=creationImage(type,size[0],size[1],teinteMax, matImageFinale);
	
	return(imageFinale);
}
예제 #11
0
파일: main.c 프로젝트: huigao80/flyer
/*******************************************************************************
*
* 函数名  : main
* 负责人  : 彭鹏
* 创建日期: 20160112
* 函数功能: MPU9250 主函数
*
* 输入参数: 无
* 输出参数: 无
* 返回值  : 主程序永不返回
*
* 调用关系: 无
* 其 它   : 获取MPU9250数据 中断中完成
*
******************************************************************************/
int main(void)
{ 
    hardware_init();
#define _HARDWARE_DEBUG_
#ifdef _HARDWARE_DEBUG_
    hardware_test();

#else
    function_init();
    while(1)
    { 
        fusion();
        pid();
    }
#endif
}
예제 #12
0
파일: free.c 프로젝트: zayrt/my_malloc
void		free(void *ptr)
{
  t_addr	*tmp;

  tmp = g_block;
  if (ptr != NULL)
    {
      while (tmp != NULL && (void *)(tmp) + sizeof(t_addr) != ptr) // on parcourt la liste juska tomber sur le block a free
	tmp = tmp->next;
      if (tmp != NULL) // si le block a free a bien été trouver
	{
	  tmp->isFree = 1; // on met le isFree a 1 pr dire qu'il est libre et on verifie si on peut pas le fusionné ac celui d'avant ou d'aprés avec fusion
	  tmp = fusion(tmp);
	}
    }
}
예제 #13
0
// laser_scan
void laserCallback(const sensor_msgs::LaserScan::ConstPtr& scan_msg) 
{
	laser_scan_msg = *scan_msg;
	laser_scan_msg.header.frame_id = "robot";
	laser_scan_msg.intensities.assign(laser_scan_msg.ranges.size(), 0.0);
	hokuyo_scan_pub.publish(laser_scan_msg);

	// fusionscan
	if (kinect_scan_ready)
	{
		fusion(kinect_scan_msg, laser_scan_msg, fusion_scan_msg, param);
		fusion_scan_pub.publish(fusion_scan_msg);
		kinect_scan_ready = false;
	}	

	//laser_scan_ready = true;
}
예제 #14
0
파일: mymalloc.c 프로젝트: Sun42/malloc
void	insert_freelist(void *ptr)
{
  t_header	*to_insert;
  t_header	*cur;
  t_header	*prev;

  to_insert = (t_header *) ptr;

  prev = &start_free;
  cur = prev->next;
  while (to_insert > cur && cur != &start_free)
    {
      prev = cur;
      cur = cur->next;
    }
  to_insert->next = cur;
  prev->next = to_insert;
  fusion(&prev, &cur, &to_insert);
}
예제 #15
0
/**
* libère une zone mémoire précedemment allouée
* @param pnt_free: pointeur sur la zone mémoire à libérer
* @return void
*/
void		  free(void *pnt_free)
{
  t_block	*tmp;

  if (pnt_free == NULL)
    return;
  tmp = (t_block *)pnt_free - 1;
  if (tmp->pnt != pnt_free)
    return;
  pthread_mutex_lock(&list.mutex);
  tmp->free = true;
  fusion(&tmp);
  if (list.last->free == true)
  {
    if (list.last != list.beg)
  	{
  	  list.pnt_end_list = list.last;
  	  list.last->prev->next = NULL;
  	  list.last = list.last->prev;
  	}
  }
  deallocate_pageSize_memory();
  pthread_mutex_unlock(&list.mutex);
}
예제 #16
0
UEditorWindow::UEditorWindow(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::EditWindowClass),
      _confirmCloseMessageBox(0),
      _redoAction(0),
      _undoAction(0),
      _spaceNoteGeneration(false)
{

    this->setFocusPolicy(Qt::StrongFocus);
_startTime=0;
    _playViolon = false;
    _currentFile = NULL;
    _isPlaying=false;
setAcceptDrops(true);
USetting::Instance.init();

#ifdef QT_MODULE_NETWORK
UCheckUpdate * check = new UCheckUpdate(QUrl(URL_VERSION));
connect(check,SIGNAL(connected()),this,SLOT(onConnected()));
#endif


    setupAudio();
    setupUi();

            _currentFile = new UFile(this);// "songs/arkol - vingt ans/Arkol - vingt ans.txt");

            fileConnect();

            this->showSentenceWidget->setHScroll(0);

        connect(ui->vScroll,SIGNAL(valueChanged(int)),this,SLOT(onUpdateVScrollAndScale(int)));
        connect(ui->vSlider,SIGNAL(valueChanged(int)),this,SLOT(onUpdateVScrollAndScale(int)));
        connect(ui->vScroll,SIGNAL(sliderPressed()),this,SLOT(onUpdateVScrollAndScale()));
        connect(ui->vSlider,SIGNAL(sliderPressed()),this,SLOT(onUpdateVScrollAndScale()));
        //connect(ui->vScroll,SIGNAL(actionTriggered(int)),this,SLOT(changeVScroll(int)));

        connect(_hScroll,SIGNAL(valueChanged(int)),this,SLOT(changeHScroll(int)));
        //connect(ui->hSlider,SIGNAL(valueChanged(int)),this,SLOT(changeHSlider(int)));
        connect(_hScroll,SIGNAL(sliderPressed()),this,SLOT(changeHScroll()));
        //connect(ui->hSlider,SIGNAL(sliderPressed()),this,SLOT(changeHSlider()));
        connect(_hScroll,SIGNAL(pageStepChanged(int)),this,SLOT(changeHSlider(int)));





        connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(openFile()));

        connect(ui->actionEditHeaders,SIGNAL(triggered()),this,SLOT(editHeader()));
        connect(ui->actionApplyOffset,SIGNAL(triggered()),this,SLOT(openTiming()));
        connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
        connect(playAction, SIGNAL(triggered()), this, SLOT(tooglePlay()));
        connect(pauseAction, SIGNAL(triggered()), this, SLOT(tooglePlay()));
        connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecord()));
        connect(showSentenceWidget,SIGNAL(haveToStop()), this, SLOT(tooglePlay()));

        connect(this->ui->offsetSpinBox, SIGNAL(valueChanged(int)), showSentenceWidget, SLOT(setPreviousDisplayed(int)));
        this->ui->offsetSpinBox->setValue(2);
        connect(ui->actionSetNormalNote,SIGNAL(triggered()),showSentenceWidget, SLOT(setNormal()));
        connect(ui->actionSetFreeNote,SIGNAL(triggered()),showSentenceWidget, SLOT(setFree()));
        connect(ui->actionSetGoldNote,SIGNAL(triggered()),showSentenceWidget, SLOT(setGold()));

        connect(ui->actionMergeNotes,SIGNAL(triggered()),showSentenceWidget, SLOT(fusion()));
        connect(ui->actionSplitNote,SIGNAL(triggered()),showSentenceWidget, SLOT(split()));

        connect(ui->actionAddNote,SIGNAL(triggered()),showSentenceWidget, SLOT(nextClickAddNote()));
        connect(ui->actionAddSeparator,SIGNAL(triggered()),showSentenceWidget, SLOT(nextClickAddSeparator()));

        connect(ui->actionSave,SIGNAL(triggered()),this,SLOT(save()));
        connect(ui->actionSaveAs,SIGNAL(triggered()),this,SLOT(saveAs()));
        connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(newSong()));

        connect(ui->actionQuit,SIGNAL(triggered()),this,SLOT(close()));

        connect(&UInputManager::Instance,SIGNAL(spacePressEvent(void)),this,SLOT(tooglePlay()));

        connect(_wydget_timeline, SIGNAL(gapModified(double)),this, SLOT(gapModified(double)));

         connect(ui->actionDeleteNote,SIGNAL(triggered()),showSentenceWidget,SLOT(deleteNotes()));

        connect(ui->actionPreferences,SIGNAL(triggered()),&USetting::Instance,SLOT(showDialog()));

        connect(ui->actionMorphe,SIGNAL(triggered()),showSentenceWidget,SLOT(calquer()));


        connect(ui->actionLockTimings,SIGNAL(toggled(bool)),showSentenceWidget,SLOT(lockTime(bool)));

        connect(ui->actionCenter,SIGNAL(triggered()),this,SLOT(centerView()));

        connect(ui->actionHelp,SIGNAL(triggered()),this,SLOT(displayHelpScreen()));
        connect(ui->actionSendFeedback,SIGNAL(triggered()),this,SLOT(displayFeedback()));




        onUpdateVScrollAndScale();
        changeHScroll(0);


       // _currentFile = new UFile(this);
        this->showSentenceWidget->setLyrics(_currentFile->lyrics);
        _wydget_lyrics->setWidgetWords(showSentenceWidget);


        _undoAction = _currentFile->lyrics->history().createUndoAction(this->ui->menuEdit, tr("Annuler "));
        _undoAction->setShortcut(QKeySequence::Undo);
        _undoAction->setIcon(QIcon(":/images/undo.png"));
        this->ui->menuEdit->addAction(_undoAction);
        this->ui->toolBar->insertAction(this->ui->actionSetNormalNote, _undoAction);

        _redoAction = _currentFile->lyrics->history().createRedoAction(this->ui->menuEdit, tr("Refaire "));
        _redoAction->setShortcut(QKeySequence::Redo);
        _redoAction->setIcon(QIcon(":/images/redo.png"));
        this->ui->menuEdit->addAction(_redoAction);
        this->ui->toolBar->insertAction(this->ui->actionSetNormalNote, _redoAction);


        readLastFile();

        connect(ui->actionRecentFiles,SIGNAL(triggered()),this,SLOT(openLastFile()));



        readSettings();

        _spaceNote = new Recorder(this->showSentenceWidget);

        _autoSaveTimer = new QTimer(this);
          connect(_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));

          adaptNewFile();


}
예제 #17
0
파일: main.c 프로젝트: Pauchpock/UTC-GI
int main() {
    t_ludotheque *ludo1 = NULL, *ludo2 = NULL, *temp = NULL;
    t_jeu *jeu11, *jeu12, *jeu13, *jeu14, *jeu21, *jeu22, *jeu23;
    char inputUser;

    afficherMenu();

    while((inputUser = getchar()) != '6') {
        while (getchar()!='\n'); // clear input

        switch(inputUser) {
            case '1':
                supprimer_ludotheque(ludo1);
                ludo1 = creer_ludotheque();
                jeu11 = creer_jeu("Jeu de l'oie",HASARD,2,10,30);
                jeu12 = creer_jeu("Echecs",RPG,1,4,90);
                jeu13 = creer_jeu("Monopoly",PLATEAU,2,3,10);
                jeu14 = creer_jeu("Tarot",RPG,2,6,15);
                ajouter_jeu(ludo1,jeu11);
                ajouter_jeu(ludo1,jeu12);
                ajouter_jeu(ludo1,jeu13);
                ajouter_jeu(ludo1,jeu14);
                printf("Ludothèque 1 créée et remplie.\n");
                break;
            case '2':
                printf("Ludothèque n°1\n");
                affiche_ludotheque(ludo1);
                break;
            case '3':
                printf("Creation d'un jeu\n");
                if (ajouter_jeu(ludo1,saisir_jeu()) == 0)
                    printf("Le jeu n'a pas été ajouté (la ludothèque n'existe pas ?)\n");
                else
                    printf("Le jeu a bien été ajouté !\n");
                break;
            case '4':
                if (ludo1==NULL)
                    printf("Aucune requête ne peut être effectuée : la ludothèque n'existe pas.\n");
                else {
                    temp = saisir_requete(ludo1);
                    if (temp != NULL)
                        affiche_ludotheque(temp);
                    else
                        printf("Une erreur est survenue.\n");
                }
                break;
            case '5':
                if (ludo1 == NULL) {
                    ludo1 = creer_ludotheque();
                    jeu11 = creer_jeu("CTest",HASARD,2,10,30);
                    jeu12 = creer_jeu("ATest",RPG,1,4,90);
                    jeu13 = creer_jeu("BTest",PLATEAU,2,3,10);
                    jeu14 = creer_jeu("zTest",RPG,2,6,15);
                    ajouter_jeu(ludo1,jeu11);
                    ajouter_jeu(ludo1,jeu12);
                    ajouter_jeu(ludo1,jeu13);
                    ajouter_jeu(ludo1,jeu14);
                    printf("Ludothèque 1 créée et remplie.\n");
                }
                else
                    printf("Ludothèque n°1\n");
                affiche_ludotheque(ludo1);

                supprimer_ludotheque(ludo2);
                ludo2 = creer_ludotheque();
                jeu21 = creer_jeu("CTest",HASARD,2,10,30);
                jeu22 = creer_jeu("BBTest",RPG,1,4,90);
                jeu23 = creer_jeu("ZTest",PLATEAU,2,3,10);
                ajouter_jeu(ludo2,jeu21);
                ajouter_jeu(ludo2,jeu22);
                ajouter_jeu(ludo2,jeu23);
                printf("Ludothèque 2 créée et remplie.\n");
                affiche_ludotheque(ludo2);
                printf("\nFusion...\n");
                temp = fusion(ludo1,ludo2);
                if (temp != NULL) affiche_ludotheque(temp);
                break;
            default:
                printf("Mauvaise entrée. Veuillez taper 1, 2, 3, 4, 5 ou 6.\n");
                continue;
        }

        printf("\n");
        afficherMenu();
    }
    printf("Au revoir !\n");
    supprimer_ludotheque(ludo1);
    supprimer_ludotheque(ludo2);
    return 0;
}
예제 #18
0
int main ( int argc, char *argv[] )
{
	int x=2;
	int ligne=0;
	int colonne=0;
	int compteur=0;
	int compteur2=0;
	char option=' ';
	struct tab2D matrice1;
	struct tab2D matrice2;
	
	// argc doit etre  1 pour que le programme s'execute//
    if ( argc <= 1 ) 
    {
		signaler_erreur(0);
		return EXIT_SUCCESS;
    }

	if (!strcmp(argv[1], "-H"))
	{
		option='h';
	}
	else if (!strcmp(argv[1], "-V"))
	{
		option='v';
	}
    	
	while (argv[x]!=NULL)
	{
		// argv[1] , c est le nom du fichier 
		FILE *file = fopen( argv[x], "r" );
		
		if ( file == NULL)
		{
			if (!strcmp(argv[x], "-L")  || !strcmp(argv[x], "-C" )) 
			{
				break;
			}
			
			signaler_erreur(0);
			return EXIT_SUCCESS;		
		}

		fseek(file, 0L, SEEK_END);
		// si le fichier est vide, tableau vide
		if ( ftell(file) == 0 )
		{
			if (!strcmp(argv[x], "-L")  || !strcmp(argv[x], "-C" )) 
			{
				break;
			}
			
			signaler_erreur(1);
			return EXIT_SUCCESS;
		}

		rewind(file);
		// nombre de ligne dans le fichier
		ligne=nbre_lignes_fichier(file);
		//un tableau pour contenir le nombre de colonne dans chaque linge
		int tableau[ligne] ;
		compteur2=nbre_colonnes_fichier(file, tableau,ligne);
		// max du colonne
		colonne=taille_max_lignes(tableau , ligne);
		// ligne sans les zeros
		ligne=ligneAjuster (tableau, ligne);
		
		int tab2[ligne*compteur2] ;
		valeurTab(file,tab2);
		
		if(compteur==0)
		{
			matrice1=charger(file,tableau,ligne,colonne,tab2);
			matrice1.lignes=ligne;
			matrice1.colonnes=colonne;
		}
		else
		{
			matrice2=charger(file,tableau,ligne,colonne,tab2);
			matrice2.lignes=ligne;
			matrice2.colonnes=colonne;
			matrice1=fusion(matrice1,matrice2,option);
		}
			
		fclose( file );		
		compteur++;
		x++;
	}
	
	if (argc == (x))
	{
		affiche_Tab2D(matrice1);
		return EXIT_SUCCESS;
	}
	
 	if (!strcmp(argv[x], "-L")  || !strcmp(argv[x], "-C" )) 
	{
	    if (erreurOption(argv,x) == 1)
		{
			return EXIT_SUCCESS;
		}
		
 		matrice1 = filter(matrice1, control(argv, matrice1.colonnes, 'C'), control(argv, matrice1.lignes, 'L'));			
		affiche_Tab2D(matrice1);
		
		return EXIT_SUCCESS;
 	}

}
bool SensorService::threadLoop()
{
    ALOGD("nuSensorService thread starting...");

    const size_t numEventMax = 16;
    const size_t minBufferSize = numEventMax + numEventMax * mVirtualSensorList.size();
    sensors_event_t buffer[minBufferSize];
    sensors_event_t scratch[minBufferSize];
    SensorDevice& device(SensorDevice::getInstance());
    const size_t vcount = mVirtualSensorList.size();

    ssize_t count;
    do {
        count = device.poll(buffer, numEventMax);
        if (count<0) {
            ALOGE("sensor poll failed (%s)", strerror(-count));
            break;
        }
/* fix err PTR when count=0  -- by liaoxl.lenovo 1.22.2013 start */
#if 0
        recordLastValue(buffer, count);

        // handle virtual sensors
        if (count && vcount) {
            sensors_event_t const * const event = buffer;
            const DefaultKeyedVector<int, SensorInterface*> virtualSensors(
                    getActiveVirtualSensors());
            const size_t activeVirtualSensorCount = virtualSensors.size();
            if (activeVirtualSensorCount) {
                size_t k = 0;
                SensorFusion& fusion(SensorFusion::getInstance());
                if (fusion.isEnabled()) {
                    for (size_t i=0 ; i<size_t(count) ; i++) {
                        fusion.process(event[i]);
                    }
                }
                for (size_t i=0 ; i<size_t(count) && k<minBufferSize ; i++) {
                    for (size_t j=0 ; j<activeVirtualSensorCount ; j++) {
                        if (count + k >= minBufferSize) {
                            ALOGE("buffer too small to hold all events: "
                                    "count=%u, k=%u, size=%u",
                                    count, k, minBufferSize);
                            break;
                        }
                        sensors_event_t out;
                        SensorInterface* si = virtualSensors.valueAt(j);
                        if (si->process(&out, event[i])) {
                            buffer[count + k] = out;
                            k++;
                        }
                    }
                }
                if (k) {
                    // record the last synthesized values
                    recordLastValue(&buffer[count], k);
                    count += k;
                    // sort the buffer by time-stamps
                    sortEventBuffer(buffer, count);
                }
            }
        }

        // send our events to clients...
        const SortedVector< wp<SensorEventConnection> > activeConnections(
                getActiveConnections());
        size_t numConnections = activeConnections.size();
        for (size_t i=0 ; i<numConnections ; i++) {
            sp<SensorEventConnection> connection(
                    activeConnections[i].promote());
            if (connection != 0) {
                connection->sendEvents(buffer, count, scratch);
            }
        }
    } while (count >= 0 || Thread::exitPending());

#else
        else if(count == 0)
bool SensorService::threadLoop()
{
    LOGD("nuSensorService thread starting...");

    const size_t numEventMax = 16 * (1 + mVirtualSensorList.size());
    sensors_event_t buffer[numEventMax];
    sensors_event_t scratch[numEventMax];
    SensorDevice& device(SensorDevice::getInstance());
    const size_t vcount = mVirtualSensorList.size();

    ssize_t count;
    do {
        count = device.poll(buffer, numEventMax);
        if (count<0) {
            LOGE("sensor poll failed (%s)", strerror(-count));
            break;
        }

        recordLastValue(buffer, count);

        // handle virtual sensors
        if (count && vcount) {
            sensors_event_t const * const event = buffer;
            const DefaultKeyedVector<int, SensorInterface*> virtualSensors(
                    getActiveVirtualSensors());
            const size_t activeVirtualSensorCount = virtualSensors.size();
            if (activeVirtualSensorCount) {
                size_t k = 0;
                SensorFusion& fusion(SensorFusion::getInstance());
                if (fusion.isEnabled()) {
                    for (size_t i=0 ; i<size_t(count) ; i++) {
                        fusion.process(event[i]);
                    }
                }
                for (size_t i=0 ; i<size_t(count) ; i++) {
                    for (size_t j=0 ; j<activeVirtualSensorCount ; j++) {
                        sensors_event_t out;
                        if (virtualSensors.valueAt(j)->process(&out, event[i])) {
                            buffer[count + k] = out;
                            k++;
                        }
                    }
                }
                if (k) {
                    // record the last synthesized values
                    recordLastValue(&buffer[count], k);
                    count += k;
                    // sort the buffer by time-stamps
                    sortEventBuffer(buffer, count);
                }
            }
        }

        // send our events to clients...
        const SortedVector< wp<SensorEventConnection> > activeConnections(
                getActiveConnections());
        size_t numConnections = activeConnections.size();
        for (size_t i=0 ; i<numConnections ; i++) {
            sp<SensorEventConnection> connection(
                    activeConnections[i].promote());
            if (connection != 0) {
                connection->sendEvents(buffer, count, scratch);
            }
        }
    } while (count >= 0 || Thread::exitPending());

    LOGW("Exiting SensorService::threadLoop => aborting...");
    abort();
    return false;
}
예제 #21
0
ENREGISTRER_PROBLEME(205, "Dice Game")
{
    // Peter has nine four-sided (pyramidal) dice, each with faces numbered 1, 2, 3, 4.
    // Colin has six six-sided (cubic) dice, each with faces numbered 1, 2, 3, 4, 5, 6.
    //
    // Peter and Colin roll their dice and compare totals: the highest total wins. The result is a
    // draw if the totals are equal.
    //
    // What is the probability that Pyramidal Pete beats Cubic Colin? Give your answer rounded to
    // seven decimal places in the form 0.abcdefg
    vecteur D4 { 1, 2, 3, 4 };
    vecteur D6 { 1, 2, 3, 4, 5, 6 };

    const std::map<nombre, nombre> Zero {{ 0, 1 }};

    auto Peter1 = fusion(Zero, D4);
    auto Peter2 = fusion(Peter1, Peter1);
    auto Peter4 = fusion(Peter2, Peter2);
    auto Peter8 = fusion(Peter4, Peter4);
    auto Peter9 = fusion(Peter8, Peter1);

    auto Colin1 = fusion(Zero, D6);
    auto Colin2 = fusion(Colin1, Colin1);
    auto Colin4 = fusion(Colin2, Colin2);
    auto Colin6 = fusion(Colin4, Colin2);

    nombre somme = 0;
    for (auto p: Peter9)
        for (auto c: Colin6)
        {
            if (p.first > c.first)