std::vector<uint256> stledgerentry::getowners ()
{
    std::vector<uint256> owners;
    account account;

    for (int i = 0, fields = getcount (); i < fields; ++i)
    {
        auto const& fc = getfieldstype (i);

        if ((fc == sfaccount) || (fc == sfowner))
        {
            auto entry = dynamic_cast<const staccount*> (peekatpindex (i));

            if ((entry != nullptr) && entry->getvalueh160 (account))
                owners.push_back (getaccountrootindex (account));
        }

        if ((fc == sflowlimit) || (fc == sfhighlimit))
        {
            auto entry = dynamic_cast<const stamount*> (peekatpindex (i));

            if ((entry != nullptr))
            {
                auto issuer = entry->getissuer ();

                if (issuer.isnonzero ())
                    owners.push_back (getaccountrootindex (issuer));
            }
        }
    }

    return owners;
}
Beispiel #2
0
/**
* Number of nonzero elements in numeric array.
*/
mwSize nonzerocount(const mxArray* arr) {
	if (mxIsCell(arr)) {
		mwSize n = mxGetNumberOfElements(arr);
		mwSize c = 0;
		mwIndex ix;

		for (ix = 0; ix < n; ix++) {
			const mxArray* cell = mxGetCell(arr, ix);
			if (cell != NULL) {
				c += nonzerocount(cell);
			}
		}
		return c;
	} else if (mxIsStruct(arr)) {
		mexErrMsgIdAndTxt(__ARGTYPEMISMATCH__, "Structure arrays are not supported.");
		return 0;
	} else if (mxIsSparse(arr)) {
		mwIndex* jc = mxGetJc(arr);
		mwSize n = mxGetN(arr);  /* number of columns */
		return jc[n];  /* number of nonzero elements */
	} else {  /* filter zero elements */
		mwSize n = mxGetNumberOfElements(arr);
		mwSize c = 0;
		const double* pr = mxGetPr(arr);
		const double* pi = mxGetPi(arr);
		mwSize i;

		if (pr == NULL) {
			mexErrMsgIdAndTxt(__ARGTYPEMISMATCH__, "Operation supported only on numeric arrays.");
		}

		if (pi != NULL) {  /* real and imaginary part */
			for (i = 0; i < n; i++) {
				if (isnonzero(*(pr++)) || isnonzero(*(pi++))) {
					c++;
				}
			}
		} else {  /* real part only */
			for (i = 0; i < n; i++) {
				if (isnonzero(*(pr++))) {
					c++;
				}
			}
		}
		return c;
	}
}
Beispiel #3
0
void
arp_print(netdissect_options *ndo,
	  const u_char *bp, u_int length, u_int caplen)
{
	const struct arp_pkthdr *ap;
	u_short pro, hrd, op, linkaddr;

	ap = (const struct arp_pkthdr *)bp;
	ND_TCHECK(*ap);

	hrd = HRD(ap);
	pro = PRO(ap);
	op = OP(ap);


        /* if its ATM then call the ATM ARP printer
           for Frame-relay ARP most of the fields
           are similar to Ethernet so overload the Ethernet Printer
           and set the linkaddr type for linkaddr_string(ndo, ) accordingly */

        switch(hrd) {
        case ARPHRD_ATM2225:
            atmarp_print(ndo, bp, length, caplen);
            return;
        case ARPHRD_FRELAY:
            linkaddr = LINKADDR_FRELAY;
            break;
        default:
            linkaddr = LINKADDR_ETHER;
            break;
	}

	if (!ND_TTEST2(*ar_tpa(ap), PROTO_LEN(ap))) {
		ND_PRINT((ndo, "%s", tstr));
		ND_DEFAULTPRINT((const u_char *)ap, length);
		return;
	}

        if (!ndo->ndo_eflag) {
            ND_PRINT((ndo, "ARP, "));
        }

        /* print hardware type/len and proto type/len */
        if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
	    PROTO_LEN(ap) != 4 ||
            HRD_LEN(ap) == 0 ||
            ndo->ndo_vflag) {
            ND_PRINT((ndo, "%s (len %u), %s (len %u)",
                      tok2str(arphrd_values, "Unknown Hardware (%u)", hrd),
                      HRD_LEN(ap),
                      tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro),
                      PROTO_LEN(ap)));

            /* don't know know about the address formats */
            if (!ndo->ndo_vflag) {
                goto out;
            }
	}

        /* print operation */
        ND_PRINT((ndo, "%s%s ",
               ndo->ndo_vflag ? ", " : "",
               tok2str(arpop_values, "Unknown (%u)", op)));

	switch (op) {

	case ARPOP_REQUEST:
		ND_PRINT((ndo, "who-has %s", ipaddr_string(ndo, TPA(ap))));
		if (isnonzero((const u_char *)THA(ap), HRD_LEN(ap)))
			ND_PRINT((ndo, " (%s)",
				  linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap))));
		ND_PRINT((ndo, " tell %s", ipaddr_string(ndo, SPA(ap))));
		break;

	case ARPOP_REPLY:
		ND_PRINT((ndo, "%s is-at %s",
                          ipaddr_string(ndo, SPA(ap)),
                          linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap))));
		break;

	case ARPOP_REVREQUEST:
		ND_PRINT((ndo, "who-is %s tell %s",
			  linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap)),
			  linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap))));
		break;

	case ARPOP_REVREPLY:
		ND_PRINT((ndo, "%s at %s",
			  linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap)),
			  ipaddr_string(ndo, TPA(ap))));
		break;

	case ARPOP_INVREQUEST:
		ND_PRINT((ndo, "who-is %s tell %s",
			  linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap)),
			  linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap))));
		break;

	case ARPOP_INVREPLY:
		ND_PRINT((ndo,"%s at %s",
			  linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap)),
			  ipaddr_string(ndo, SPA(ap))));
		break;

	default:
		ND_DEFAULTPRINT((const u_char *)ap, caplen);
		return;
	}

 out:
        ND_PRINT((ndo, ", length %u", length));

	return;
trunc:
	ND_PRINT((ndo, "%s", tstr));
}
Beispiel #4
0
int
rdwrpart(Req *r)
{
	int q, nonzero;
	Part *p;
	vlong offset;
	long count, tot, n, o;
	uchar *blk, *dat;
	void *(*move)(void*, void*, ulong);

	q = r->fid->qid.path-Qpart;
	if(q < 0 || q > nelem(tab) || !tab[q].inuse || tab[q].vers != r->fid->qid.vers){
		respond(r, "unknown partition");
		return -1;
	}

	p = &tab[q];
	offset = r->ifcall.offset;
	count = r->ifcall.count;
	if(offset < 0){
		respond(r, "negative offset");
		return -1;
	}
	if(count < 0){
		respond(r, "negative count");
		return -1;
	}
	if(offset > p->length*sectsize){
		respond(r, "offset past end of partition");
		return -1;
	}
	if(offset+count > p->length*sectsize)
		count = p->length*sectsize - offset;
	offset += p->offset*sectsize;

	if(r->ifcall.type == Tread)
		move = memmove;
	else
		move = evommem;

	tot = 0;
	nonzero = 1;
	if(r->ifcall.type == Tread)
		dat = (uchar*)r->ofcall.data;
	else{
		dat = (uchar*)r->ifcall.data;
		nonzero = isnonzero(dat, r->ifcall.count);
	}
	o = offset & (BLKSZ-1);

	/* left fringe block */
	if(o && count){
		blk = getblock(offset, r->ifcall.type==Twrite && nonzero);
		n = BLKSZ - o;
		if(n > count)
			n = count;
		if(r->ifcall.type != Twrite || blk != zero)
			(*move)(dat, blk+o, n);
		if(r->ifcall.type == Twrite)
			dirty(offset, blk);
		tot += n;
	}
	/* full and right fringe blocks */
	while(tot < count){
		blk = getblock(offset+tot, r->ifcall.type==Twrite && nonzero);
		n = BLKSZ;
		if(n > count-tot)
			n = count-tot;
		if(r->ifcall.type != Twrite || blk != zero)
			(*move)(dat+tot, blk, n);
		if(r->ifcall.type == Twrite)
			dirty(offset+tot, blk);
		tot += n;
	}
	r->ofcall.count = tot;
	respond(r, nil);
	return 0;
}
Beispiel #5
0
int isrank(const char c)
{
	return (isnonzero(c) && (c != '9'));
}
Beispiel #6
0
//---------------------------------------------------------------------------------------------------------------
static double NSEEL_CGEN_CALL _sig(double *x, double *constraint)
{
  double t = (1+exp(-*x * (*constraint)));
  return isnonzero(t) ? 1.0/t : 0;
}
Beispiel #7
0
//---------------------------------------------------------------------------------------------------------------
static double NSEEL_CGEN_CALL _bor(double *var, double *var2)
{
  return isnonzero(*var) || isnonzero(*var2) ? 1 : 0;
}
Beispiel #8
0
//---------------------------------------------------------------------------------------------------------------
static double NSEEL_CGEN_CALL _band(double *var, double *var2)
{
  return isnonzero(*var) && isnonzero(*var2) ? 1 : 0;
}