Example #1
0
static void
tree_dump(uintptr_t n, int depth)
{
	if (n == 0) {
		printf("empty.\n");
		return;
	}

	if (critbit_isinnode(n)) {
		CritbitNode *node = critbit_toinnode(n);

		printf("%*s", depth * 2, "");
		printf("bit: %d\n", node->bit);

		tree_dump(node->child[0], depth + 1);
		tree_dump(node->child[1], depth + 1);
	} else {
		Tuple *t = critbit_toexnode(n);
		int i;

		printf("%*s", depth * 2, "");
		printf("key:");
		for (i = 0; i < 4; i++) {
			printf(" %02x", t->key.oct[i]);
		}
		printf("/%d\n", t->key.nbits);
		printf("%*s", depth * 2, "");
		printf("val: %d\n", t->val);
	}
}
Example #2
0
static void
tree_dump(uintptr_t n, int depth)
{
	if (n == 0) {
		printf("empty.\n");
		return;
	}

	if (critbit_isinnode(n)) {
		CritbitNode *node = critbit_toinnode(n);

		printf("%*s", depth * 2, "");
		printf("bit: %d\n", node->bit);

		tree_dump(node->child[0], depth + 1);
		tree_dump(node->child[1], depth + 1);
	} else {
		Tuple *t = critbit_toexnode(n);
		char str[INET_ADDRSTRLEN];

		inet_ntop(AF_INET, &t->key.addr, str, sizeof(str));

		printf("%*s", depth * 2, "");
		printf("key: %s/%d\n", str, t->key.mask);
		printf("%*s", depth * 2, "");
		printf("val: %d\n", t->val);
	}
}
Example #3
0
void
tree_dump(struct btnode *n, int depth)
{
	int i;

	if (!n)
		return;

	for (i = 0; i < depth; i++)
		printf("  ");

	if (n->flags & BT_FLAG_FREE)
		printf("`- (deleted node)\n");
	else
		printf("`- %p\n", n->value);

	tree_dump(n->left, depth+1);
	tree_dump(n->right, depth+1);
}
Example #4
0
int
main(int argc, const char *argv[])
{
  apr_pool_t *pool;
  int exit_code = EXIT_SUCCESS;
  svn_error_t *err;
  const char *path;
  const char *cmd;

  if (argc < 2 || argc > 4)
    {
      fprintf(stderr, "USAGE: entries-dump [--entries|--subdirs|--tree-dump] DIR_PATH\n");
      exit(1);
    }

  if (svn_cmdline_init("entries-dump", stderr) != EXIT_SUCCESS)
    {
      return EXIT_FAILURE;
    }

  /* Create our top-level pool.  Use a separate mutexless allocator,
   * given this application is single threaded.
   */
  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));

  path = svn_dirent_internal_style(argv[argc-1], pool);

  if (argc > 2)
    cmd = argv[1];
  else
    cmd = NULL;

  if (!cmd || !strcmp(cmd, "--entries"))
    err = entries_dump(path, NULL, pool);
  else if (!strcmp(cmd, "--subdirs"))
    err = directory_dump(path, pool);
  else if (!strcmp(cmd, "--tree-dump"))
    err = tree_dump(path, pool);
  else
    err = svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
                            "Invalid command '%s'",
                            cmd);
  if (err)
    {
      svn_handle_error2(err, stderr, FALSE, "entries-dump: ");
      svn_error_clear(err);
      exit_code = EXIT_FAILURE;
    }

  /* Clean up, and get outta here */
  svn_pool_destroy(pool);
  apr_terminate();

  return exit_code;
}
Example #5
0
static void
test(void)
{
	const Key list[] = {
		{12, {0x20, 0x10, 0x00, 0x00}},
		{12, {0x20, 0x20, 0x00, 0x00}},
		{13, {0x20, 0x18, 0x00, 0x00}}
	};
	const int n = sizeof(list) / sizeof(list[0]);
	CritbitPos pos;
	Critbit tree;
	Tuple *t;
	int ret;
	int i, j;

	critbit_init(&tree);

	for (i = 0; i < n; i++) {
		t = critbit_lookup(&tree, list[i].oct, list[i].nbits, &pos);
		assert(t == NULL);

		t = malloc(sizeof(Tuple));
		assert(t != NULL);

		printf("cbit: %d\n", pos.bit);

		t->key = list[i];
		t->val = i;
		ret = critbit_insert(&tree, t, &pos);
		assert(ret == 0);

		printf("===> Insert %d\n", i);
		printf("nums: %d\n", tree.nums);
		tree_dump(tree.root, 0);
	}

	for (i = 0; i < n; i++) {
		t = critbit_lookup(&tree, list[i].oct, list[i].nbits, NULL);
		assert(t != NULL);

		printf("get key:");
		for (j = 0; j < 4; j++) {
			printf(" %02x", t->key.oct[j]);
		}
		printf("/%d\n", t->key.nbits);
		printf("get val: %d\n", t->val);

		assert(memcmp(&t->key, &list[i], sizeof(t->key)) == 0);
	}
}
Example #6
0
//================================================================================
void tree_dtor (node* tree) {

    if (tree == NULL) {
        tree_dump(tree);
        return;
    }

    if (tree->left != NULL)
        tree_dtor(tree->left);

    if (tree->rght != NULL)
        tree_dtor(tree->rght);

    free(tree->info);
    free(tree);

    return;
}
Example #7
0
static void
test(void)
{
	const char *list[] = {
		"10.0.0.1",
		"10.0.0.2",
		"11.0.0.1"
	};
	const int n = sizeof(list) / sizeof(list[0]);
	struct in_addr addr;
	CritbitPos pos;
	Critbit tree;
	Tuple *t;
	int ret;
	int i;

	critbit_init(&tree);

	for (i = 0; i < n; i++) {
		inet_pton(AF_INET, list[i], &addr);
		t = critbit_lookup(&tree, &addr, 32, &pos);
		assert(t == NULL);

		t = malloc(sizeof(Tuple));
		assert(t != NULL);

		t->key.mask = 32;
		t->key.addr = addr;
		t->val = i;
		ret = critbit_insert(&tree, t, &pos);
		assert(ret == 0);

		printf("===> Insert %d\n", i);
		printf("nums: %d\n", tree.nums);
		tree_dump(tree.root, 0);
	}
}
Example #8
0
int tree_optimize(FILE* strout, tree_head* syntax_tree)
{
	fprintf(strout, "\n\nOptimizing...........\n");
	bool is_optimized = false;
	int ret = tree_optimize(syntax_tree -> root, &is_optimized);
	int _size = 0;
	ret = tree_check(syntax_tree -> root, &_size);
	
	VERIFY(ret == SNTX_DIV_BY_ZERO, 0, "MAIN: There's division by zero");
	

	while (is_optimized == true)
	{
		is_optimized = false;
		ret = tree_optimize(syntax_tree -> root, &is_optimized);
		VERIFY(ret == SNTX_DIV_BY_ZERO, 0, "MAIN: There's division by zero");

	}
	fprintf(strout, "\n\nDONE!\n");
	
	tree_dump(strout, syntax_tree);

	return CPLR_OK;
}