Beispiel #1
11
int main(int argc, char *argv[])
{
    clock_t start, end, elapsed;
    FILE *entrada, *entrada2, *copia, *consulta, *saida;
    Words *words=NULL, *aux=NULL;
    char linha[1024],linha2[1024];
    char delimiters[] = " .,;:!?'\n'-*";
    char *token=NULL, *cp, c, n,aspas=(char)39,tab=(char)9;
    int i=0, ok=0,okay=0;



    if (argc != 5)         //numero de parametros corretos
    {
        printf("Numero incorreto de parametros.\n Sintaxe: copia arq_origem arq_destino\n");
        return 1;
    }

    entrada = fopen(argv[1], "r");       //abre o primeiro arquivo (arquivo de entrada)
    copia = fopen("facil.txt", "w");     //arquivo auxiliar
    consulta = fopen(argv[2], "r");      //abre o arquivo de consulta
    saida = fopen (argv[3], "w");        //abre ou cria ou arquivo de saida

    if(!entrada)                         //caso arquivos não existam
    {
        printf("ERRO\n");
        return 1;
    }
    if(!consulta)
    {
        printf("ERRO\n");
        return 1;
    }

    while(!feof(entrada))                //cria arquivo auxiliar a ser usado sem pontos, e caracteres separadores especiais
    {
        c=fgetc(entrada);
        if((c==',')||(c==':')||(c==';')||(c=='.')||(c=='-')||(c==EOF)||(c=='!')||(c=='?')||(c=='"')||(c=='*')||(c==aspas)||(c=='(')||(c==')')||(c=='_') || c==tab)
            c=' ';

        fputc(tolower(c),copia);
    }

    fclose(entrada);
    fclose(copia);


    entrada = fopen("facil.txt", "r");
    entrada2 = fopen("facil.txt", "r");

    if(!entrada)
        printf("ERRO\n");

    ///AQUI COLOCA OS ELEMENTOS NA ABP
    else
    {
        while(fgets(linha,1024, entrada))
        {

            stolower(linha);   //função que transforma tudo para minusculo

            cp = strdup(linha);

            token = strtok (cp, delimiters);    //pega tokens (usa cp como auxiliar para caso o ponteiro fique iinvalido em algum momento)
            while(token!=NULL)
            {
                words = abp(words,token);          //insere na abp
                token = strtok (NULL, delimiters); //pega proximo token

            }
        }
    }
    words = abp(words, "(NULL)");  //insere a palavra "(NULL)" na abp, para ser apontada pela ultima palavra do texto


    aux = words;                   //ponteiro aux fixo no inicio da ABP
    fseek(entrada, 0, SEEK_SET);
    n=fscanf(entrada2,"%s",linha2);//inicia o arquivo auxiliar uma palavra na frente


    ///AQUI COLOCA OS ELEMTTOS NO CAMPO LISTA DO NÓ DA ABP
    while(n != EOF)
    {
        words = aux;

        n=fscanf(entrada2,"%s",linha2);
        c=fscanf(entrada,"%s",linha);

        if(n == EOF)
        {
            words=busca(words,linha);                               //caso seja a ultima palavra do texto, busca ela na árvore
            words->vizinhos=insere_lista(words->vizinhos,"(NULL)"); //insere ela apontando também para ("NULL")
            break;
        }

        words=busca(words,linha);                             //busca a palavra no texto

        words->vizinhos=insere_lista(words->vizinhos,linha2); //insere ela apontando para sua sucessora
    }

   // printf("iuti");
    fclose(entrada2);
    fclose(entrada);
    moda(aux,aux);  //calcula a medida estatística para cada elemento da lista
    ordena(aux);    //ordena a lista pelo valor de sua "moda"

    ///AQUI FAZ A BUSCA E GERA SAIDA
    start=clock();
    fseek(consulta,0,SEEK_SET);
    while(fgets(linha,1023,consulta))
    {

        words=aux;                     //volta para o inicio da árvore
        strcpy(linha, strtok(linha,delimiters)); //paga pegar a linha correta
        words=busca(words,linha);      //vai para o lugar da arvore daquela palavra

        if(words!=NULL)
        {
            fputs("Consulta: ", saida);
            fputs(words->id, saida);
            fputs("\n", saida);

            i=0;
            while(words->vizinhos!=NULL && i<atoi(argv[4]))
            {
                fprintf(saida,"Sugestao: %s",words->vizinhos->id);  //printa tudo bonitinho
                okay=strlen(words->vizinhos->id);
                for(ok=0; ok<30-okay; ok++)
                    fprintf(saida," ");
                fprintf(saida,"(%lf)\n",words->vizinhos->moda);
                words->vizinhos = words->vizinhos->prox;
                i++;
            }
            fputs("\n", saida);

        }
    }

    fputs("\n", saida);
    end=clock(); //lê o tempo final
    elapsed = 1000 * (end - start) / (CLOCKS_PER_SEC);
    fprintf(saida,"Gasto: %ld ms", elapsed); //mostra o tempo final em ms

    fclose(consulta);
    fclose(saida);

    //Desenha(aux,1);

    deltree(aux);

    return 0;
}
Beispiel #2
0
int main() {
	ll r;
	int T,i;
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&N);
		for(i=0;i<N;i++) scanf("%d",&a[i]);
		n=100100;
		deltree();
		for(i=0;i<N;i++) {
			left[i]=read(a[i]);
			left2[i]=read(100000)-read(a[i]-1);
			update(1,a[i]);
		}
		deltree();
		for(i=N-1;i>=0;i--) {
			/* how many numbers greater than or equal to a[i]? */
			right[i]=read(100000)-read(a[i]-1);
			right2[i]=read(a[i]);
			update(1,a[i]);
		}
		for(r=i=0;i<N;i++) r+=(ll)left[i]*right[i]+(ll)left2[i]*right2[i];
		printf("%lld\n",r);
	}
	return 0;
}
Beispiel #3
0
void deltree(node * tree){
    if (tree){
        deltree(tree->left);
        deltree(tree->right);
        free(tree);
    }
}
Beispiel #4
0
// username�û���֤ʧ�ܵĴ�����������û�������Ŀǰ��δʹ������������� added by interma@BMY 2005.5.16
void register_fail(char *userid)
{
	int id;
	strcpy(genbuf, userid);
	id = getuser(genbuf);

	if (lookupuser.userid[0] == '\0' || !strcmp(lookupuser.userid, "SYSOP")) {
		return;
	}

	sprintf(genbuf, "mail/%c/%s", mytoupper(lookupuser.userid[0]),
		lookupuser.userid);
	deltree(genbuf);
	sprintf(genbuf, "home/%c/%s", mytoupper(lookupuser.userid[0]),
		lookupuser.userid);
	deltree(genbuf);
	lookupuser.userlevel = 0;
	strcpy(lookupuser.address, "");
	strcpy(lookupuser.username, "");
	strcpy(lookupuser.realname, "");
	strcpy(lookupuser.ip, "");
	strcpy(lookupuser.realmail, "");
	lookupuser.userid[0] = '\0';
	substitute_record(PASSFILE, &lookupuser, sizeof (lookupuser), id);
	setuserid(id, lookupuser.userid);
}
Beispiel #5
0
void deltree(node * root)
{
     if(root != NULL)
     {
             deltree(root -> left);
             deltree(root -> right);
             free(root);
     }
}
Beispiel #6
0
/*Recursão para liberar toda a memória do final*/
void deltree(Words *tree)
{
    if (tree)
    {
        deltree(tree->esq);
        deltree(tree->dir);
        free(tree);
    }
}
Beispiel #7
0
Datei: node.c Projekt: 8l/scc
void
deltree(Node *np)
{
	if (!np)
		return;
	deltree(np->left);
	deltree(np->right);
	delnode(np);
}
Beispiel #8
0
/* deletes the tree */
void deltree ( struct AVLNode *root )
{
    if ( root != NULL )
    {
        deltree ( root -> left ) ;
        deltree ( root -> right ) ;
    }
    free ( root ) ;
}
void bPlusTree::deltree(bPlusTreeNode *root)
{
	int i;
	if (root != NULL)
	{
		for (i = 0; i < root->count; i++)
		{
			deltree(root->child[i]);
			delete (root->child[i]);
		}
		deltree(root->child[i]);
		delete (root->child[i]);
	}
}
Beispiel #10
0
 main( )
{
    struct AVLNode *avl = NULL ;
    int h ;

   // clrscr( ) ;

    avl = buildtree ( avl, 20, &h ) ;
    avl = buildtree ( avl, 6, &h ) ;
    avl = buildtree ( avl, 29, &h ) ;
    avl = buildtree ( avl, 5, &h ) ;
    avl = buildtree ( avl, 12, &h ) ;
    avl = buildtree ( avl, 25, &h ) ;
    avl = buildtree ( avl, 32, &h ) ;
    avl = buildtree ( avl, 10, &h ) ;
    avl = buildtree ( avl, 15, &h ) ;
    avl = buildtree ( avl, 27, &h ) ;
    avl = buildtree ( avl, 13, &h ) ;

    printf ( "\nAVL tree:\n" ) ;
    display ( avl ) ;

    avl = deldata ( avl, 20, &h ) ;
    avl = deldata ( avl, 12, &h ) ;

    printf ( "\nAVL tree after deletion of a node:\n" ) ;
    display ( avl ) ;

    deltree ( avl ) ;

   // getch( ) ;
    return 0;
}
Beispiel #11
0
main()
{
      node *ptr,
           *head;
      int f[30], fr, u, i, n, total = 0;
      char alpha2[30];
      node *a[30];
            
      printf("Banyak huruf : ");
      scanf("%d", &n);
      for(i = 0; i < n; i++)
      {
            printf("input huruf dan frekuensi :\n");
            scanf("%s %d", alpha2, &fr);
            a[i] = create(alpha2, fr);
      }
      
      for( ;n > 1; n--)
      {
              sort(a, n);
              u = a[0] -> fre + a[1] -> fre;
              
              strcpy(alpha2, a[0] -> alpha);
              strcat(alpha2, a[1] -> alpha);
              ptr = create(alpha2, u);
              ptr -> right = a[1];
              ptr -> left = a[0];
              a[0] = ptr;
              sright(a, n);
      }
      
      assign(a[0], f, 0);
      
      deltree(a[0]);
}
Beispiel #12
0
static void deltree(link_t *t)
{
    if (*t == NULL) {
        return ;
    }

    if ((*t)->left != NULL) {
        deltree(&(*t)->left);
    }

    if ((*t)->right != NULL) {
        deltree(&(*t)->right);
    }

    dellink(t);
}
Beispiel #13
0
int monster::AIfindpath(HERO *p,short r)
{
	mtime.week=-1;
	mtime.range=p->range;
	if(t!=0)
		deltree(t);
	if((t=(tree *)malloc(sizeof(tree)))==0)return 0;
	t->x=p->x;
	t->y=p->y;
	t->J=p->job;
	t->R=p->movement;
	t->D=i;
	t->f=0;
	for(int j=0;j<4;j++)
		t->c[j]=0;
	find2(t);

	if(mtime.week==-1)return 0;
	else
	{
		howtogo(mtime.x,mtime.y);
		short i=1,dr=mtime.range;
		while(1)
		{
		   if((dr-=eff2[maze[pt[i].y][pt[i].x]*4+p->job])<0)break;
		   i++;
		}
		moves=i;
		return 1;
	}
}
Beispiel #14
0
void btree_finalize(T *t)
{
    if (*t == NULL) {
        return ;
    }

    deltree(&(*t)->root);
    free(*t);
    *t = NULL;
}
Beispiel #15
0
void fastmarch(void) 
/*< fast marching time-to-depth conversion >*/
{
  int i,j,ii,jj,ind,m,mm;
  char ch,dir;

  for( i=0;i<nx;i++ ) {
      ind=i+nx;
      ch=solve(ind,'z',1);
      if( ch=='s') {
	  addtree(ind);
	  *(ms+ind)='c';
      }
  }
  
  while( count > 0 ) {
    ind=(*(r+1));
    j=ind/nx;
    i=ind%nx;
    *(ms+ind)='a';
    deltree();
    /*(      printf("accept %i, %i\t",i,j);*/
    /* update the nearest neighbors */
    for( m=0; m<4; m++ ) {
      ch='n';
      dir=(m<2) ? 'x' : 'z';
      mm=2*(m%2)-1;
      if( dir=='x' ) {
	ii=i+mm;
	jj=j;
	if( ii>=0 && ii<nx ) ch='y';
      }
      else if( dir=='z' ) {
	ii=i;
	jj=j+mm;
	if( jj>=0 && jj<nz ) ch='y';
      }
      if( ch=='y' ) {
	ind=ii+jj*nx;
	if( *(ms+ind)=='a' ) ch='n';
	else {
	  ch=solve(ind,dir,mm);
	  if( ch=='s' ) {
	    if( *(ms+ind)=='u' ) {
	      addtree(ind);
	      *(ms+ind)='c';
	    }
	    else updtree(ind);
	    /* printf("(%i,%i) is updated; t0=%.4e\tx0=%.4e\tv=%.4e\t q=%.4e\n",ii,jj,*(t0+ind),*(x0+ind),*(v+ind),*(q+ind));*/
	  }
	}
      }
    }
  }
}
MyModel::~MyModel()
{
    while (!tempDirs->isEmpty()) {
        deltree(QDir::temp().absoluteFilePath(tempDirs->last()));
        tempDirs->removeLast();
    }
    delete tempDirs;
    if (fileSystem) {
        delete fileSystem;
    }
}
Beispiel #17
0
int main(){
	struct tnode *root = NULL;

	char ch, fakech, quit = 1;
	int n;
	do{
		printf("\n");
		printf("1 - Add\n");
		printf("2 - Inorder Print\n");
		printf("3 - Preorder Print\n");
		printf("4 - Delete Tree\n");
		printf("0 - Quit\n");
		printf("\n");
		printf("Enter choice: ");

		scanf("%c", &ch);
		scanf("%c", &fakech);

		switch(ch){
			case '1':
				printf("Enter element: ");
				scanf("%d", &n);
				scanf("%c", &fakech);

				root = addnode(root, n);

				break;

			case '2':
				printf("Tree: ");
				inorder(root);
				printf("\n");
				break;

			case '3':
				printf("Tree: ");
				preorder(root);
				printf("\n");
				break;

			case '4':
				deltree(root);
				root = NULL;
				printf("Deleted!\n");
				break;

			case '0':
				quit = 0;
				break;
		}
	} while(quit);

	return 0;
}
void main()
{       int n,digit,g,o;
	node *insert(node *,int );
	void preorder(node *P);
	void inorder(node *P);
	void postorder(node *P);
	void deltree(void);
	do
	{
	printf("\tWhat do you want to do? \n");
	printf("\t\t 1) insert the element:\n");
	printf("\t\t 2) preorder traversal:\n");
	printf("\t\t 3) inorder traversal:\n");
	printf("\t\t 4) postorder traversal:\n");
	printf("\t\t 5) delete \n");
	scanf("%d",&n);
	switch(n)
	{
		case 1: printf("\tEnter the digit:\n");
			scanf("%d",&digit);
			while(digit!=0)
			{
				P=insert(P,digit);
				scanf("%d",&digit);
			}
			break;
		case 2: printf("\tThe preorder traversal is as follows:\n");
			preorder(P);
			getch();
			break;
		case 3: printf("\t The inorder traversal is as follows:\n");
			inorder(P);
			getch();
			break;
		case 4: printf("\t The postorder traversal is as follows:\n");
			postorder(P);
			getch();
			break;
		case 5: printf("\t delete\n");
			deltree();
			break;
	 }
		printf("\t DO you want to continue:\n");
		printf("\t 1)YES\n");
		printf("\t 2)NO\n");
		scanf("%d",&g);
		clrscr();

	 }while(g==1);
}
Beispiel #19
0
int cmd_deltree(char **arg)
{	
	char *ruta = arg[1];
	if (!ruta) {
		printf("Falta un operando\n");
		show_help(arg[0]);
		return -1;
	}
	
	deltree(ruta);
	//printf("Borrando.. %s\n", ruta);
	borrar_archivo(ruta);
	
	return 0;
}
Beispiel #20
0
void main()
{
    node *root;
    node *tmp;
    //int i;
    int vetor[] = {50, 95, 180, 34, 119, 11, 123, 62, 64, 199};
    root = NULL;
    /* Inserting nodes into tree */
    int i;
    for(i = 0; i < 10; i++) {
        insert(&root, vetor[i], 0);
    }
    /*int altura = (7/2) - (1);
    insert(&root, 9,0);
    insert(&root, 4,0);
    insert(&root, 15,0);
    insert(&root, 6,0);
    insert(&root, 12,0);
    insert(&root, 17,0);
    insert(&root, 2,0);*/

    /* Printing nodes of tree */
    printf("Pre Order Display\n");
   // printf("%d\n", print_preorder(root , root->data, altura));

    printf("In Order Display\n");
    print_inorder(root);

    printf("Post Order Display\n");
    print_postorder(root);

    //isLeaf(root);
    /* Search node into tree */
    tmp = search(&root, 62);
    //printf("%d\n", tmp);
    if (tmp)
    {
        printf("Searched node=%d\n", tmp->data);
    }
    else
    {
        printf("Data Not found in tree.\n");
    }

    /* Deleting all nodes of tree */
    deltree(root);
}
Beispiel #21
0
Datei: node.c Projekt: 8l/scc
Node *
delstmt(void)
{
	Node *next, *prev;

	next = curstmt->next;
	prev = curstmt->prev;
	if (next)
		next->prev = prev;
	if (prev)
		prev->next = next;
	else
		curfun->u.stmt = next;
	deltree(curstmt);

	return curstmt = next;
}
Beispiel #22
0
int deltree(char *ruta)
{
	struct dirent **dirlist;
	int n = scandir(ruta, &dirlist, NULL, alphasort);
	if (n < 0) {
		perror("scandir");
		return -1;
	}
	
	int i;
	for(i=0; i<n; i++){
		//directorio? recursividad
		char *dirname = dirlist[i]->d_name;
		char *new_path = concatenar_carpeta(ruta, dirname);
		
		if(!new_path){
			perror("Concatenar_carpeta");
			break;
		}
		
		if(is_dir(new_path))
		{	  
			if((strcmp(dirname, "..")!=0) &&
			   (strcmp(dirname, ".")!=0)) 
			{
				deltree(new_path);
				//printf("Borrando.. %s\n", new_path);
				borrar_archivo(new_path);
			}
		}
		else
		{
			//printf("Borrando.. %s\n", new_path);
			int borrado = borrar_archivo(new_path);
			if (borrado != 0)
				printf("Imposible borrar:%s\n", new_path);
		}	
		free(new_path);
		free(dirlist[i]);
	}
	
	free(dirlist);
		
	return 0;
}
Beispiel #23
0
int main( )
{
	struct thtree *th_head ;

	th_head = NULL ;  /* empty tree */

	insert ( &th_head, 11 ) ;
	insert ( &th_head, 9 ) ;
	insert ( &th_head, 13 ) ;
	insert ( &th_head, 8 ) ;
	insert ( &th_head, 10 ) ;
	insert ( &th_head, 12 ) ;
	insert ( &th_head, 14 ) ;
	insert ( &th_head, 15 ) ;
	insert ( &th_head, 7 ) ;

	system ( "cls" ) ;
	printf ( "Threaded binary tree before deletion:\n" ) ;
	inorder ( th_head ) ;

	del ( &th_head, 10 ) ;
	printf ( "\n" ) ;
	printf ( "Threaded binary tree after deletion:\n" ) ;
	inorder ( th_head ) ;

	del ( &th_head, 14 ) ;
	printf ( "\n" ) ;
	printf ( "Threaded binary tree after deletion:\n" ) ;
	inorder ( th_head ) ;

	del ( &th_head, 8 ) ;
	printf ( "\n" ) ;
	printf ( "Threaded binary tree after deletion:\n" ) ;
	inorder ( th_head ) ;

	del ( &th_head, 13 ) ;
	printf ( "\n" ) ;
	printf ( "Threaded binary tree after deletion:\n" ) ;
	inorder ( th_head ) ;

	deltree ( &th_head ) ;

	return 0 ;
}
int		main(int ac, char **av)
{
	node *root;
	//node *tmp;
	root = NULL;
	//tmp = NULL;
	node *opti;
	opti = NULL;

	if (ac == 1)
	{
		ft_putstr("Erreur : manque les parametres");
		return (0);
	}

	int i;
	i = 1;
	while (i < ac)
	{
		insert(&root, ft_atoi(av[i]));
		i++;
	}

	//organize(&root);
	affiche_arbre_rec(root);
	ft_putchar('\n');
	opti_arbre_rec(root, &opti);
	affiche_arbre_rec(opti);
	ft_putstr("\nresultat de la recherche : ");
	ft_putnbr(recherche_arbre(&root, 85)->id);
	//affiche_arbre_rec(root, &opti);

	/* Search node into tree */
	/*
	tmp = search(&root, 9);
	if (tmp)
		printf("\nSearched node = %d\n", tmp->data);
	else
		printf("\nData Not found in tree.\n");
	*/
	/* Deleting all nodes of tree */
	deltree(root);
}
Beispiel #25
0
int main()
{
    
    node *tmp;

    root = NULL;
    /* Inserting nodes into tree */
    insert(&root, 9);
    insert(&root, 4);
    insert(&root, 15);
    insert(root, 6);
    insert(&root, 12);
    insert(&root, 17);
    insert(&root, 2);

    /* Printing nodes of tree */
    printf("Pre Order Display\n");
    print_preorder(root);

    printf("In Order Display\n");
    print_inorder(root);

    printf("Post Order Display\n");
    print_postorder(root);

    /* Search node into tree */
    tmp = search(&root, 4);
    if (tmp)
    {
        printf("Searched node=%d\n", tmp->data);
    }
    else
    {
        printf("Data Not found in tree.\n");
    }

    /* Deleting all nodes of tree */
    deltree(root);

    return 0;
}
Beispiel #26
0
int main()
{
  printf("*** Ex 5.7.10 ***\n");
 
  node *root;
  node *tmp;
  //int i;

  root = NULL;
  /* Inserting nodes into tree */
  insert(&root, 9);
  insert(&root, 4);
  insert(&root, 15);
  insert(&root, 6);
  insert(&root, 12);
  insert(&root, 17);
  insert(&root, 2);

  printf("In Order Display\n");
  print_inorder(root);

  /* Search node into tree */
  tmp = search(&root, 4);
  if (tmp)
  {
    printf("Searched node=%d\n", tmp->data);
  }
  else
  {
    printf("Data Not found in tree.\n");
  }

  /* Deleting all nodes of tree */
  deltree(root);

  printf("\n\nProgram Terminated...\n");

  return 0;
}
Beispiel #27
0
void deltree(const char *dir)
{
    struct dirent *pdir;
    struct stat st;
    DIR *d;
    char *path;

    if (!dir)
        return;

    path =(char *)my_malloc(sizeof(char)*256);
    d = opendir(dir);

    while( (pdir=readdir(d)) )
    {
        if (strcmp(pdir->d_name,".") == 0)
            continue;
        if (strcmp(pdir->d_name,"..") == 0)
            continue;

        strcpy(path, dir);
        if (path[strlen(path)-1] != '/')
            strcat(path, "/");
        strcat(path, pdir->d_name);
        if (!(lstat(path, &st)>=0))
            continue;
        if (st.st_mode&S_IFDIR)
            deltree(path);
        else if (st.st_mode&S_IFREG)
            remove(path);
    }

    free(path);
    rmdir(dir);
    return;
}
Beispiel #28
0
int     bsolve(
	int m, 
	double *sy,
	int *iy,
	int *pny
)
{
        int i, j, jr, ny=*pny;
        int k, row, row2, consistent=TRUE;
        double beta;
        double eps;

	static double *y=NULL, *yy=NULL;
	static int    *tag=NULL;
	static int  currtag=1;

	double starttime, endtime;

	starttime = (double) clock();

	if (   y  == NULL) CALLOC(   y, m,   double);
	if (  yy  == NULL) CALLOC(  yy, m,   double);
	if ( tag  == NULL) CALLOC( tag, m,   int);

	if ( newcol == NULL) MALLOC(  newcol, m, double );
	if (inewcol == NULL) MALLOC( inewcol, m, int );

	for (k=0; k<ny; k++) {
	    i = irowperm[iy[k]];
	    y[i] = sy[k];
	    tag[i] = currtag;
	    addtree(i);
	}

        if (rank < m) eps = EPSSOL * maxv(sy,ny);

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  L  y                                    */

        for (i=getfirst(); i < rank && i != -1; i=getnext()) {
                beta = y[i];
                for (k=0; k<degL[i]; k++) {
                        row = L[i][k].i;
			if (tag[row] != currtag) {
			    y[row] = 0.0;
			    tag[row] = currtag;
			    addtree(row);
			}
                        y[row] -= L[i][k].d * beta;
                }
        }

        /*------------------------------------------------------+
        | Apply refactorization row operations.                */

	for (jr=0; jr<nr; jr++) {

            /*--------------------------------------------------+
            | Gather sparse vector.                            */

	    k=0;
            for (j=col_outs[jr]; j<=imaxs[jr]; j++) {
		if (tag[j] == currtag) {
		    sy[k] = y[j];
		    iy[k] =   j;
		    k++;
		    tag[j]--;
		    deltree(j); 
		}
	    }
	    ny = k;

            /*--------------------------------------------------+
            | Scatter and permute.                             */

	    for (k=0; k<ny; k++) {
		i = iperm[jr][iy[k]];
		y[i] = sy[k];
		tag[i] = currtag;
		addtree(i);
	    }

            /*--------------------------------------------------+
            | Apply row operations.                            */

	    row = rows[jr];
	    for (k=0; k<ngauss[jr]; k++) {
		row2 = row_list[jr][k];
		if (tag[row] != currtag) {
		    y[row] = 0.0;
		    tag[row] = currtag;
		    addtree(row);
		}
		if (tag[row2] == currtag) {
		    y[row] -= gauss[jr][k] * y[row2];
		}
	    }

	}

        /*------------------------------------------------------+
	|                                       -1              |
        | Set aside sparse intermediate vector L  P a  for      |
	|                                            j          |
        | refactorization routine.                             */

	nnewcol = 0;
	for (i=getfirst(); i != -1; i=getnext()) {
	    if ( ABS(y[i]) > EPS ) {
	        newcol [nnewcol] = y[i];
	        inewcol[nnewcol] = i;
	        nnewcol++;
	    }
	}

        /*------------------------------------------------------+
        |               -1                                      |
        |       y  <-  U  y                                    */

        for (i=getlast(); i >= rank && i != -1; i=getprev()) {
                if ( ABS( y[i] ) > eps ) consistent = FALSE;
                y[i] = 0.0;
        }
        for ( ; i>=0; i=getprev()) {
                beta = y[i]/diag[i];
                for (k=0; k<degU[i]; k++) {
			row = U[i][k].i;
			if (tag[row] != currtag) {
			    y[row] = 0.0;
			    tag[row] = currtag;
			    addtree(row);
			}
			y[row] -= U[i][k].d * beta;
                }
                y[i] = beta;
        }

	ny = 0;
	for (i=getfirst(); i != -1; i=getnext()) {
	    if ( ABS(y[i]) > EPS ) {
	        sy[ny] = y[i];
	        iy[ny] = colperm[i];
	        ny++;
	    }
	}
	*pny = ny;

	currtag++;
	killtree();

	endtime = (double) clock();
	cumtime += endtime - starttime;

        return consistent;
}
Beispiel #29
0
int
bbsdelmail_main()
{
	int fd;
	struct fileheader f;
	struct fileheader *fhmw, *fhw;
	char path[80], file[80], *ptr, list[40][20], fullpath[256];
	int num, ndelfile = 0;
	struct stat st;
	int count;
	int wcount, wstart;
	int spam;
	struct yspam_ctx *yctx;
	html_header(1);
	//check_msg();
	if (!loginok || isguest)
		http_fatal("您尚未登录");
	changemode(RMAIL);

	spam=atoi(getparm("spam"));
	strsncpy(list[ndelfile], getparm("file"), 20);
	if (list[ndelfile][0] == 'M')
		ndelfile++;
	for (num = 0; num < 40 && ndelfile < 40; num++) {
		sprintf(file, "F%d", num);
		strsncpy(list[ndelfile], getparm(file), 20);
		if (list[ndelfile][0] == 'M' || list[ndelfile][0] == 'G')
			ndelfile++;
	}
	
	if(-2==get_mailsize(currentuser)){
		errlog("strange user %s",currentuser->userid);
		http_fatal("邮箱内部错误! 请联系系统维护!");
	}

	setmailfile(path, currentuser->userid, ".DIR");
	fd = open(path, O_RDWR);
	if (fd < 0)
		http_fatal("错误的参数2");
	flock(fd, LOCK_EX);
	fstat(fd, &st);
	if (st.st_size % sizeof (struct fileheader) != 0) {
		flock(fd, LOCK_UN);
		close(fd);
		return -1;
	}
	fhmw = malloc(st.st_size);
	if (fhmw == NULL) {
		flock(fd, LOCK_UN);
		close(fd);
		return -1;
	}
	fhw = fhmw;
	count = 0;
	wstart = -1;
	wcount = 0;
	yctx = yspam_init("127.0.0.1");
	while (read(fd, &f, sizeof (struct fileheader)) == sizeof (struct fileheader)) {
		count++;
		ptr = fh2fname(&f);
		for (num = 0; num < ndelfile; num++) {
			if (!strcmp(ptr, list[num]))
				break;
		}
		if (num == ndelfile) {
			if (wstart == -1)
				continue;
			memcpy(fhw, &f, sizeof (struct fileheader));
			wcount++;
			fhw++;
		} else {
			if (wstart == -1)
				wstart = count - 1;
			if (!f.filetime)
				continue;
			setmailfile(fullpath, currentuser->userid, fh2fname(&f));
			update_mailsize_down(&f, currentuser->userid);
			if (spam && yspam_feed_spam(yctx, currentuser->userid, fh2fname(&f)) == 0) {
				unlink(fullpath);
				continue;
			}
			deltree(fullpath);
		}
	}
	yspam_fini(yctx);
	if (wstart != -1) {
		ftruncate(fd, (wstart + wcount) * sizeof (struct fileheader));
		if (wcount > 0) {
			lseek(fd, wstart * sizeof (struct fileheader), SEEK_SET);
			write(fd, fhmw, wcount * sizeof (struct fileheader));
		}
	}
	free(fhmw);
	flock(fd, LOCK_UN);
	close(fd);
	printf("信件已删除.<br><a href=bbsmail>返回所有信件列表</a>\n");
	printf("<script>top.f4.location.reload();</script>");
	http_quit();
	return 0;
}
Beispiel #30
0
Btree :: ~Btree( )
{
    deltree ( root ) ;
}