Esempio n. 1
0
File: ops.c Progetto: vr3d/heman
heman_image* heman_ops_stairstep(heman_image* hmap, int nsteps,
    heman_image* mask, heman_color mask_color, int invert_mask,
    HEMAN_FLOAT offset)
{
    assert(hmap->nbands == 1);
    assert(!mask || mask->nbands == 3);
    int size = hmap->height * hmap->width;
    HEMAN_FLOAT* src = hmap->data;
    HEMAN_FLOAT minv = 1000;
    HEMAN_FLOAT maxv = -1000;
    for (int i = 0; i < size; ++i) {
        if (!mask || _match(mask, mask_color, invert_mask, i)) {
            minv = MIN(minv, src[i]);
            maxv = MAX(maxv, src[i]);
        }
    }
    HEMAN_FLOAT range = maxv - minv;
    for (int i = 0; i < size; ++i) {
        HEMAN_FLOAT e = *src;
        if (!mask || _match(mask, mask_color, invert_mask, i)) {
            e = e - minv;
            e /= range;
            e = floor(e * nsteps) / nsteps;
            e = e * range + minv;
        }
        *src++ = e + offset;
    }
    return hmap;
}
Esempio n. 2
0
/* ************************************************************ */
SOM_Scope void SOMLINK epProcessEnvironment(header somSelf)
{
    /* headerData *somThis = headerGetData(somSelf); */
    page thisPage;
    textLine thisHd;
    TPWord thisWord;

    headerMethodDebug("header", "epProcessEnvironment");

    thisPage = __get_currentPage(somSelf);
    thisHd = _pgGetHeaderBlock(thisPage);

    for (;;) {
	thisWord = readToken(__get_currentFileMgr(somSelf));
	if (_match(thisWord, "[[end_environment]]")) {
	    _somFree(thisWord);
	    return;
	}
	if (_tpwType(thisWord) == TP_LINE_BREAK) {
	    _somFree(thisWord);
	    continue;
	}
	_llAddTail(thisHd, thisWord);
	if (_match(thisWord, "[[page_number]]"))
	    _pgSetPageNumber(thisPage, thisWord);
    }

}
Esempio n. 3
0
// ID && NUM && ...
static TreeNode *
_factor(void) {
	TreeNode *t = NULL;
	switch(token) {
		case LPAREN:
			_match(LPAREN);
			t = _exp();
			_match(RPAREN);
			break;
		case NUM:
			t = new_exp_node(ConstK);
			t->attr.val = atoi(token_string);
			_match(NUM);
			break;
		case ID:
			t = new_exp_node(IdK);
			t->attr.name = copy_string(token_string);
			_match(ID);
			break;
		default :
			_syntax_error("Unexpected token.\n");
			print_token(token, token_string);
			token = get_token();
	}
	return t;
}
Esempio n. 4
0
static TreeNode *
_read_stmt(void) {
	TreeNode *t = new_stmt_node(ReadK);
	_match(READ);
	if (t != NULL && token == ID)
		t->attr.name = copy_string(token_string);
	_match(ID);				// take care of token `ID' should be matched
	return t;
}
Esempio n. 5
0
static TreeNode *
_repeat_stmt(void) {
	_match(REPEAT);
	TreeNode *t = new_stmt_node(RepeatK);
	if (t != NULL) t->child[0] = _stmt_sequence();
	_match(UNTIL);
	if (t != NULL) t->child[1] = _exp();
	return t;
}
Esempio n. 6
0
static TreeNode *
_assign_stmt(void) {
	TreeNode *t = new_stmt_node(AssignK);
	if (t != NULL && token == ID)
		t->attr.name = copy_string(token_string);
	_match(ID);
	_match(ASSIGN);
	if (t != NULL) t->child[0] = _exp();
	return t;
}
Esempio n. 7
0
void RingoFastIndex::fetch (OracleEnv &env, int max_matches)
{
   env.dbgPrintf("requested %d hits\n", max_matches);
   matched.clear();
   
   BingoFingerprints &fingerprints = _context.context().fingerprints;
   
   if (_fetch_type == _SUBSTRUCTURE)
   {
      if (fingerprints.ableToScreen(_screening))
      {
         while (matched.size() < max_matches)
         {
            if (_screening.passed.size() > 0)
            {
               int idx = _screening.passed.begin();
               _match(env, _screening.passed.at(idx));
               _screening.passed.remove(idx);
               continue;
            }

            if (fingerprints.screenPart_Init(env, _screening))
            {
               while (fingerprints.screenPart_Next(env, _screening))
                  ;
               fingerprints.screenPart_End(env, _screening);
               _unmatched += _screening.block->used - _screening.passed.size();
            }
            else
            {
               env.dbgPrintfTS("screening ended\n");
               break;
            }

            _screening.items_passed += _screening.passed.size();
            
            env.dbgPrintfTS("%d reactions passed screening\n", _screening.passed.size());
         } 
      }
      else
      {
         while (matched.size() < max_matches && _cur_idx < _context.context().context().storage.count())
            _match(env, _cur_idx++);
         
         env.dbgPrintfTS("%d reactions matched\n", matched.size());
      }
   }
   else
      throw Error("unexpected fetch type: %d", _fetch_type);
}
Esempio n. 8
0
File: ops.c Progetto: vr3d/heman
heman_image* heman_ops_percentiles(heman_image* hmap, int nsteps,
    heman_image* mask, heman_color mask_color, int invert_mask,
    HEMAN_FLOAT offset)
{
    assert(hmap->nbands == 1);
    assert(!mask || mask->nbands == 3);
    int size = hmap->height * hmap->width;
    HEMAN_FLOAT* src = hmap->data;
    HEMAN_FLOAT minv = 1000;
    HEMAN_FLOAT maxv = -1000;
    int npixels = 0;
    for (int i = 0; i < size; ++i) {
        if (!mask || _match(mask, mask_color, invert_mask, i)) {
            minv = MIN(minv, src[i]);
            maxv = MAX(maxv, src[i]);
            npixels++;
        }
    }

    HEMAN_FLOAT* vals = malloc(sizeof(HEMAN_FLOAT) * npixels);
    npixels = 0;
    for (int i = 0; i < size; ++i) {
        if (!mask || _match(mask, mask_color, invert_mask, i)) {
            vals[npixels++] = src[i];
        }
    }
    HEMAN_FLOAT* percentiles = malloc(sizeof(HEMAN_FLOAT) * nsteps);
    for (int tier = 0; tier < nsteps; tier++) {
        float height = qselect(vals, npixels, tier * npixels / nsteps);
        percentiles[tier] = height;
    }
    free(vals);

    for (int i = 0; i < size; ++i) {
        HEMAN_FLOAT e = *src;
        if (!mask || _match(mask, mask_color, invert_mask, i)) {
            for (int tier = nsteps - 1; tier >= 0; tier--) {
                if (e > percentiles[tier]) {
                    e = percentiles[tier];
                    break;
                }
            }
        }
        *src++ = e + offset;
    }
    free(percentiles);

    return hmap;
}
Esempio n. 9
0
void MangoFastIndex::_fetchSubstructure (OracleEnv &env, int max_matches)
{
   BingoFingerprints &fingerprints = _context.context().fingerprints;

   if (fingerprints.ableToScreen(_screening))
   {
      while (matched.size() < max_matches)
      {
         if (_screening.passed.size() > 0)
         {
            int idx = _screening.passed.begin();
            _match(env, _screening.passed.at(idx));
            _screening.passed.remove(idx);
            continue;
         }

         if (fingerprints.screenPart_Init(env, _screening))
         {
            while (fingerprints.screenPart_Next(env, _screening))
            {
               if (_screening.passed_pre.size() <= _context.context().context().sub_screening_pass_mark ||
                   _screening.query_bit_idx    >= _context.context().context().sub_screening_max_bits)
               {
                  env.dbgPrintfTS("stopping at bit #%d; ", _screening.query_bit_idx);
                  break;
               }
            }
            fingerprints.screenPart_End(env, _screening);
            _unmatched += _screening.block->used - _screening.passed.size();
         }
         else
         {
            env.dbgPrintfTS("screening ended\n");
            break;
         }

         _screening.items_passed += _screening.passed.size();
         env.dbgPrintf("%d molecules passed screening\n", _screening.passed.size());
      }
   }
   else
   {
      while (matched.size() < max_matches && _cur_idx < _context.context().context().storage.count())
         _match(env, _cur_idx++);

      env.dbgPrintfTS("%d molecules matched of tested %d\n", matched.size(), _cur_idx);
   }
}
Esempio n. 10
0
File: match.c Progetto: etosha/fslib
/* Linear time arcs matching for two SORTED arrays of arcs */
void match_full_sorted(
                struct _arc * a,
                struct _arc * b,
                arc_t M,
                arc_t N,
                struct _queue *   q) 
{
    arc_t i = 0; 
    arc_t j = 0; 
    arc_t t;

    struct _match_item mi;

    while (i < M && j < N) {
        if ( a[i].olabel <  b[j].ilabel ) ++i;
        else
            if ( a[i].olabel > b[j].ilabel ) ++j;
            else {
                for (t=j; a[i].olabel == b[t].ilabel; ++t ) {
                    mi.a = a[i]; 
                    mi.b = b[t]; 
                    if (_match(a, b, i, t))
                        queue_enque(q, &mi);
                }
                ++i;
            }
    }
}
Esempio n. 11
0
int m_servlist(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	aClient		*acptr;
	char		*mask;

	mask = IsParam(1) ? parv[1] : NULL;

	for (acptr = client; acptr; acptr = acptr->next)
	{
		if (!IsPerson(acptr) || !IsServices(acptr))
			continue;
		if (mask && _match(mask, acptr->name))
			continue;

		sendto_one(sptr, TEXT_SERVLIST,
			me.name, sptr->name,
			acptr->name, acptr->user->username, GetHost(acptr),
			acptr->srvptr->name, acptr->srvptr->hopcount,
			acptr->info);
	}

	sendto_one(sptr, TEXT_SERVLISTEND,
		me.name, sptr->name,
		mask ? mask : "*");

	return 0;
}
Esempio n. 12
0
    bool AllMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const {
        FieldRef path;
        path.parse(_path);

        bool traversedArray = false;
        int32_t idxPath = 0;
        BSONElement e = getFieldDottedOrArray( doc, path, &idxPath, &traversedArray );

        string rest = pathToString( path, idxPath+1 );

        if ( e.type() != Array || traversedArray || rest.size() == 0 ) {
            return matchesSingleElement( e );
        }

        BSONElementSet all;

        BSONObjIterator i( e.Obj() );
        while ( i.more() ) {
            BSONElement e = i.next();
            if ( ! e.isABSONObj() )
                continue;

            e.Obj().getFieldsDotted( rest, all );
        }

        return _match( all );
    }
Esempio n. 13
0
static TreeNode *
_write_stmt(void) {
	TreeNode *t = new_stmt_node(WriteK);
	_match(WRITE);
	if (t != NULL) t->child[0] = _exp();
	return t;
}
/*----------------------------------------------------------------------- */
SEXP
lib_erode_dilate (SEXP x, SEXP kernel, SEXP what, SEXP binary) {
    numeric resetTo, * tgt, * src, *kern, min, max;
    int nz, i, j, nprotect;
    int * dim;
    PointXY size, ksize, pt;
    SEXP res;

    validImage(x,0);
    validImage(kernel,0);

    /* value to reset the checked part t */
    if ( INTEGER(what)[0] == DILATE )
        resetTo = 1.0; /* checking background, reseting to 1 */
    else
        resetTo = 0.0; /* checking foreground, reseting to 0 */
    dim = INTEGER ( GET_DIM(x) );
    size.x = dim[0];
    size.y = dim[1];
    nz = getNumberOfFrames(x,0);

    kern = REAL (kernel);
    ksize.x = INTEGER ( GET_DIM(kernel) )[0];
    ksize.y = INTEGER ( GET_DIM(kernel) )[1];
    nprotect = 0;

    PROTECT ( res = Rf_duplicate(x) );
    nprotect++;

    for ( i = 0; i < nz; i++ ) {
        tgt = &( REAL(res)[i * size.x * size.y] );
        src = &( REAL(x)[i * size.x * size.y] );

        if ( ! INTEGER(binary)[0] ) {
            min = max = src[0];
            for ( j = 0; j < size.x * size.y; j++ ) {
                if (src[j] > max)
                    max = src[j];
                if (src[j] < min)
                    min = src[j];
            }
            for ( j = 0; j < size.x * size.y; j++ ) {
                pt = pointFromIndex (j, size.x);
                tgt[j] = _greymatch(kern, &ksize, src, &size, &pt,
                                    INTEGER(what)[0], min , max);
            }
        }
        else {
            for ( j = 0; j < size.x * size.y; j++ ) {
                if ( tgt[j] == resetTo ) continue;
                pt = pointFromIndex (j, size.x);
                if ( !_match(kern, &ksize, src, &size, &pt, resetTo) )
                    tgt[j] = resetTo;
            }
        }
    }
    
    UNPROTECT (nprotect);
    return res;
}
Esempio n. 15
0
static int _match(const wchar_t *s, const wchar_t *p, wchar_t *out, int Case,
		  int length,
		  int (*compfn) (wchar_t a, wchar_t b))
{
	for (; *p != '\0' && length; ) {
		switch (*p) {
			case '?':	/* match any one character */
				if (*s == '\0')
					return(0);
				if(out)
					*(out++) = *s;
				break;
			case '*':	/* match everything */
				while (*p == '*' && length) {
					p++;
					length--;
				}

					/* search for next char in pattern */
				while(*s) {
					if(_match(s, p, out, Case, length,
						  compfn))
						return 1;
					if(out)
						*out++ = *s;
					s++;
				}
				continue;
			case '[':	 /* match range of characters */
				p++;
				length--;
				if(!parse_range(&p, s, out++, compfn))
					return 0;
				break;
			case '\\':	/* Literal match with next character */
				p++;
				length--;
				/* fall thru */
			default:
				if (!compfn(*s,*p))
					return(0);
				if(out)
					*(out++) = *p;
				break;
		}
		p++;
		length--;
		s++;
	}
	if(out)
		*out = '\0';

					/* string ended prematurely ? */
	if (*s != '\0')
		return(0);
	else
		return(1);
}
Esempio n. 16
0
static TreeNode *
_if_stmt(void) {
//     each node have 3 children, for IF-STMT:
// 0 : is EXP tree
// 1 : is stmt-sequence after THEN
// 2 : is stmt-sequence after ELSE
	TreeNode *t = new_stmt_node(IfK);
	_match(IF);
	if (t != NULL) t->child[0] = _exp();
	_match(THEN);
	if (t != NULL) t->child[1] = _stmt_sequence();
	if (token == ELSE) {
		_match(ELSE);
		if (t != NULL) t->child[2] = _stmt_sequence();
	}
	_match(END);
	return t;
}
Esempio n. 17
0
static void
_set_syslog_level (char *s)
{
    int n = _match (s, level_tab);

    if (n < 0)
        msg_exit ("unknown syslog level: %s", s);
    syslog_level = n;
}
Esempio n. 18
0
int str_match(int m,elem_t* a,int n,elem_t* b){
	int match[MAXN+1][MAXN+1],i,j;
	memset(match,0,sizeof(match));
	for (i=0;i<m;i++)
		for (j=0;j<n;j++)
			match[i+1][j+1]=max(max(match[i][j+1],match[i+1][j]),
							(match[i][j]+_value(a[i],b[i]))*_match(a[i],b[j]));
	return match[m][n];
}
Esempio n. 19
0
unsigned int
_match(LetterType* pattern, int n,
       LetterType* text, int m,
       LetterType wildCard,
       LetterType unlimitedWildCard
       )
{
// A naive (brute force) string matching algorithm that handles 
// wild card (?) and unlimited wild card (*) symbols.
   unsigned int findMisMatch = false;

   for ( int i=0; i<n; i++ ) {  // over the "text" string

      for ( int j=0; j<m; j++ ) {    // over the pattern
         if ( pattern[j] == wildCard ) {
            continue;
         } else
         if ( pattern[j] == unlimitedWildCard ) {

             for (;;) {

               j++;

               if ( j == m )
                 return true;

               if ( pattern[j] != unlimitedWildCard ) 
                 break;
             } 

             for ( int x=i+1; x<n; x++ ) {
                if ( text[x] == pattern[j] )
                   if (
                   _match(
                        &pattern[j], m-j,
                        &text[x], n-x,
                        wildCard, unlimitedWildCard
                         ) == true 
                      )
                      return true;
                
             }

         } else {
            if ( pattern[j] != text[i] ) {
               findMisMatch = true;
               break;
            }
         }
      }
      if ( findMisMatch == false )
         return true;  
   }
   return false;  
}
Esempio n. 20
0
static void
_set_syslog_facility (char *s)
{
    int n = _match (s, facility_tab);

    if (n < 0)
        msg_exit ("unknown syslog facility: %s", s);
    syslog_facility = n;
    closelog ();
    openlog (prog, LOG_NDELAY | LOG_PID, syslog_facility);
}
Esempio n. 21
0
	bool DispatcherManager::notifyByObject(PACKET& packet, Object* obj){
		if(Dispatcher* dispatcher =_match(static_cast<int64_t>(packet.to))){
			const bool ret =dispatcher->notifyByObject(packet, obj);
			dispatcher->release();
			return ret;
		}
		else{
			ERROR("dispatcher manager notify to %lld failed, missmatch", (long long)packet.to);
			return false;
		}
	}
Esempio n. 22
0
	/** reply **/
	bool DispatcherManager::reply(PACKET& packet, void* body, const int64_t body_len){
		if(Dispatcher* dispatcher =_match(static_cast<int64_t>(packet.to))){
			const bool ret =dispatcher->reply(packet, body, body_len);
			dispatcher->release();
			return ret;
		}
		else{
			ERROR("dispatcher manager reply to %lld failed, missmatch", (long long)packet.to);
			return false;
		}
	}
Esempio n. 23
0
int gnrc_netif_ipv6_addr_match(gnrc_netif_t *netif,
                               const ipv6_addr_t *addr)
{
    int idx;

    assert((netif != NULL) && (addr != NULL));
    gnrc_netif_acquire(netif);
    _match(netif, addr, NULL, &idx);
    gnrc_netif_release(netif);
    return idx;
}
Esempio n. 24
0
int match(const wchar_t *s, const wchar_t *p, wchar_t *out, int Case, int length)
{
	int (*compfn)(wchar_t a, wchar_t b);

	if(Case)
		compfn = casecmp;
	else
		/*compfn = exactcmp;*/
		compfn = casecmp;
	return _match(s, p, out, Case, length, compfn);
}
Esempio n. 25
0
bool LexerRule::canMatch(const std::string& text) const
{
	for(auto beginPosition = text.begin();
		beginPosition != text.end(); ++beginPosition)
	{
		std::string::const_iterator position = beginPosition;
	
		if(_match(position, beginPosition, text.end())) return true;
	}

	return false;
}
Esempio n. 26
0
// + && -
static TreeNode *
_simple_exp(void) {
	TreeNode *t = _term();
	while (token == PLUS || token == MINUS) {
		TreeNode *q = new_exp_node(OpK);
		q->child[0] = t;
		q->attr.op = token;
		t = q;
		_match(token);
		t->child[1] = _term();
	}
	return t;
}
Esempio n. 27
0
bool LexerRule::isExactMatch(const std::string& text) const
{
	auto textMatchEnd = text.begin();
	auto ruleMatchEnd = begin();
	
	if(!_match(textMatchEnd, ruleMatchEnd, text.begin(), text.end(),
		begin(), end()))
	{
		return false;
	}
	
	return textMatchEnd == text.end() && ruleMatchEnd == end();
}
Esempio n. 28
0
int str_match(int m,elem_t* a,int n,elem_t* b,elem_t* ret){
	int match[MAXN+1][MAXN+1],last[MAXN+1][MAXN+1],i,j,t;
	memset(match,0,sizeof(match));
	for (i=0;i<m;i++)
		for (j=0;j<n;j++){
			match[i+1][j+1]=(match[i][j+1]>match[i+1][j]?match[i][j+1]:match[i+1][j]);
			last[i+1][j+1]=(match[i][j+1]>match[i+1][j]?3:1);
			if ((t=(match[i][j]+_value(a[i],b[i]))*_match(a[i],b[j]))>match[i+1][j+1])
				match[i+1][j+1]=t,last[i+1][j+1]=2;
		}
	for (;match[i][j];i-=(last[t=i][j]>1),j-=(last[t][j]<3))
		ret[match[i][j]-1]=(last[i][j]<3?a[i-1]:b[j-1]);
	return match[m][n];
}
Esempio n. 29
0
/* ************************************************************ */
SOM_Scope void SOMLINK epProcessEnvironment(txtEnvProcessor somSelf)
{
    txtEnvProcessorData *somThis = txtEnvProcessorGetData(somSelf);

/* Declare local variables.
   ------------------------ */
    page thisPage;
    fileMgr thisFile;
    long n = 0;
    thisPage = __get_currentPage(somSelf);
    thisFile = __get_currentFileMgr(somSelf);
    txtEnvProcessorMethodDebug("txtEnvProcessor", "epProcessEnvironment");

/* Prepare for looping.
   -------------------- */
    _epInitializeEnvironment(somSelf);

/* Loop until end of file.
   ----------------------- */
    while (_thisWord = readToken(thisFile)) {
/*    _print(_thisWord, stdout); */
	if (_tpwType(_thisWord) == TP_EOF) {
	    _somFree(_thisWord);
	    break;
	}
	if (_match(_thisWord, "[[end_environment]]")) {
	    _epShutdownEnvironment(somSelf);
	    break;
	}
	switch (_tpwType(_thisWord)) {
	    case TP_LINE_BREAK:
		_tpProcessLineBreak(somSelf);
		continue;
	    case TP_WORD:
		_tpProcessWord(somSelf);
		continue;
	    case TP_PARAGRAPH_BREAK:
		_tpProcessNewParagraph(somSelf);
		continue;
	    case TP_BLANK_SPACE:
		_tpProcessBlanks(somSelf);
		continue;
	    case TP_TOKEN:
		_epStartUpNewEnvironment(somSelf, _thisWord);
		_somFree(_thisWord);
		continue;
	}
    }
    _tpProcessFullLine(somSelf);
}
Esempio n. 30
0
bool LexerRule::_match(const_iterator& matchEnd,
	const_iterator textBegin, const_iterator textEnd) const
{
	auto ruleEnd = begin();
	
	for(auto ruleCharacter = begin(); ruleCharacter != end(); ++ruleCharacter)
	{
		if(_match(matchEnd, ruleEnd, textBegin, textEnd, ruleCharacter, end()))
		{
			return true;
		}
	}
	
	return false;
}