Exemplo n.º 1
0
static int mark_root_table(lua_State* L, lua_State* dL, int type) {
	int len = 0;
	
	lua_pushnil(L);
	while (lua_next(L, -2) != 0) {
		++len;
		if (LUA_TTABLE == lua_type(L, -1)) {
			lua_pushvalue(L, -2);
			
			make_root(dL, lua_topointer(L, -2), lua_tostring(L, -1), type, NULL, 1);
			lua_pop(L, 1);
			mark_table(L, dL);
			lua_pop(dL, 1);
		} else {
		    make_root(dL, lua_topointer(L, -1), "FUNCTION", type, NULL, 0);
			mark_object(L, dL);
			lua_pop(dL, 1);
		}
		lua_pop(L, 1);
		
		make_root(dL, lua_topointer(L, -1), "[KEY]", type, NULL, LUA_TTABLE == lua_type(L, -1));
		mark_object(L, dL);
		lua_pop(dL, 1);
	}
	
	return len;
}
Exemplo n.º 2
0
void insert_edge(int i)
{
	int u = edge[i].u, v = edge[i].v;
	make_root(u);
	access(v);
	if(find(u) != find(v))
	{
		link(i + n, u);
		link(i + n, v);
	} else {
		splay(v);
		int m = val[v];
		if(edge[i].r > edge[m].r)
		{
			cut(edge[m].u, m + n);
			cut(m + n, edge[m].v);
			link(i + n, u);
			link(i + n, v);
		} else m = i;

		u = edge[m].u, v = edge[m].v;
		make_root(u);
		access(v);
		splay(v);
		if(((size[v] + 1) >> 1) & 1)
			incircle[m] = 1;
		else incircle[m] = 0;
		ans += incircle[m];
		outside[m] = 1;
	}
Exemplo n.º 3
0
static void mark_function(lua_State *L, lua_State *dL) {
	const void *p = lua_topointer(L, -1);
	int i;
	lua_Debug ar;
	char used_in[128];
	const char *name;
	
	
	if (!is_marked(dL, p)) {
		marked(dL, p, 0); //已经在table里头算了
		
		lua_pushvalue(L, -1);
		lua_getinfo(L, ">S", &ar);
		snprintf(used_in, sizeof(used_in) - 1, "%s:%d~%d", ar.short_src, ar.linedefined, ar.lastlinedefined);
		used_in[sizeof(used_in) - 1] = 0;
		
		for (i=1;;i++) {
			name = lua_getupvalue(L,-1,i);
			if (name == NULL)
				break;
			p = lua_topointer(L, -1);
			
			if (*name != '\0' && LUA_TTABLE == lua_type(L, -1)) {
				make_root(dL, p, name, RT_UPVALUE, used_in, 1);
				lua_insert(dL, MARKED_TABLE);
				mark_object(L, dL);
				lua_remove(dL, MARKED_TABLE);
			} else if (LUA_TFUNCTION == lua_type(L, -1)) {
				mark_function(L, dL);
			}
			lua_pop(L, 1);
		}
	}
}
Exemplo n.º 4
0
int main()
{
	int n, m, k, type;
	std::scanf("%d %d %d %d", &n, &m, &k, &type);
	for(int i = 0; i <= n; ++i)
		val[i] = min_v[i] = ~0u >> 1;
	for(int i = 1; i <= m; ++i)
	{
		int u, v;
		std::scanf("%d %d", &u, &v);
		if(u == v) 
		{
			ntr[i] = i;
			continue;
		}
		min_v[i + n] = val[i + n] = i;
		from[i] = u, point[i] = v;

		int mu = find(u), mv = find(v);
		if(mu != mv)
		{
			mfa[mu] = mv;
			ntr[i] = 0;
		} else {
			make_root(u);
			access(v);
			splay(v);

			int node = min_v[v];
			cut(n + node, from[node]);
			cut(n + node, point[node]);
			ntr[i] = node;
		}

		link(u, i + n);
		link(v, i + n);
	}

	for(int i = 1; i <= m; ++i)
		root[i] = insert_element(root[i - 1], 0, m, ntr[i]);

	int lastans = 0;
	for(int i = 0; i != k; ++i)
	{
		int l, r;
		std::scanf("%d %d", &l, &r);
		if(type) 
		{
			l ^= lastans;
			r ^= lastans;
		}

		if(l == 1 && r == m)
			lastans = 1;
		else lastans = n - ask(root[l - 1], root[r], 0, m, l - 1);
		std::printf("%d\n", lastans);
	}

	return 0;
}
Exemplo n.º 5
0
void cut(int u, int v)
{
	make_root(u);
	access(v);
	splay(v);
	son[v][0] = fa[u] = 0;
}
Exemplo n.º 6
0
int main() {
    int i, j;
    unsigned char ch;
    Node *current;
    size = fread(buf, 1, BUFSIZE, stdin);
    i = 0;
    while (i<257) {
        count[i] = make_node();
        count[i]->ch = i;
        i++;
    }
    i = decode_table(count, buf);
    make_codes(count);
    current = root = make_root(count);
    while (i<size) {
        for (j=7; j>=0; j--) {
            if (buf[i] & (1 << j)) current = (Node*) current->l; else
                current = (Node*) current->r;
            if (!current->l || !current->r) {
                if (current->ch == 256) return 0;
                ch = current->ch;
                fwrite(&ch, 1, 1, stdout);
                current = root;
            }
        }
        i++;
    }
    return 0;
}
binomial_node* pq_insert( binomial_queue *queue, item_type item, key_type key )
{
    binomial_node *wrapper = pq_alloc_node( queue->map, 0 );
    ITEM_ASSIGN( wrapper->item, item );
    wrapper->key = key;
    queue->size++;
    make_root( queue, wrapper );

    return wrapper;
}
/**
 * Breaks apart a tree given the root.  Makes all children new roots, and leaves
 * the node ready for deletion.
 *
 * @param queue Queue in which to operate
 * @param node  Node whose subtree to break
 */
static void break_tree( binomial_queue *queue, binomial_node *node )
{
    binomial_node *current, *next;

    current = node->left;
    while( current != NULL )
    {
        next = current->right;
        make_root( queue, current );
        current = next;
    }
}
Exemplo n.º 9
0
void link(int u, int v)
{
	make_root(u);
	fa[u] = v;
}
Exemplo n.º 10
0
int main(int argc,char *argv[]) {
  FILE *fpA;
  FILE *fpB;
  FILE *fpC;
  int c;  
  unsigned int alpha=0xff;

  if (argc !=1) sscanf(argv[1],"%x",&alpha);

  fpA=fopen("paltable.c","w");
  fpB=fopen("stdkey.h","w");
  fprintf(stderr,"making spectra.\n");
  make_reg();
  fprintf(stderr,"making color bars.\n");
  make_root();
  make_out_reg(256,17,256);
  fprintf(stderr,"printing palette table.\n");
  print_reg(fpA,"KeyPalReg",256);
  print_reg_hdr(fpB,"KeyPalReg",256);
  fprintf(stderr,"printing rgb tables.\n");
  make_map(256);
  print_map(fpA,"KeyLinear",256,alpha);
  print_hdr(fpB,"KeyLinear",256);

  fpC=fopen("linear-mag.key","w");
  fprintf(fpC,"# linear magnitude\n");
  fprintf(fpC,"%d\n",256);
  for (c=0;c<256;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,mag[c][0],mag[c][1],mag[c][2]);
  fclose(fpC);

  fpC=fopen("linear-sgn.key","w");
  fprintf(fpC,"# linear signed\n");
  fprintf(fpC,"%d\n",256);
  for (c=0;c<256;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,sgn[c][0],sgn[c][1],sgn[c][2]);
  fclose(fpC);


  make_map(20);
  print_map(fpA,"KeyTwentyBlk",20,alpha);
  print_hdr(fpB,"KeyTwentyBlk",20); 

  fpC=fopen("twentyblk-mag.key","w");
  fprintf(fpC,"# twentyblk magnitude\n");
  fprintf(fpC,"%d\n",20);
  for (c=0;c<20;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,mag[c][0],mag[c][1],mag[c][2]);
  fclose(fpC);

  fpC=fopen("twentyblk-sgn.key","w");
  fprintf(fpC,"# twentyblk signed\n");
  fprintf(fpC,"%d\n",20);
  for (c=0;c<20;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,sgn[c][0],sgn[c][1],sgn[c][2]);
  fclose(fpC);

  make_map(10);
  print_map(fpA,"KeyTenBlk",10,alpha);
  print_hdr(fpB,"KeyTenBlk",10); 

  fpC=fopen("tenblk-mag.key","w");
  fprintf(fpC,"# tenblk magnitude\n");
  fprintf(fpC,"%d\n",10);
  for (c=0;c<10;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,mag[c][0],mag[c][1],mag[c][2]);
  fclose(fpC);

  fpC=fopen("tenblk-sgn.key","w");
  fprintf(fpC,"# tenblk signed\n");
  fprintf(fpC,"%d\n",10);
  for (c=0;c<10;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,sgn[c][0],sgn[c][1],sgn[c][2]);
  fclose(fpC);

  make_map(5);
  print_map(fpA,"KeyFiveBlk",5,alpha);
  print_hdr(fpB,"KeyFiveBlk",5);

  fpC=fopen("fiveblk-mag.key","w");
  fprintf(fpC,"# fiveblk magnitude\n");
  fprintf(fpC,"%d\n",256);
  for (c=0;c<5;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,mag[c][0],mag[c][1],mag[c][2]);
  fclose(fpC);

  fpC=fopen("fiveblk-sgn.key","w");
  fprintf(fpC,"# fiveblk signed\n");
  fprintf(fpC,"%d\n",256);
  for (c=0;c<5;c++) 
    fprintf(fpC,"%.2x%.2x%.2x%.2x\n",alpha,sgn[c][0],sgn[c][1],sgn[c][2]);
  fclose(fpC);

  make_cmap(256);
  print_cmap(fpA,"KeyLinearC",256);
  print_chdr(fpB,"KeyLinearC",256);
  
  make_cmap(20);
  print_cmap(fpA,"KeyTwentyblkC",20);
  print_chdr(fpB,"KeyTwentyBlkC",20);
  
  make_cmap(10);
  print_cmap(fpA,"KeyTenBlkC",10);
  print_chdr(fpB,"KeyTenBlkC",10); 
  make_cmap(5);
  print_cmap(fpA,"KeyFiveBlkC",5);
  print_chdr(fpB,"KeyFiveBlkC",5);

  fclose(fpA);
  fclose(fpB);
  return 0;
}