ssize_t Tokenizer::_insertTokenAt(uint32_t token, size_t index)
{
    const size_t c = mRanges.size();

    if (index >= 1) {
        // do we need to merge with the previous run?
        run_t& p = mRanges.editItemAt(index-1);
        if (p.first+p.length == token) {
            p.length += 1;
            if (index < c) {
                const run_t& n = mRanges[index];
                if (token+1 == n.first) {
                    p.length += n.length;
                    mRanges.removeItemsAt(index);
                }
            }
            return index;
        }
    }
    
    if (index < c) {
        // do we need to merge with the next run?
        run_t& n = mRanges.editItemAt(index);
        if (token+1 == n.first) {
            n.first -= 1;
            n.length += 1;
            return index;
        }
    }

    return mRanges.insertAt(run_t(token,1), index);
}
Beispiel #2
0
		void do_run()
		{
			if(mRun)
			{
				run_t r = mRun;
				mRun = run_t();

				r();
			}
		}
int main (int argc, char *argv[]) //funcao main com gestao de parametros enviados pelo utilizador
{

	int rtn,total,opt;

    switch(argc){
		case 2:
			opt = getopt(argc, argv, "v");
            if(opt == 'v')
            {
                vers();
                rtn=0;
            }
            else 
            {
                help();
				rtn=1;
            }
        break;
        case 4:
			NUM_THREADS=atoi(argv[3]);
			opt = getopt(argc, argv, "t:p:");
            if(opt == 'p')
                rtn=run_p(&argv[2]);
            else if (opt == 't')
                rtn=run_t(&argv[2]);
            else
            {
                help();
                rtn=1;
            }
        break;
        default:
            help();
            rtn=1;
        break;
    }
    return rtn;
}
Beispiel #4
0
int main (int argc, char *argv[]) {

	int rtn,total,opt;

    switch(argc){
		case 2:
			opt = getopt(argc, argv, "v");
            if(opt == 'v')
            {
                vers();
                rtn=0;
            }
            else 
            {
                help();
				rtn=1;
            }
        break;
        case 4:
			NUM_THREADS=atoi(argv[3]);
			opt = getopt(argc, argv, "t:p:");
            if(opt == 'p')
                rtn=run_p(&argv[2]);
            else if (opt == 't')
                rtn=run_t(&argv[2]);
            else
            {
                help();
                rtn=1;
            }
        break;
        default:
            help();
            rtn=1;
        break;
    }
    return rtn;
}