Пример #1
0
int compare_nodes(rbtnode* p1, rbtnode* s1, rbtnode* p2, rbtnode* s2){
  unsigned int counter = 0;
    if( (p1!=s1) && (p2!=s2) ){
      if(p2->getvalue() != p1->getvalue()){
        counter = 1+ compare_nodes(p1->getleft(),s1,p2->getleft(),s2) + compare_nodes(p1->getright(),s1,p2->getright(),s2);
      }
    }
  return counter;
}
Пример #2
0
int compare_nodes(yaml_document_t *document1, int index1,
        yaml_document_t *document2, int index2, int level)
{
    if (level++ > 1000) return 0;
    yaml_node_t *node1 = yaml_document_get_node(document1, index1);
    yaml_node_t *node2 = yaml_document_get_node(document2, index2);
    int k;

    assert(node1);
    assert(node2);

    if (node1->type != node2->type)
        return 0;

    if (strcmp((char *)node1->tag, (char *)node2->tag) != 0) return 0;

    switch (node1->type) {
        case YAML_SCALAR_NODE:
            if (node1->data.scalar.length != node2->data.scalar.length)
                return 0;
            if (strncmp((char *)node1->data.scalar.value, (char *)node2->data.scalar.value,
                        node1->data.scalar.length) != 0) return 0;
            break;
        case YAML_SEQUENCE_NODE:
            if ((node1->data.sequence.items.top - node1->data.sequence.items.start) !=
                    (node2->data.sequence.items.top - node2->data.sequence.items.start))
                return 0;
            for (k = 0; k < (node1->data.sequence.items.top - node1->data.sequence.items.start); k ++) {
                if (!compare_nodes(document1, node1->data.sequence.items.start[k],
                            document2, node2->data.sequence.items.start[k], level)) return 0;
            }
            break;
        case YAML_MAPPING_NODE:
            if ((node1->data.mapping.pairs.top - node1->data.mapping.pairs.start) !=
                    (node2->data.mapping.pairs.top - node2->data.mapping.pairs.start))
                return 0;
            for (k = 0; k < (node1->data.mapping.pairs.top - node1->data.mapping.pairs.start); k ++) {
                if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].key,
                            document2, node2->data.mapping.pairs.start[k].key, level)) return 0;
                if (!compare_nodes(document1, node1->data.mapping.pairs.start[k].value,
                            document2, node2->data.mapping.pairs.start[k].value, level)) return 0;
            }
            break;
        default:
            assert(0);
            break;
    }
    return 1;
}
Пример #3
0
int compare_documents(yaml_document_t *document1, yaml_document_t *document2)
{
    int k;

    if ((document1->version_directive && !document2->version_directive)
            || (!document1->version_directive && document2->version_directive)
            || (document1->version_directive && document2->version_directive
                && (document1->version_directive->major != document2->version_directive->major
                    || document1->version_directive->minor != document2->version_directive->minor)))
        return 0;

    if ((document1->tag_directives.end - document1->tag_directives.start) !=
            (document2->tag_directives.end - document2->tag_directives.start))
        return 0;
    for (k = 0; k < (document1->tag_directives.end - document1->tag_directives.start); k ++) {
        if ((strcmp((char *)document1->tag_directives.start[k].handle,
                        (char *)document2->tag_directives.start[k].handle) != 0)
                || (strcmp((char *)document1->tag_directives.start[k].prefix,
                    (char *)document2->tag_directives.start[k].prefix) != 0))
            return 0;
    }

    if ((document1->nodes.top - document1->nodes.start) !=
            (document2->nodes.top - document2->nodes.start))
        return 0;

    if (document1->nodes.top != document1->nodes.start) {
        if (!compare_nodes(document1, 1, document2, 1))
            return 0;
    }

    return 1;
}
Пример #4
0
void
merkle_syncer::sendnode_cb (ptr<bool> deleted,
			    ref<sendnode_arg> arg, ref<sendnode_res> res, 
			    clnt_stat err)
{
  if (*deleted)
    return;
  if (err) {
    error (strbuf () << "SENDNODE: rpc error " << err);
    return;
  } else if (res->status != MERKLE_OK) {
    error (strbuf () << "SENDNODE: protocol error " << err2str (res->status));
    return;
  }

  merkle_rpc_node *rnode = &res->resok->node;

  merkle_node *lnode = ltree->lookup_exact (rnode->depth, rnode->prefix);
  if (!lnode) {
    fatal << "lookup failed: " << rnode->prefix << " at " << rnode->depth << "\n";
  }
  
  compare_nodes (ltree, local_rngmin, local_rngmax, lnode, rnode, 
		 vnode, ctype, missingfnc, rpcfnc);

  if (!lnode->isleaf () && !rnode->isleaf) {
    trace << "I vs I\n";
    st.push_back (pair<merkle_rpc_node, int> (*rnode, 0));
  }

  ltree->lookup_release(lnode);

  next ();
}
Пример #5
0
void
test_path (TestConformSimpleFixture *fixture,
           gconstpointer _data)
{
  CallbackData data;
  gint i;

  memset (&data, 0, sizeof (data));

  data.path = clutter_path_new ();

  for (i = 0; i < G_N_ELEMENTS (path_tests); i++)
    {
      gboolean succeeded;

      if (g_test_verbose ())
        g_print ("%s... ", path_tests[i].desc);

      succeeded = path_tests[i].func (&data) && compare_nodes (&data);

      if (g_test_verbose ())
        g_print ("%s\n", succeeded ? "ok" : "FAIL");

      g_assert (succeeded);
    }

  g_object_unref (data.path);
}
Пример #6
0
int main (int argc, char * argv[])
{

	struct node_list_in * list_in;
	struct node_list_out * list_out;
	struct chain_node * node_a;
	struct chain_node * node_b;
	
	int i = 0;
	
	if (argc != 3)
	{
		printf("Usage: %s <infile(sorted)> <outfile>\n", argv[0]);
		exit(0);
	}
	
	list_in = open_node_list_in(argv[1]);
	if (list_in == NULL)
	{
		printf("error opening %s\n", argv[1]);
		return 0;
	}
	
	list_out = open_node_list_out(argv[2]);
	if (list_out == NULL)
	{
		printf("error opening %s\n", argv[2]);
		return 0;
	}
	
	
	node_a = next_node_list_in(list_in);
	node_b = next_node_list_in(list_in);
	while (node_b != NULL)
	{
	
		if (compare_nodes(node_a, node_b) != 0)
			append_node_list_out(list_out, node_a);
			
		node_a = node_b;
		node_b = next_node_list_in(list_in);
		if (++i % 0xFFFFF == 0)
			printf("%d nodes done\n", i);
	}
	append_node_list_out(list_out, node_a);
			
	close_node_list_in(list_in);
	
	flush_node_list_out(list_out);
	close_node_list_out(list_out);
	
	printf("%d nodes processed\n", i);
	
	return 1;
	
}
Пример #7
0
/**
 * Builds a quicksort partition of the given array.
 */
static inline int partition(int end,struct dictionary_node_transition** transitions) {
struct dictionary_node_transition* pivot;
struct dictionary_node_transition* tmp;
int i=-1;
/* Final pivot index */
int j=end+1;
pivot=transitions[(end)/2];
for (;;) {
   do j--;
   while ((j>(-1))&&(compare_nodes(pivot,transitions[j]) < 0));
   do i++;
   while ((i<end+1)&&(compare_nodes(transitions[i],pivot) < 0));
   if (i<j) {
      tmp=transitions[i];
      transitions[i]=transitions[j];
      transitions[j]=tmp;
   } else return j;
}
}
Пример #8
0
// find nli needle in nodelist haystack and return pointer
struct nli *find_node(struct nli *needle, struct nli *haystack)
{
	struct nli *match = NULL;
	if (needle) {
		do
		{
			if (!match) match = compare_nodes(needle, haystack);
		} while (haystack = haystack->next);
	}
	return match;
}
Пример #9
0
int
mtree_specspec(FILE *fi, FILE *fj)
{
	int rval;
	NODE *root1, *root2;

	root1 = mtree_readspec(fi);
	root2 = mtree_readspec(fj);
	rval = walk_in_the_forest(root1, root2, "");
	rval += compare_nodes(root1, root2, "");
	if (rval > 0)
		return (MISMATCHEXIT);
	return (0);
}
Пример #10
0
Файл: mtree.c Проект: taysom/tau
static int compare_branches (
    tree_s		*a,
    tree_s		*b,
    branch_s	*abranch,
    branch_s 	*bbranch)
{
    key_s	*akey;
    key_s	*bkey;
    unint	i;
    int	rc;

    if (abranch->br_num != bbranch->br_num) {
        eprintf("branch num doesn't match %x!=%x\n",
                abranch->br_num, bbranch->br_num);
        return qERR_BAD_TREE;
    }
    rc = compare_nodes(a, b, abranch->br_first, bbranch->br_first);
    if (rc) return rc;
    for (i = 0; i < abranch->br_num; i++) {
        akey = &abranch->br_key[i];
        bkey = &bbranch->br_key[i];
        if (akey->k_key != bkey->k_key) {
            eprintf("branch key %lu doesn't match %llx!=%llx\n",
                    i, akey->k_key, bkey->k_key);
            return qERR_BAD_TREE;
        }
        if (akey->k_node != bkey->k_node) {
            eprintf("key block %lu doesn't match %llx!=%llx\n",
                    i, akey->k_node, bkey->k_node);
            return qERR_BAD_TREE;
        }
        rc = compare_nodes(a, b, akey->k_node, bkey->k_node);
        if (rc) return rc;
    }
    return 0;
}
Пример #11
0
/**
 * 'transitions' is supposed to be sorted, i.e. equivalent transitions
 * are contiguous. If two transitions point to equivalent nodes, we
 * redirect the second transition on the first's node and we free the
 * node that is not pointed anymore.
 */
static void merge(int size,struct dictionary_node_transition** transitions,Abstract_allocator prv_alloc) {
int i=1;
struct dictionary_node_transition* base=transitions[0];
while (i<size) {
   if (compare_nodes(base,transitions[i])==0) {
      /* If the base transition is equivalent to the current one
       * then we must destroy the current one's destination node */
      free_dictionary_node(transitions[i]->node,prv_alloc);
      /* We modify the current one's destination node */
      transitions[i]->node=base->node;
      /* And we increase the number of references of the node, in order
       * to know later when it could be freed */
      (base->node->incoming)++;
   }
   else {
      base=transitions[i];
   }
   i++;
}
}
Пример #12
0
int main (int argc, char * argv[])
{

	int i;
	int lowest_table;
	int tables_n;
	struct node_list_out * list_out;
	struct table_in ** tables_in;
	
	
	if (argc < 4)
	{
		printf("Usage: %s <table_out> [tables_in 0..n]\n", argv[0]);
		printf("The first argument is the table file to write to.\n");
		printf("The subsequent arguments are sorted tables to merge into the table_out.\n");
		exit(0);
	}
	
	list_out = open_node_list_out(argv[1]);
	if (list_out == NULL)
	{
		printf("error opening %s for output\n", argv[1]);
		exit(0);
	}
	
	tables_in = load_tables_in (argc - 2, &(argv[2]));
	
	tables_n = argc - 2;
	lowest_table = 0;
	while (lowest_table >= 0)
	{
		lowest_table = -1;
		
		for (i = 0; i < tables_n; i++)
		{
			if (tables_in[i]->node != NULL)
			{
				if (lowest_table == -1)
					lowest_table = i;
				else if (compare_nodes(tables_in[i]->node, tables_in[lowest_table]->node) < 0)
					lowest_table = i;
				else
				{
					while (compare_nodes(tables_in[i]->node, tables_in[lowest_table]->node) == 0)
					{
						tables_in[i]->node = next_node_list_in(tables_in[i]->list_in);
						if (tables_in[i]->node == NULL)
							break;
					}
				}
			}
		}
		if (lowest_table >= 0)
		{
			append_node_list_out(list_out, tables_in[lowest_table]->node);
			tables_in[lowest_table]->node = next_node_list_in(tables_in[lowest_table]->list_in);
		}
	}
	
	flush_node_list_out(list_out);
	
	printf ("done\n");
	fflush(stdout);
	
	close_node_list_out(list_out);
	for (i = 0; i < tables_n; i++)
	{
		table_in_close(tables_in[i]);
	}
	
	return 1;
	
}
Пример #13
0
Файл: mtree.c Проект: taysom/tau
int compare_trees (tree_s *a, tree_s *b)
{
    return compare_nodes(a, b, root(a), root(b));
}
Пример #14
0
static int
walk_in_the_forest(NODE *t1, NODE *t2, char const *path)
{
	int r, i;
	NODE *c1, *c2, *n1, *n2;
	char *np;

	r = 0;

	if (t1 != NULL)
		c1 = t1->child;
	else
		c1 = NULL;
	if (t2 != NULL)
		c2 = t2->child;
	else
		c2 = NULL;
	while (c1 != NULL || c2 != NULL) {
		n1 = n2 = NULL;
		if (c1 != NULL)
			n1 = c1->next;
		if (c2 != NULL)
			n2 = c2->next;
		if (c1 != NULL && c2 != NULL) {
			if (c1->type != F_DIR && c2->type == F_DIR) {
				n2 = c2;
				c2 = NULL;
			} else if (c1->type == F_DIR && c2->type != F_DIR) {
				n1 = c1;
				c1 = NULL;
			} else {
				i = strcmp(c1->name, c2->name);
				if (i > 0) {
					n1 = c1;
					c1 = NULL;
				} else if (i < 0) {
					n2 = c2;
					c2 = NULL;
				}
			}
		}
		if (c1 == NULL && c2->type == F_DIR) {
			asprintf(&np, "%s%s/", path, c2->name);
			i = walk_in_the_forest(c1, c2, np);
			free(np);
			i += compare_nodes(c1, c2, path);
		} else if (c2 == NULL && c1->type == F_DIR) {
			asprintf(&np, "%s%s/", path, c1->name);
			i = walk_in_the_forest(c1, c2, np);
			free(np);
			i += compare_nodes(c1, c2, path);
		} else if (c1 == NULL || c2 == NULL) {
			i = compare_nodes(c1, c2, path);
		} else if (c1->type == F_DIR && c2->type == F_DIR) {
			asprintf(&np, "%s%s/", path, c1->name);
			i = walk_in_the_forest(c1, c2, np);
			free(np);
			i += compare_nodes(c1, c2, path);
		} else {
			i = compare_nodes(c1, c2, path);
		}
		r += i;
		c1 = n1;
		c2 = n2;
	}
	return (r);	
}
Пример #15
0
int main (int argc, char * argv[])
{

	struct node_list_in * list_a;
	struct node_list_in * list_b;
	struct node_list_out * list_out;
	struct chain_node * node_a;
	struct chain_node * node_b;
	
	uint32_t i = 0;
	
	if (argc != 4)
	{
		printf("Usage: %s <infile_a> <infile_b> <outfile(sorted)>\n", argv[0]);
		exit(0);
	}
	
	list_a = open_node_list_in(argv[1]);
	if (list_a == NULL)
	{
		printf("error opening %s\n", argv[1]);
		return 0;
	}
	
	list_b = open_node_list_in(argv[2]);
	if (list_b == NULL)
	{
		printf("error opening %s\n", argv[2]);
		return 0;
	}
	
	list_out = open_node_list_out(argv[3]);
	if (list_out == NULL)
	{
		printf("error opening %s\n", argv[3]);
		return 0;
	}
	
	node_a = next_node_list_in(list_a);
	node_b = next_node_list_in(list_b);
	while (1)
	{
		if (node_a == NULL)
		{
			if (node_b == NULL)
				break;
			append_node_list_out(list_out, node_b);
			node_b = next_node_list_in(list_b);
		}
		else if (node_b == NULL)
		{
			append_node_list_out(list_out, node_a);
			node_a = next_node_list_in(list_a);
		}
		else if (compare_nodes(node_a, node_b) < 0)
		{
			append_node_list_out(list_out, node_a);
			node_a = next_node_list_in(list_a);
		}
		else if (compare_nodes(node_a, node_b) > 0)
		{
			append_node_list_out(list_out, node_b);
			node_b = next_node_list_in(list_b);
		}
		else
			node_a = next_node_list_in(list_a);
		i++;
	}
	
	close_node_list_in(list_a);
	close_node_list_in(list_b);
	
	flush_node_list_out(list_out);
	close_node_list_out(list_out);
	
	printf("%d nodes processed\n", i);
	
	return 1;
	
}
Пример #16
0
int main (int argc, char * argv[])
{

	struct node_list_in * list_in;
	struct chain_context chain;
	struct chain_node * node;
	struct chain_node * nodes;
	uint32_t A, B, C, D;
	int i;

	/************************
	* DEAL WITH INPUT       *
	************************/

	if (argc != 8)
	{
		//             0  1               2               3         4                  5            6         7
		printf("Usage: %s <sorted rtable> <hash_function> <charset> <plaintext_length> <chain_size> <table_i> <hash>\n", argv[0]);
		exit(0);
	}
	
	if (strcmp(argv[2], "nt") == 0)
	{
		hash_function = nt_hash;
		reduce_function = nt_reduce;
	}
	else
	{
		printf("Invalid hash function\n");
		exit(0);
	}
	
	if (strcmp(argv[3], "az") == 0)
		chain.charset = az;
	else if (strcmp(argv[3], "az09") == 0)
		chain.charset = az09;
	else if (strcmp(argv[3], "azAZ09") == 0)
		chain.charset = azAZ09;
	else if (strcmp(argv[3], "azAZ09special") == 0)
		chain.charset = azAZ09special;
	else
	{
		printf("Invalid hash function\n");
		exit(0);
	}
	
	/*********************************
	* INIT CRAP                      *
	*********************************/
	
	A = hex_string_to_uint32(&(argv[7][0]));
	B = hex_string_to_uint32(&(argv[7][8]));
	C = hex_string_to_uint32(&(argv[7][16]));
	D = hex_string_to_uint32(&(argv[7][24]));

	chain.chain = 0;
	chain.chain_size = atoi(argv[5]);
	chain.table = atoi(argv[6]);
	chain.plaintext_length = atoi(argv[4]);
	chain.charset = az;
	memset(chain.plaintext, 0, 128);
	
	printf("chain.chain %d\tchain.plaintext_length %d\n", chain.chain, chain.plaintext_length);
	printf("chain.table %d\tchain.chain_size %d\n", chain.table, chain.chain_size);
	printf("starting hash %08x%08x%08x%08x\n", A, B, C, D);
	
	nodes = malloc(sizeof(struct chain_node) * chain.chain_size);
	nodes[0].a = A;
	nodes[0].b = B;
	nodes[0].c = C;
	nodes[0].d = D;
	
	/**********************************************
	* CONSTRUCT CHAINS TO FIND HASHES TO LOOK FOR *
	**********************************************/
	
	printf("generating chains... ");
	for (i = 1; i < chain.chain_size; i++)
	{
		chain.A = A;
		chain.B = B;
		chain.C = C;
		chain.D = D;
		create_context_chain(&chain, i);
		nodes[i].a = chain.A;
		nodes[i].b = chain.B;
		nodes[i].c = chain.C;
		nodes[i].d = chain.D;
	}
	printf("done\n");
	
	printf("merge_sort... ");
	merge_sort(nodes, chain.chain_size);
	printf("done\n");
	
	#if RC_DEBUG == 1
	printf("Testing sorted list\n");
	for (i = 0; i < chain.chain_size; i++)
	{
		printf("%08x%08x%08x%08x\n", nodes[i].a, nodes[i].b, nodes[i].c, nodes[i].d);
	}
	#endif
	
	/**************************
	* SEARCH FOR THOSE HASHES *
	**************************/
	
	i = 0;
	list_in = open_node_list_in(argv[1]);
	if (list_in == NULL)
	{
		printf("failed to open %s\n", argv[1]);
		exit(0);
	}
	node = next_node_list_in(list_in);
	
	printf("search for hash\n");
	while (node != NULL)
	{
		// skip nodes in file until we get to the next node in nodes
		// to look for (nodes is sorted)
		while (compare_nodes(node, &nodes[i]) < 0)
		{
			node = next_node_list_in(list_in);
			if (node == NULL)
				break;
		}
		
		if (node != NULL)
		{
			if (compare_nodes(node, &nodes[i]) == 0)
			{
				chain.chain = node->chain_id;
				if (find_hash_in_chain(&chain, A, B, C, D) == 1)
				{
					return 1;
				}
			}
		}
		
		i++;
		
	}
		
	close_node_list_in(list_in);;
	
	return 1;

}