当前位置: 首页>>代码示例>>C++>>正文


C++ smalloc函数代码示例

本文整理汇总了C++中smalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ smalloc函数的具体用法?C++ smalloc怎么用?C++ smalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了smalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assert

/**
 * @brief Reads the database into memory.
 *
 * @details Reads the database into memory so we can speedup computation.
 *
 * @param filenames   Name of input files.
 * @param nproteins   Number of proteins (number of input files).
 * @param nfeatures   Number of features for all proteins.
 * @param naminoacids Largest number of amino acids for all proteins.
 *
 * @returns The database.
 * 
 * @todo Check for bad file format.
 */
void database_read
(const char **filenames, unsigned nproteins, unsigned nfeatures)
{
	unsigned width;
	
	/* Sanity check. */
	assert(filenames != NULL);
	assert(nproteins != 0);
	assert(nfeatures != 0);

	/* Allocate database. */
	database.nproteins = nproteins;
	database.labels = smalloc(nproteins*sizeof(unsigned));
	database.data = smalloc(nfeatures*sizeof(double *));
	width = database.maxaminoacids*nproteins;
	for (unsigned i = 0; i < nfeatures; i++)
		database.data[i] = smalloc(width*sizeof(double));

	/* Read database. */
	for (unsigned wprotein = 0; wprotein < nproteins; wprotein++)
	{
		char *line;          /* Working line.        */
		unsigned waminoacid; /* Current amino acid. */
		FILE *wfile;         /* Working file.        */

		/* Open working file. */
		wfile = fopen(filenames[wprotein], "r");
		if (wfile == NULL)
			error ("cannot open input file");
		
		/* Read label. */
		line = readline(wfile);
		sscanf(line, "%u", &database.labels[wprotein]);
		free(line);
		
		/* Read amino acid. */
		waminoacid = 0;
		while (!feof(wfile))
		{
			char *token;       /* Working token.                  */
			unsigned wfeature; /* Working feature.                */
			unsigned j;        /* waminoacid*nproteins + wprotein */
			
			line = readline(wfile);
			
			/* Read line. */
			wfeature = 0;
			token = strtok(line, ";");
			j = waminoacid*nproteins + wprotein;
			while (token != NULL)
			{
				sscanf(token, "%lf", &database.data[wfeature][j]);
				
				token = strtok(NULL, ";");
				wfeature++;
				
				if (wfeature > nfeatures)
					error("bad input file");
				if (waminoacid > database.maxaminoacids)
					error("bad input file");
			}
			
			waminoacid++;
			free(line);
		}
		
		fclose(wfile);
	}
	
	database_transpose();
}
开发者ID:cart-pucminas,项目名称:proteins,代码行数:85,代码来源:database.c

示例2: main


//.........这里部分代码省略.........

  Dim = 0;			/* for any hypercube legacy code...  */

#endif /* PARALLEL */
  
#ifndef PARALLEL
  Dim        = 0;
  ProcID     = 0;
  Num_Proc   = 1;
#endif /* PARALLEL */


  /*
  *   HKM - Change the ieee exception handling based on the machine and
  *         the level of debugging/speed desired. This call currently causes
  *         core dumps for floating point exceptions.
  */

  handle_ieee();
  
  log_msg("--------------");
  log_msg("GOMA begins...");

  /*
   * Some initial stuff that only the master process does.
   */

  if ( ProcID == 0 )
    {
      if (argc > 1)
	{
	  log_msg("Preprocessing command line options.");
	  clc = (struct Command_line_command **) 
	    smalloc( argc * sizeof(struct Command_line_command *));
	  for (i=0; i<argc; i++)
	    {
	      clc[i] = (struct Command_line_command *) 
		smalloc(sizeof(struct Command_line_command));
	      clc[i]->type   = 0; /* initialize command line structure */
	      clc[i]->i_val  = 0;
	      clc[i]->r_val  = 0.;
	      clc[i]->string = (char *) 
		smalloc(MAX_COMMAND_LINE_LENGTH*sizeof(char));
	      for ( j=0; j<MAX_COMMAND_LINE_LENGTH; j++)
		{
		  clc[i]->string[j] = '\0';
		}
#ifdef DEBUG
	      fprintf(stderr, "clc[%d]->string is at 0x%x\n", i, clc[i]->string);
	      fprintf(stderr, "clc[%d]         is at 0x%x\n", i, clc[i]);
#endif
	    }
	}

      strcpy(Input_File, "input");
      strcpy(Echo_Input_File , "echo_input");

      if (argc > 1) translate_command_line(argc, argv, clc, &nclc);
	  	  
	  ECHO("OPEN", Echo_Input_File);
      
	  echo_command_line( argc, argv, Echo_Input_File );
      print_code_version();
      ptmp = legal_notice;
      while ( strcmp(*ptmp, LAST_LEGAL_STRING) != 0 )
	{
开发者ID:goma,项目名称:goma,代码行数:67,代码来源:main.c

示例3: gen_citations

void gen_citations(paragraph * source, keywordlist * kl)
{
  paragraph *para;
  int bibnum = 0;

  for (para = source; para; para = para->next)
  {
    word *ptr;

    /*
     * \BR and \nocite paragraphs get special processing here.
     */
    if (para->type == para_BR)
    {
      keyword *kw = kw_lookup(kl, para->keyword);
      if (!kw)
      {
        error(err_nosuchkw, &para->fpos, para->keyword);
      } else if (kw->text)
      {
        error(err_multiBR, &para->fpos, para->keyword);
      } else
      {
        kw->text = dup_word_list(para->words);
      }
    } else if (para->type == para_NoCite)
    {
      wchar_t *wp = para->keyword;
      while (*wp)
      {
        cite_biblio(kl, wp, para->fpos);
        wp = uadv(wp);
      }
    }

    /*
     * Scan for keyword references.
     */
    for (ptr = para->words; ptr; ptr = ptr->next)
    {
      if (ptr->type == word_UpperXref || ptr->type == word_LowerXref
          || ptr->type == word_FreeTextXref)
        cite_biblio(kl, ptr->text, ptr->fpos);
    }
  }

  /*
   * We're now almost done; all that remains is to scan through
   * the cited bibliography entries and invent default citation
   * texts for the ones that don't already have explicitly
   * provided \BR text.
   */
  for (para = source; para; para = para->next)
  {
    if (para->type == para_BiblioCited)
    {
      keyword *kw = kw_lookup(kl, para->keyword);
      assert(kw != NULL);
      if (!kw->text)
      {
        word *wd = smalloc(sizeof(word));
        wd->text = gentext(++bibnum);
        wd->type = word_Normal;
        wd->alt = NULL;
        wd->next = NULL;
        kw->text = wd;
      }
      para->kwtext = kw->text;
    }
  }
}
开发者ID:151706061,项目名称:nsis-chinese,代码行数:71,代码来源:biblio.c

示例4: mountfix

/*
 * Rewrite the results of a directory read to reflect current 
 * name space bindings and mounts.  Specifically, replace
 * directory entries for bind and mount points with the results
 * of statting what is mounted there.  Except leave the old names.
 */
static long
mountfix(Chan *c, uchar *op, long n, long maxn)
{
	char *name;
	int nbuf, nname;
	Chan *nc;
	Mhead *mh;
	Mount *m;
	uchar *p;
	int dirlen, rest;
	long l;
	uchar *buf, *e;
	Dir d;

	p = op;
	buf = nil;
	nbuf = 0;
	for(e=&p[n]; p+BIT16SZ<e; p+=dirlen){
		dirlen = dirfixed(p, e, &d);
		if(dirlen < 0)
			break;
		nc = nil;
		mh = nil;
		if(findmount(&nc, &mh, d.type, d.dev, d.qid)){
			/*
			 * If it's a union directory and the original is
			 * in the union, don't rewrite anything.
			 */
			for(m=mh->mount; m; m=m->next)
				if(eqchantdqid(m->to, d.type, d.dev, d.qid, 1))
					goto Norewrite;

			name = dirname(p, &nname);
			/*
			 * Do the stat but fix the name.  If it fails, leave old entry.
			 * BUG: If it fails because there isn't room for the entry,
			 * what can we do?  Nothing, really.  Might as well skip it.
			 */
			if(buf == nil){
				buf = smalloc(4096);
				nbuf = 4096;
			}
			if(waserror())
				goto Norewrite;
			l = devtab[nc->type]->stat(nc, buf, nbuf);
			l = dirsetname(name, nname, buf, l, nbuf);
			if(l == BIT16SZ)
				error("dirsetname");
			poperror();

			/*
			 * Shift data in buffer to accomodate new entry,
			 * possibly overflowing into rock.
			 */
			rest = e - (p+dirlen);
			if(l > dirlen){
				while(p+l+rest > op+maxn){
					mountrock(c, p, &e);
					if(e == p){
						dirlen = 0;
						goto Norewrite;
					}
					rest = e - (p+dirlen);
				}
			}
			if(l != dirlen){
				memmove(p+l, p+dirlen, rest);
				dirlen = l;
				e = p+dirlen+rest;
			}

			/*
			 * Rewrite directory entry.
			 */
			memmove(p, buf, l);

		    Norewrite:
			cclose(nc);
			putmhead(mh);
		}
	}
	if(buf)
		free(buf);

	if(p != e)
		error("oops in rockfix");

	return e-op;
}
开发者ID:Akheon23,项目名称:nix-os,代码行数:95,代码来源:sysfile.c

示例5: printf

/* ----------------------------------------------------------------------
 * Command line reading and parsing.
 */
struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
{
    char *line;
    int linelen, linesize;
    struct sftp_command *cmd;
    char *p, *q, *r;
    int quoting;

    if ((mode == 0) || (modeflags & 1)) {
	printf("psftp> ");
    }
    fflush(stdout);

    cmd = smalloc(sizeof(struct sftp_command));
    cmd->words = NULL;
    cmd->nwords = 0;
    cmd->wordssize = 0;

    line = NULL;
    linesize = linelen = 0;
    while (1) {
	int len;
	char *ret;

	linesize += 512;
	line = srealloc(line, linesize);
	ret = fgets(line + linelen, linesize - linelen, fp);

	if (!ret || (linelen == 0 && line[0] == '\0')) {
	    cmd->obey = sftp_cmd_quit;
	    if ((mode == 0) || (modeflags & 1))
		printf("quit\n");
	    return cmd;		       /* eof */
	}
	len = linelen + strlen(line + linelen);
	linelen += len;
	if (line[linelen - 1] == '\n') {
	    linelen--;
	    line[linelen] = '\0';
	    break;
	}
    }
    if (modeflags & 1) {
	printf("%s\n", line);
    }

    p = line;
    while (*p && (*p == ' ' || *p == '\t'))
	p++;

    if (*p == '!') {
	/*
	 * Special case: the ! command. This is always parsed as
	 * exactly two words: one containing the !, and the second
	 * containing everything else on the line.
	 */
	cmd->nwords = cmd->wordssize = 2;
	cmd->words = srealloc(cmd->words, cmd->wordssize * sizeof(char *));
	cmd->words[0] = "!";
	cmd->words[1] = p+1;
    } else {

	/*
	 * Parse the command line into words. The syntax is:
	 *  - double quotes are removed, but cause spaces within to be
	 *    treated as non-separating.
	 *  - a double-doublequote pair is a literal double quote, inside
	 *    _or_ outside quotes. Like this:
	 *
	 *      firstword "second word" "this has ""quotes"" in" and""this""
	 *
	 * becomes
	 *
	 *      >firstword<
	 *      >second word<
	 *      >this has "quotes" in<
	 *      >and"this"<
	 */
	while (*p) {
	    /* skip whitespace */
	    while (*p && (*p == ' ' || *p == '\t'))
		p++;
	    /* mark start of word */
	    q = r = p;		       /* q sits at start, r writes word */
	    quoting = 0;
	    while (*p) {
		if (!quoting && (*p == ' ' || *p == '\t'))
		    break;		       /* reached end of word */
		else if (*p == '"' && p[1] == '"')
		    p += 2, *r++ = '"';    /* a literal quote */
		else if (*p == '"')
		    p++, quoting = !quoting;
		else
		    *r++ = *p++;
	    }
	    if (*p)
		p++;		       /* skip over the whitespace */
//.........这里部分代码省略.........
开发者ID:rdebath,项目名称:sgt,代码行数:101,代码来源:psftp.c

示例6: LoadClustersFromFile


//.........这里部分代码省略.........

            if (repeatcount == 1) representative = repeatkey;

            /* read symbol */
            i = fscanf(fp, " %c", &symbol);

            if (i != 1 || (symbol != '\'' && symbol != '"')) {
                printf("\n\nUnexpected value qualifier detected in cluster file!");
                exit(1);
            }

            /* assign direction */
            if (symbol == '\'')
                direction = 0;
            else
                direction = 1;


            /* do something with it */
            //printf(" %d%c",repeatkey,symbol);
            if (NULL != cstart) { EasyListInsertHead(elist, RDCreate(repeatkey, direction)); }

            /* read a character */
            symbol = 0;
            i = fscanf(fp, " %c", &symbol);


            /* if no more characters then break */
            if (i != 1) break;

            /* if comment, read it and  then break */
            if (symbol == '#')  {
                fscanf(fp, "%s", comment);
                //fscanf(fp," %c",&symbol); // scan extra character
                break;
            }

            /* put character back */
            ungetc(symbol, fp);

            /* if character was a digit continue otherwise break */
            if ((symbol >= '0' && symbol <= '9') || symbol == '-') continue;
            else break;
        }

        //printf("\n");
        if (NULL != citem) {

            /* count pos and neg */
            pos = 0; neg = 0;

            for (nof1 = elist->head; nof1 != NULL; nof1 = nof1->next) {
                a = (RD *)EasyListItem(nof1);

                if (a->id >= 0) pos++; else neg++;
            }


            TotalReads += pos;
            TotalRefs += neg;

            citem->idlist = smalloc(pos * sizeof(int));
            citem->dirlist = smalloc(pos * sizeof(char));
            citem->negidlist = smalloc(neg * sizeof(int));
            citem->negdirlist = smalloc(neg * sizeof(char));
            citem->next = NULL;


            /* insert into RLINK structure and free temp list */
            pos = 0; neg = 0;

            for (nof1 = elist->head; nof1 != NULL; nof1 = nof1->next) {
                a = (RD *)EasyListItem(nof1);

                if (a->id >= 0) {
                    citem->idlist[pos] = a->id;
                    citem->dirlist[pos] = a->dir;
                    pos++;
                }
                else {
                    citem->negidlist[neg] = a->id;
                    citem->negdirlist[neg] = a->dir;
                    neg++;
                }
            }

            citem->refs = neg;
            citem->reads = pos;
            EasyListDestroy(elist);

        }

    }

    /* close file */
    fclose(fp);


    return clustersread;
}
开发者ID:yzhernand,项目名称:VNTRseek,代码行数:101,代码来源:joinc.c

示例7: cygterm_init


//.........这里部分代码省略.........
	 */
	static const struct plug_function_table fn_table = {
		cygterm_log,
		cygterm_closing,
		cygterm_receive,
		cygterm_sent,
		cygterm_accepting
	};
	Local local;
	const char *command;
	char cmdline[2 * MAX_PATH];
	int cport;
	const char *err;
	int cmdlinelen;

	cygterm_debug("top");

	local = snew(struct cygterm_backend_data);
	local->fn = &fn_table;
	local->a = NULL;
	local->s = NULL;
	local->cfg = *cfg;
	local->editing = 0;
	local->echoing = 0;
	local->exitcode = 0;
	*backend_handle = local;

	local->frontend = frontend_handle;

	/* set up listen socket for communication with child */
	cygterm_debug("setupCygTerm");

	/* let sk use INADDR_LOOPBACK and let WinSock choose a port */
	local->a = sk_newlistener(0, 0, (Plug)local, 1, ADDRTYPE_IPV4);
	if ((err = sk_socket_error(local->a)) != NULL)
		goto fail_free;

	/* now, get the port that WinSock chose */
	/* XXX: Is there another function in PuTTY to do this? */
	cygterm_debug("getting port");
	cport = sk_getport(local->a);
	if (cport == -1) {
		err = "Failed to get port number for cthelper";
		goto fail_close;
	}

	if (strchr(local->cfg.termtype, ' ')) {
		err = "term type contains spaces";
		goto fail_close;
	}

	/*  Build cthelper command line */
	cmdlinelen = sprintf(cmdline, CTHELPER" %u %s ", cport, local->cfg.termtype);
	cmdlinelen += makeAttributes(cmdline + cmdlinelen, &local->cfg);

	command = cfg->cygcmd;
	cygterm_debug("command is :%s:", command);
	/*  A command of  "."  or  "-"  tells us to pass no command arguments to
	 *  cthelper which will then run the user's shell under Cygwin.  */
	if ((command[0]=='-'||command[0]=='.') && command[1]=='\0')
		;
	else if (cmdlinelen + strlen(command) + 2 > sizeof cmdline) {
		err = "command is too long";
		goto fail_close;
	}
	else {
		cmdlinelen += sprintf(cmdline + cmdlinelen, " %s", command);
	}

	/* Add the Cygwin /bin path to the PATH. */
	if (cfg->cygautopath) {
		char *cygwinBinPath = getCygwinBin();
		if (!cygwinBinPath) {
			/* we'll try anyway */
			cygterm_debug("cygwin bin directory not found");
		}
		else {
			cygterm_debug("found cygwin directory: %s", cygwinBinPath);
			appendPath(cygwinBinPath);
			sfree(cygwinBinPath);
		}
	}

	cygterm_debug("starting cthelper: %s", cmdline);
	if ((err = spawnChild(cmdline, &local->pi, &local->ctl)))
		goto fail_close;

	/*  This should be set to the local hostname, Apparently, realhost is used
	 *  only to set the window title.
	 */
	strcpy(*realhost = smalloc(sizeof CYGTERM_NAME), CYGTERM_NAME);
	cygterm_debug("OK");
	return 0;

fail_close:
	sk_close(local->a);
fail_free:
	sfree(local);
	return err;
}
开发者ID:eis,项目名称:FuTTY-nodialog,代码行数:101,代码来源:cygterm.c

示例8: do_clearmodes

static void do_clearmodes(User * u)
{
	int i, all;
	int count;		/* For saving ban info */
	char *s;
	char *argv[3];
	char *chan;
	Channel *c;
	Ban **bans;		/* For saving ban info */
	struct c_userlist *cu, *next;

	chan = strtok(NULL, " ");
	all = 0;

	if (!chan) {
		syntax_error(s_OperServ, u, "CLEARMODES",
		    OPER_CLEARMODES_SYNTAX);
	} else if (!(c = findchan(chan))) {
		notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, chan);
	} else if (c->bouncy_modes) {
		notice_lang(s_OperServ, u, OPER_BOUNCY_MODES_U_LINE);
		return;
	} else {
		s = strtok(NULL, " ");

		if (s) {
			if (stricmp(s, "ALL") == 0) {
				all = 1;
			} else {
				syntax_error(s_OperServ, u, "CLEARMODES",
				    OPER_CLEARMODES_SYNTAX);
				return;
			}
		}

		if (WallOSClearmodes) {
			wallops(s_OperServ, "%s used CLEARMODES%s on %s",
			    u->nick, all ? " ALL" : "", chan);
		}

		if (all) {
			/* Clear mode +o */
			for (cu = c->chanops; cu; cu = next) {
				next = cu->next;
				argv[0] = sstrdup(chan);
				argv[1] = sstrdup("-o");
				argv[2] = sstrdup(cu->user->nick);
				send_cmd(MODE_SENDER(s_ChanServ),
				    "MODE %s %s :%s", argv[0], argv[1],
				    argv[2]);
				do_cmode(s_ChanServ, 3, argv);
				free(argv[2]);
				free(argv[1]);
				free(argv[0]);
			}

			/* Clear mode +v */
			for (cu = c->voices; cu; cu = next) {
				next = cu->next;
				argv[0] = sstrdup(chan);
				argv[1] = sstrdup("-v");
				argv[2] = sstrdup(cu->user->nick);
				send_cmd(MODE_SENDER(s_ChanServ),
				    "MODE %s %s :%s", argv[0], argv[1],
				    argv[2]);
				do_cmode(s_ChanServ, 3, argv);
				free(argv[2]);
				free(argv[1]);
				free(argv[0]);
			}
		}

		/* Clear modes */
		send_cmd(MODE_SENDER(s_OperServ),
		    "MODE %s -ciklmMnOpsRt :%s", chan,
		    c->key ? c->key : "");
		argv[0] = sstrdup(chan);
		argv[1] = sstrdup("-ciklmMnOpsRt");
		argv[2] = c->key ? c->key : sstrdup("");
		do_cmode(s_OperServ, 2, argv);
		free(argv[0]);
		free(argv[1]);
		free(argv[2]);
		c->key = NULL;
		c->limit = 0;

		/* Clear bans */
		count = c->bancount;
		bans = smalloc(sizeof(Ban *) * count);

		for (i = 0; i < count; i++) {
			bans[i] = smalloc(sizeof(Ban));
			bans[i]->mask = sstrdup(c->newbans[i]->mask);
		}
		for (i = 0; i < count; i++) {
			argv[0] = sstrdup(chan);
			argv[1] = sstrdup("-b");
			argv[2] = bans[i]->mask;
			send_cmd(MODE_SENDER(s_OperServ), "MODE %s %s :%s",
			    argv[0], argv[1], argv[2]);
//.........这里部分代码省略.........
开发者ID:oftc,项目名称:oftc-blitzed,代码行数:101,代码来源:operserv.c

示例9: userinit

void
userinit(void)
{
	void *v;
	Proc *p;
	Segment *s;
	Page *pg;

	p = newproc();
	p->pgrp = newpgrp();
	p->egrp = smalloc(sizeof(Egrp));
	p->egrp->ref = 1;
	p->fgrp = dupfgrp(nil);
	p->rgrp = newrgrp();
	p->procmode = 0640;

	kstrdup(&eve, "");
	kstrdup(&p->text, "*init*");
	kstrdup(&p->user, eve);

	p->fpstate = FPinit;
	fpoff();

	/*
	 * Kernel Stack
	 *
	 * N.B. make sure there's enough space for syscall to check
	 *	for valid args and 
	 *	4 bytes for gotolabel's return PC
	 */
	p->sched.pc = (ulong)init0;
	p->sched.sp = (ulong)p->kstack+KSTACK-(sizeof(Sargs)+BY2WD);

	/*
	 * User Stack
	 *
	 * N.B. cannot call newpage() with clear=1, because pc kmap
	 * requires up != nil.  use tmpmap instead.
	 */
	s = newseg(SG_STACK, USTKTOP-USTKSIZE, USTKSIZE/BY2PG);
	p->seg[SSEG] = s;
	pg = newpage(0, 0, USTKTOP-BY2PG);
	v = tmpmap(pg);
	memset(v, 0, BY2PG);
	segpage(s, pg);
	bootargs(v);
	tmpunmap(v);

	/*
	 * Text
	 */
	s = newseg(SG_TEXT, UTZERO, 1);
	s->flushme++;
	p->seg[TSEG] = s;
	pg = newpage(0, 0, UTZERO);
	memset(pg->cachectl, PG_TXTFLUSH, sizeof(pg->cachectl));
	segpage(s, pg);
	v = tmpmap(pg);
	memset(v, 0, BY2PG);
	memmove(v, initcode, sizeof initcode);
	tmpunmap(v);

	ready(p);
}
开发者ID:carriercomm,项目名称:plan9-gpl,代码行数:64,代码来源:main.c

示例10: wbpcover

void 
wbpcover (
    int n_left,		/* number of vertices on left side */
    int n_right,		/* number of vertices on right side */
    int *pointers,		/* start/stop of adjacency lists */
    int *indices,		/* adjacency list for each vertex */
    int *vweight,		/* vertex weights */
    int *psep_size,		/* returned size of separator */
    int *psep_weight,		/* returned weight of separator */
    int **psep_nodes		/* list of separator nodes */
)
{
    extern int DEBUG_COVER;	/* debug flag for this routine */
    int      *touched;		/* flags for each vertex */
    int      *resid;		/* remaining, unmatched vertex weight */
    int      *flow;		/* flow on each right->left edge */
    int      *sep_nodes;	/* list of separator nodes */
    int       sep_size;		/* returned size of separator */
    int       sep_weight;	/* returned weight of separator */
    int       nedges;		/* number of edges in bipartite graph */
    int       i, j;		/* loop counter */
    int       wleft, wright, wedges;

    void      confirm_cover();

if (DEBUG_COVER) {
    printf("-> Entering wbpcover, nleft = %d, nright = %d, 2*nedges = %d\n",
	n_left, n_right, pointers[n_left+n_right]-pointers[0]);

    wleft = wright = 0;
    wedges = 0;
    for (i = 0; i < n_left; i++) {
	wleft += vweight[i];
	for (j = pointers[i]; j < pointers[i + 1]; j++)  {
	    wedges += vweight[i] * vweight[indices[j]];
	}
    }
    for (i = n_left; i < n_left + n_right; i++) {
	wright += vweight[i];
	for (j = pointers[i]; j < pointers[i + 1]; j++)  {
	    wedges += vweight[i] * vweight[indices[j]];
	}
    }
    printf("    Corresponds to unweighted, nleft = %d, nright = %d, 2*nedges = %d\n",
	wleft, wright, wedges);
}

    nedges = pointers[n_left + n_right] - pointers[0];

    resid = smalloc((n_left + n_right) * sizeof(int));
    touched = smalloc((n_left + n_right) * sizeof(int));
    flow = smalloc((nedges + 1) * sizeof(int));


    /* Not a matching.  I can be connected to multiple nodes. */
    bpflow(n_left, n_right, pointers, indices, vweight, resid, flow, touched);

    reachability(n_left, n_right, pointers, indices, resid, flow, touched);


    /* Separator includes untouched nodes on left, touched on right. */
    /* Left separator nodes if unconnected to unmatched right node via */
    /* augmenting path, right separator nodes otherwise. */

    /* First count the separator size for malloc. */
    sep_size = 0;
    for (i = 0; i < n_left; i++) {
	if (!touched[i]) {
	    sep_size++;
	}
    }
    for (i = n_left; i < n_left + n_right; i++) {
	if (touched[i]) {
	    sep_size++;
	}
    }

    sep_nodes = smalloc((sep_size + 1) * sizeof(int));

    sep_size = sep_weight = 0;
    for (i = 0; i < n_left; i++) {
	if (!touched[i]) {
	    sep_nodes[sep_size++] = i;
	    sep_weight += vweight[i];
	}
    }
    for (i = n_left; i < n_left + n_right; i++) {
	if (touched[i]) {
	    sep_nodes[sep_size++] = i;
	    sep_weight += vweight[i];
	}
    }

    sep_nodes[sep_size] = 0;

    *psep_size = sep_size;
    *psep_weight = sep_weight;
    *psep_nodes = sep_nodes;

/* Check the answer. */
//.........这里部分代码省略.........
开发者ID:Russell-Jones-OxPhys,项目名称:Trilinos,代码行数:101,代码来源:flow.c

示例11: mapper

void 
mapper (
    struct vtx_data **graph,	/* data structure with vertex weights */
    double **xvecs,		/* continuous indicator vectors */
    int nvtxs,		/* number of vtxs in graph */
    int *active,		/* space for nmyvals ints */
    int *sets,			/* returned processor assignment for my vtxs */
    int ndims,		/* number of dimensions being divided into */
    int cube_or_mesh,		/* 0 => hypercube, d => d-dimensional mesh */
    int nsets,		/* number of sets to divide into */
    int mediantype,		/* type of eigenvector partitioning to use */
    double *goal,			/* desired set sizes */
    int vwgt_max		/* largest vertex weight */
)
{
    double    temp_goal[2];	/* combined set goals if using option 1. */
    double    wbelow;		/* weight of vertices with negative values */
    double    wabove;		/* weight of vertices with positive values */
    int      *temp_sets;	/* sets vertices get assigned to */
    int       vweight;		/* weight of a vertex */
    int       using_vwgts;	/* are vertex weights being used? */
    int       bits;		/* bits for assigning set numbers */
    int       i, j;		/* loop counters */

    void      median(), rec_median_k(), rec_median_1(), median_assign();
    void      map2d(), map3d();

    /* NOTE: THIS EXPECTS XVECS, NOT YVECS! */

    using_vwgts = (vwgt_max != 1);

    if (ndims == 1 && mediantype == 1)
	mediantype = 3;		/* simpler call than normal option 1. */

    if (mediantype == 0) {	/* Divide at zero instead of median. */
	bits = 1;
	temp_sets = smalloc((nvtxs + 1) * sizeof(int));
	for (j = 1; j <= nvtxs; j++)
	    sets[j] = 0;

	for (i = 1; i <= ndims; i++) {
	    temp_goal[0] = temp_goal[1] = 0;
	    for (j = 0; j < (1 << ndims); j++) {
		if (bits & j)
		    temp_goal[1] += goal[j];
		else
		    temp_goal[0] += goal[j];
	    }
	    bits <<= 1;

	    wbelow = wabove = 0;
	    vweight = 1;
	    for (j = 1; j <= nvtxs; j++) {
		if (using_vwgts)
		    vweight = graph[j]->vwgt;
		if (xvecs[i][j] < 0)
		    wbelow += vweight;
		else if (xvecs[i][j] > 0)
		    wabove += vweight;
	    }

	    median_assign(graph, xvecs[i], nvtxs, temp_goal, using_vwgts, temp_sets,
			  wbelow, wabove, (double) 0.0);

	    for (j = 1; j <= nvtxs; j++)
		sets[j] = (sets[j] << 1) + temp_sets[j];
	}
    }

    else if (mediantype == 1) {	/* Divide using min-cost assignment. */
	if (ndims == 2)
	    map2d(graph, xvecs, nvtxs, sets, goal, vwgt_max);
	else if (ndims == 3)
	    map3d(graph, xvecs, nvtxs, sets, goal, vwgt_max);
    }


    else if (mediantype == 2) {	/* Divide recursively using medians. */
	rec_median_k(graph, xvecs, nvtxs, active, ndims, cube_or_mesh, goal,
		     using_vwgts, sets);
    }

    else if (mediantype == 3) {	/* Cut with independent medians => unbalanced. */
	bits = 1;
	temp_sets = smalloc((nvtxs + 1) * sizeof(int));
	for (j = 1; j <= nvtxs; j++)
	    sets[j] = 0;

	for (i = 1; i <= ndims; i++) {
	    temp_goal[0] = temp_goal[1] = 0;
	    for (j = 0; j < (1 << ndims); j++) {
		if (bits & j)
		    temp_goal[1] += goal[j];
		else
		    temp_goal[0] += goal[j];
	    }
	    bits <<= 1;

	    median(graph, xvecs[i], nvtxs, active, temp_goal, using_vwgts, temp_sets);
	    for (j = 1; j <= nvtxs; j++)
//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:trilinos,代码行数:101,代码来源:mapper.c

示例12: ipread

static long
ipread(Chan *ch, void *a, long n, vlong off)
{
	int r;
	Conv *c;
	Proto *x;
	char *p, *s;
	Fs *f;
	ulong offset = off;

	f = ipfs[ch->dev];

	p = a;
	switch(TYPE(ch->qid)) {
	default:
		error(Eperm);
	case Qprotodir:
	case Qtopdir:
	case Qconvdir:
		return devdirread(ch, a, n, 0, 0, ipgen);
	case Qarp:
		error(Eperm);	/* TO DO */
	case Qndb:
		return readstr(off, a, n, f->ndb);
	case Qctl:
		sprint(up->genbuf, "%lud", CONV(ch->qid));
		return readstr(offset, p, n, up->genbuf);
	case Qremote:
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		sprint(up->genbuf, "%I!%d\n", c->raddr, c->rport);
		return readstr(offset, p, n, up->genbuf);
	case Qlocal:
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		sprint(up->genbuf, "%I!%d\n", c->laddr, c->lport);
		return readstr(offset, p, n, up->genbuf);
	case Qstatus:
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		s = smalloc(Statelen);
		if(waserror()){
			free(s);
			nexterror();
		}
		snprint(s, Statelen, "%s\n", ipstates[c->state]);
		n = readstr(offset, p, n, s);
		poperror();
		free(s);
		return n;
	case Qdata:
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		if(c->sfd < 0)
			error(Ehungup);
		if(c->headers) {
			if(n < c->headers)
				error(Ebadarg);
			p = a;
			r = so_recv(c->sfd, p + c->headers, n - c->headers, p, c->headers);
			if(r > 0)
				r += c->headers;
		} else
			r = so_recv(c->sfd, a, n, nil, 0);
		if(r < 0)
			oserror();
		return r;
	case Qstats:
		error("stats not implemented");
		return n;
	}
}
开发者ID:Vykook,项目名称:acme-sac,代码行数:72,代码来源:devip.c

示例13: ipread

static long
ipread(Chan *ch, void *a, long n, vlong off)
{
	Conv *c;
	Proto *x;
	char *buf, *p;
	long rv;
	Fs *f;
	ulong offset = off;

	f = ipfs[ch->dev];

	p = a;
	switch(TYPE(ch->qid)) {
	default:
		error(Eperm);
	case Qtopdir:
	case Qprotodir:
	case Qconvdir:
		return devdirread(ch, a, n, 0, 0, ipgen);
	case Qarp:
		return arpread(f->arp, a, offset, n);
 	case Qbootp:
 		return bootpread(a, offset, n);
 	case Qndb:
		return readstr(offset, a, n, f->ndb);
	case Qiproute:
		return routeread(f, a, offset, n);
	case Qipselftab:
		return ipselftabread(f, a, offset, n);
	case Qlog:
		return netlogread(f, a, offset, n);
	case Qctl:
		buf = smalloc(16);
		snprint(buf, 16, "%lud", CONV(ch->qid));
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qremote:
		buf = smalloc(Statelen);
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		if(x->remote == nil) {
			snprint(buf, Statelen, "%I!%d\n", c->raddr, c->rport);
		} else {
			(*x->remote)(c, buf, Statelen-2);
		}
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qlocal:
		buf = smalloc(Statelen);
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		if(x->local == nil) {
			snprint(buf, Statelen, "%I!%d\n", c->laddr, c->lport);
		} else {
			(*x->local)(c, buf, Statelen-2);
		}
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qstatus:
		buf = smalloc(Statelen);
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		(*x->state)(c, buf, Statelen-2);
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qdata:
		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
		return qread(c->rq, a, n);
	case Qerr:
		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
		return qread(c->eq, a, n);
	case Qsnoop:
		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
		return qread(c->sq, a, n);
	case Qstats:
		x = f->p[PROTO(ch->qid)];
		if(x->stats == nil)
			error("stats not implemented");
		buf = smalloc(Statelen);
		(*x->stats)(x, buf, Statelen);
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	}
}
开发者ID:99years,项目名称:plan9,代码行数:90,代码来源:devip.c

示例14: cmd_send

static int  cmd_send(void *handle, char *buf, int len)
{
	pcmd_backend_data local = handle;
	DWORD writed;
	char *tmp = smalloc(len+1);
	memset(tmp,0,len+1);
	if( !handle || !buf || !len )
		return 0;
	if( strstr(buf, "\r\n") == NULL )
	{
		if( len == 1 && buf[0] == 127 ) //backspace
		{
			int l = strlen(local->semdcmd);
			if( l != 0 )
			{
				from_backend(local->frontend, 0, buf, len);
				l = l-1;
			}
			local->semdcmd[l] = '\0';
			local->bufsize = 1;
		}
		else if( buf[0] == 27 )
		{
			// left || right || up || down
			char c = buf[2];
			if( c == 'A' || c == 'B' ) // up and down
			{
				cmd_rollback_until_none(local);
				if( local->historycount != 0 )
				{
					char* his_buf = (c == 'A') ? cmd_get_previeous_histroy(local) : cmd_get_next_histroy(local);
					strcpy(local->semdcmd, his_buf);
					from_backend(local->frontend, 0, local->semdcmd, strlen(local->semdcmd));
				}
			}
			else
			{
				from_backend(local->frontend, 0, buf+1, 2);
				memcpy(tmp, buf+1, 2);
				strcat(local->semdcmd, tmp);
				local->bufsize = 2;
			}
		}
		else
		{
			from_backend(local->frontend, 0, buf, len);
			memcpy(tmp, buf, len);
			strcat(local->semdcmd, tmp);
			local->bufsize = len;
		}
		
	}
	else
	{

		char sendcmd[MAX_CMD_BUF];
		strcpy(sendcmd, local->semdcmd);
		cmd_rollback_until_none(local);

		WriteFile(local->m_hStdInWrite, sendcmd, strlen(sendcmd), &writed, NULL);
		local->bufsize = writed;
		WriteFile(local->m_hStdInWrite, "\n", 1, &writed, NULL);
		local->bufsize += writed;
		cmd_add_histroy(local, sendcmd);
		local->current_histroy = NULL;
	}

	sfree(tmp);
	return local->bufsize;
}
开发者ID:hackpascal,项目名称:line-is-not-emulator,代码行数:70,代码来源:cmdterm.c

示例15: newproc

Proc*
newproc(void)
{
	Mach *m = machp();
	Proc *p;

	p = psalloc();

	p->state = Scheding;
	p->psstate = "New";
	p->mach = 0;
	p->qnext = 0;
	p->nchild = 0;
	p->nwait = 0;
	p->waitq = 0;
	p->parent = 0;
	p->pgrp = 0;
	p->egrp = 0;
	p->fgrp = 0;
	p->rgrp = 0;
	p->pdbg = 0;
	p->kp = 0;
	if(m->externup != nil && m->externup->procctl == Proc_tracesyscall)
		p->procctl = Proc_tracesyscall;
	else
		p->procctl = 0;
	p->syscalltrace = nil;
	p->notepending = 0;
	p->ureg = 0;
	p->privatemem = 0;
	p->noswap = 0;
	p->errstr = p->errbuf0;
	p->syserrstr = p->errbuf1;
	p->errbuf0[0] = '\0';
	p->errbuf1[0] = '\0';
	p->nlocks = 0;
	p->delaysched = 0;
	p->trace = 0;
	kstrdup(&p->user, "*nouser");
	kstrdup(&p->text, "*notext");
	kstrdup(&p->args, "");
	p->nargs = 0;
	p->setargs = 0;
	memset(p->seg, 0, sizeof p->seg);
	p->pid = incref(&pidalloc);
	pshash(p);
	p->noteid = incref(&noteidalloc);
	if(p->pid <= 0 || p->noteid <= 0)
		panic("pidalloc");
	if(p->kstack == 0){
		p->kstack = smalloc(KSTACK);
		*(uintptr_t*)p->kstack = STACKGUARD;
	}

	/* sched params */
	p->mp = 0;
	p->wired = 0;
	procpriority(p, PriNormal, 0);
	p->cpu = 0;
	p->lastupdate = sys->ticks*Scaling;
	p->edf = nil;

	p->ntrap = 0;
	p->nintr = 0;
	p->nsyscall = 0;
	p->nactrap = 0;
	p->nacsyscall = 0;
	p->nicc = 0;
	p->actime = 0ULL;
	p->tctime = 0ULL;
	p->ac = nil;
	p->nfullq = 0;
	p->req = nil;
	p->resp = nil;
	memset(&p->PMMU, 0, sizeof p->PMMU);
	return p;
}
开发者ID:npe9,项目名称:harvey,代码行数:77,代码来源:proc.c


注:本文中的smalloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。