Exemple #1
0
void
sha1oracle::reset ()
{
  u_int64_t ini[2] = { 0, idx };
  count = 0;
  for (size_t i = 0; i < nctx; i++)
    newstate (state[i]);
  firstblock = true;
  update (ini, sizeof (ini));
}
Exemple #2
0
static ERL_NIF_TERM
evaluate_msg(msg_t *msg, worker_t *w)
{
    switch(msg->type) {
    case msg_newstate:
        return newstate(msg->env, msg->hold_env);
    case msg_dofile:
        return dofile(msg->env, msg->res->L, msg->arg1);
    case msg_gencall:
        return gencall(msg->env, msg->res->L, msg->arg1, msg->arg2, msg->arg3);
    default:
        return make_error_tuple(msg->env, "invalid_command");
    }
}
Exemple #3
0
state_t *move_me(state_t *s, const int dy, const int dx)
{
	const int y = s->c[0] / w;
	const int x = s->c[0] % w;
	const int y1 = y + dy;
	const int x1 = x + dx;
	const int c1 = y1 * w + x1;

	if (y1 < 0 || y1 > h || x1 < 0 || x1 > w
			|| board[c1] == wall)
		return NULL;

	int at_box = 0;
	for (int i = 1; i <= n_boxes; i++) {
		if (s->c[i] == c1) {
			at_box = i;
			break;
		}
	}

	int c2;
	if (at_box) {
		c2 = c1 + dy * w + dx;
		if (board[c2] == wall || !live[c2])
			return NULL;
		for (int i = 1; i <= n_boxes; i++)
			if (s->c[i] == c2) return NULL;
	}

	state_t *n = newstate(s);
	memcpy(n->c + 1, s->c + 1, sizeof(cidx_t) * n_boxes);

	cidx_t *p = n->c;
	p[0] = c1;

	if (at_box) p[at_box] = c2;

	// leet bubble sort
	for (int i = n_boxes; --i; ) {
		cidx_t t = 0;
		for (int j = 1; j < i; j++) {
			if (p[j] > p[j + 1])
				t = p[j], p[j] = p[j+1], p[j+1] = t;
		}
		if (!t) break;
	}

	return n;
}
Exemple #4
0
state_t *parse_board(const int y, const int x, const char *s)
{
	w = x, h = y;
	board = calloc(w * h, sizeof(uint8_t));
	assert(board);
	goals = calloc(w * h, sizeof(uint8_t));
	assert(goals);
	live  = calloc(w * h, sizeof(uint8_t));
	assert(live);

	n_boxes = 0;
	for (int i = 0; s[i]; i++) {
		switch(s[i]) {
		case '#':	board[i] = wall;
				continue;

		case '.':	// fallthrough
		case '+':	goals[i] = 1; // fallthrough
		case '@':	continue;

		case '*':	goals[i] = 1; // fallthrough
		case '$':	n_boxes++;
				continue;
		default:	continue;
		}
	}

	const int is = sizeof(int);
	state_size = (sizeof(state_t) + (1 + n_boxes) * sizeof(cidx_t) + is - 1)
			/ is * is;

	state_t *state = newstate(NULL);

	for (int i = 0, j = 0; i < w * h; i++) {
		if (goals[i]) mark_live(i);
		if (s[i] == '$' || s[i] == '*')
			state->c[++j] = i;
		else if (s[i] == '@' || s[i] == '+')
			state->c[0] = i;
	}

	return state;
}
Exemple #5
0
bool SDL::State::update()
{
    if (!m_data)
        return false;

    StateDescriptor* newdesc = DescriptorDb::FindLatestDescriptor(m_data->m_desc->m_name);
    if (newdesc == m_data->m_desc)
        return false;

    SDL::State newstate(newdesc);
    for (size_t i=0; i < newstate.m_data->m_vars.size(); ++i) {
        VarDescriptor* newdesc = newstate.m_data->m_vars[i].descriptor();
        StateDescriptor::varmap_t::iterator vari = m_data->m_desc->m_varmap.find(newdesc->m_name);
        if (vari == m_data->m_desc->m_varmap.end())
            continue;
        newstate.m_data->m_vars[i].copy(m_data->m_vars[vari->second]);
    }
    newstate.m_data->ref();
    m_data->unref();
    m_data = newstate.m_data;
    return true;
}
Exemple #6
0
static ERL_NIF_TERM
elua_newstate_sync(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    return newstate(env, env);
};
Exemple #7
0
void main()
{
	FILE *f;

	f=fopen("tab2.txt","r");
	while(!feof(f))
	{
		fscanf(f,"%s",tab[n]);
		n++;
	}
	n--;
	ns=n-1;

	for(i=0;i<ns;i++)
		st[i][0]=i+48;

	printf("\n\nTHE NFA TABLE IS AS FOLLOWS\n\n");
	for(i=0;tab[0][i]!='\0';i++)
	{
		printf("\t%c",tab[0][i]);
		iv++;
	}

	for(i=1;i<n;i++)
	{
		printf("\n%c\t",st[i-1][0]);
		for(j=0;tab[i][j]!='\0';j++)
		{
			if(tab[i][j]==':')
				printf("\t");
			else
				printf("%c",tab[i][j]);
		}
	}

	search();
	newstate();

	while(ns!=(n-1))
	{
		for(k=0;k<strlen(st[n-1]);k++)
		{
			if(st[n-1][k]==',')
			{
				//st[n-1][k]=' ';
				k++;
			}
			for(i=1;i<n;i++)
			{
				if(st[n-1][k]==st[i-1][0])
					break;
			}
			for(j=0;j<iv;j++)
			{
				tab[n][j]=nss+48;
				if(k==0)
					strcpy(tr[nss],tr[tab[i][j]-48]);
				else
				{
					if(tr[nss][0]=='x')
						strcpy(tr[nss],tr[tab[i][j]-48]);
					else
					{
						for(o=0;o<strlen(tr[tab[i][j]-48]);o++)
						{
							for(p=0;p<strlen(tr[nss]);p++)
								if( tr[nss][p] == tr[tab[i][j]-48][o] || tr[tab[i][j]-48][o]=='x')
									break;
							if(p==strlen(tr[nss]))
								tr[nss][strlen(tr[nss])]=tr[tab[i][j]-48][o];
						}
					}
				}
				nss++;
			}
			nss=nss-2;
		}
		nss=nss+2;
		n++;
		newstate();
	}

	printf("\n\n\n\nTHE DFA TABLE IS AS FOLLOWS\n\n");
	for(i=0;tab[0][i]!='\0';i++)
		printf("\t%c",tab[0][i]);

	for(i=1;i<n;i++)
	{
		printf("\n%s\t",st[i-1]);
		for(j=0;j<iv;j++)
			printf("%s\t",tr[tab[i][j]-48]);
	}

	f=fopen("tab2res.txt","w");
	fprintf(f,"\t%s",tab[0]);
	for(i=1;i<n;i++)
	{
		fprintf(f,"\n%s\t",st[i-1]);
		for(j=0;j<iv;j++)
		{
			fprintf(f,"%s",tr[tab[i][j]-48]);
			if(j==0)
				fprintf(f,":");
		}
	}
	printf("\n\n");
	getchar();
}