예제 #1
0
파일: core.c 프로젝트: jakobwesthoff/lucie
static int L_readini( lua_State* L ) 
{
    const char* filename;
    inifile_t* inifile            = NULL;
    inireader_iterator_t* iter    = NULL;
    inireader_entry_t* current    = NULL;
    btree_element_t* root         = NULL;
    btree_element_t* groupelement = NULL;
    btree_element_t* grouproot    = NULL;

    PARAM_STRING( filename );

    if ( ( inifile = inireader_open( filename ) ) == NULL ) 
    {
        return_error();
    }

    // Add every entry into a btree to get the arrays and groups in one piece later
    DEBUGLOG( "Creating btree" );
    root = btree_create();
    iter = inireader_get_iterator( inifile, 0, 0, 0, 0 );
    DEBUGLOG( "Filling up btree" );
    for ( current = inireader_iterate( iter ); current != NULL; current = inireader_iterate( iter ) )         
    {
        DEBUGLOG( "Searching for or adding group: %s", current->group );
        // Find group element
        groupelement = btree_find( root, current->group );        
        if ( groupelement == NULL ) 
        {
            // A new grouproot needs to be created
            DEBUGLOG( "Creating new grouproot" );
            grouproot = btree_create();
            btree_add( &root, current->group, grouproot );
        }
        else 
        {
            // Retrieve the already added grouproot
            DEBUGLOG( "Setting grouproot" );
            grouproot = ( btree_element_t* )groupelement->data;
        }

        // Add the new element to the grouptree
        btree_add( &grouproot, current->identifier, current );
    }
    
    // Traverse the tree and put our inivalues onto the lua stack
    DEBUGLOG( "Creating initial lua table" );
    lua_newtable( L );    
    readini_tree_traverse( L, root );
    DEBUGLOG( "Freeing the btree data" );
    // Free the group trees
    readini_tree_free( root );
    // Free the main tree
    btree_free( root );
    // Close the inifile
    inireader_close( inifile );
    
    return 1;
}
예제 #2
0
void *
xmp_init (struct fuse_conn_info *conn)
{
  struct rlimit rlim;
  int ret;
  ret = getrlimit(RLIMIT_MEMLOCK , &rlim);
  if (ret == 0)
  {
    fprintf(stderr, "memlock limit = soft %lu hard %lu\n",
            rlim.rlim_cur, rlim.rlim_max);
  }
  else
  {
    fprintf(stderr, "getrlimit %s", strerror(ret));
  }
  rlim.rlim_cur = 524288000;
  rlim.rlim_max = 624288000;
  ret = setrlimit(RLIMIT_MEMLOCK, &rlim);
  if (ret == 0)
  {
    fprintf(stderr, "memlock limit = soft %lu hard %lu\n",
            rlim.rlim_cur, rlim.rlim_max);
    ret = mlockall(MCL_CURRENT|MCL_FUTURE);
    if (ret == 0)
    {
      fprintf(stderr, "Made all memory pinned!\n");
    }
  }
  else
  {
    fprintf(stderr, "Unable to set rlimit. Need root access\n");
  }

  mem_add = 0;
  mem_find = 0;
  binode_add = 0;
  binode_find = 0;
  block_inode_tree = btree_create (3);
  block_inode_tree->value = value;
  block_inode_tree->key_size = keysize;
  block_inode_tree->data_size = datasize;

  memory_tree = btree_create (3);
  memory_tree->value = value;
  memory_tree->key_size = keysize;
  memory_tree->data_size = datasize;

  
  return FUSEXMP_DATA;
}
예제 #3
0
void btree_test() {
	struct btree *node1 = btree_create(NULL, TYPE_INT, 1);
	struct btree *node2 = btree_create(NULL, TYPE_INT, 2);
	struct btree *node3 = btree_create(NULL, TYPE_INT, 3);
	struct btree *node4 = btree_create(NULL, TYPE_INT, 4);
	struct btree *node5 = btree_create(NULL, TYPE_INT, 5);
	struct btree *node6 = btree_create(NULL, TYPE_INT, 6);
	struct btree *node7 = btree_create(NULL, TYPE_INT, 7);
	struct btree *node8 = btree_create(NULL, TYPE_INT, 8);
	node1->left = node2;
	node1->right = node3;
	node2->left = node4;
	node2->right = node5;
	node3->left = node6;
	node3->right = node7;
	node4->left = node8;

	fprintf(stdout, "preorder:\n");
	btree_preorder(node1);

	fprintf(stdout, "postorder:\n");
	btree_postorder(node1);

	fprintf(stdout, "inorder:\n");
	btree_inorder(node1);
	
	fprintf(stdout, "btree_search(node5, node8) = %d\n", btree_search(node5, node8));	
	fprintf(stdout, "btree_search(node4, node8) = %d\n", btree_search(node4, node8));	

	btree_destroy(node1);
}
예제 #4
0
int main()
{
    int arr[] = {18, 31, 12, 10, 15, 48, 45, 47, 50, 52, 23, 30, 20};
//    int arr[] = {18, 31, 12, 10};

    btree_node *root = btree_create();

    for(int i = 0; i < sizeof(arr) / sizeof(int); i++)
    {
        root = btree_insert(root, arr[i]);
        btree_level_display(root);
        btree_linear_print(root);
    }

    //int todel[] = {15, 18, 23, 30, 31, 52, 50};
    int todel[] = {45, 30, 12, 10};
    for(int i = 0; i < sizeof(todel) / sizeof(int); i++)
    {
        printf("after delete %d\n", todel[i]);
        root = btree_delete(root, todel[i]);
        btree_level_display(root);
        btree_linear_print(root);
    }

    return 0;
}
예제 #5
0
char *test_btree_create()
{
	root = btree_create(s);
	mu_assert(root != 0, "btree did not allocate root page");

	return NULL;
}
예제 #6
0
/**
* @brief test case for random number insert, search and delete.
*/
void testcase_for_random() {
	TREE* T = btree_create();
	int i = 0, n = 100;
	int _t = 0;
	srand(time(NULL));
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("btree_insert(T, %d) = %d\n", _t, btree_insert(T, _t));
	}
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("btree_search(T, %d) = %d\n", _t, btree_search(T, _t));
	}

	printf("btree_traveral: ");
	btree_traveral(T, printout_node);
	printf("\n");

	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("btree_delete(T, %d) = %d\n", _t, btree_delete(T, _t));
	}

	printf("btree_traveral: ");
	btree_traveral(T, printout_node);
	printf("\n");

	btree_destory(T);
}
예제 #7
0
node_bt    *btree_insert(node_bt *node, void *data, int(*func)(void*,void*), void *key)
{
  node_bt  *new_node;
  node_bt  *previos;
  node_bt  *root;
  int compare_result;

  root = node;
  new_node = btree_create(data);
  while(root) {
    previos = root;
    compare_result = func(root->data, key);     
    if (compare_result < 0)
      root = root->left;
    else if (compare_result > 0)
      root = root->right;
    else
      break; 
  }
  if (compare_result == 0)
    previos->data = data;
  else 
    if (compare_result > 0)
      previos->right = new_node;
    else
      previos->left = new_node; 
  
  return node;
} 
예제 #8
0
int main(void)
{
	btree_tree *tmp;
	uint32_t data_idx;
	size_t size;
	time_t ts;
	char *data;
	int i;
	char testdata[11];

	// testing too large data
	tmp = btree_create("test.mmap", 102, 204, 10);
	if (!tmp) {
		printf("Couldn't create tree from disk image.\n");
		exit(1);
	}
	for (i = 0; i < 205; i++) {
		if (btree_insert(tmp, i * 3, &data_idx)) {
			sprintf(testdata, "H: %07d", i);
			btree_set_data(tmp, data_idx, testdata, 10, time(NULL));
			data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
			printf("%s %zd\n", data, size);
		}
	}

	btree_dump(tmp);
	btree_free(tmp);

	return 0;
}
예제 #9
0
int main()
{
	//B树的root结点
	btree_node * root;
	btree_node *btree = btree_create();

	root = btree_insert(btree, 3);

	root = btree_insert(root, 5);
	root = btree_insert(root, 7);
	root = btree_insert(root, 11);
	root = btree_insert(root, 8);
	root = btree_insert(root, 9);
	root = btree_insert(root, 1);
	root = btree_insert(root, 12);
	root = btree_insert(root, 10);
	root = btree_insert(root, 2);
	root = btree_insert(root, 4);
	root = btree_insert(root, 6);
	root = btree_insert(root, 13);
	root = btree_insert(root, 16);
	root = btree_insert(root, 14);

	printf("The Graph of B-Tree is :\n\n");
	btree_print_v(root, 0);

	return 0;
}
예제 #10
0
int insert (b_tree** root ,  i_primario* element){	//k is the insertion_key

	int j;
	b_tree* aux = (*root);

	
	if(aux->i_counter == (ORDEM-1)){
		// NÓ ESTÁ CHEIO

			//Criação de um novo nó pai
		b_tree* parent;
		btree_create(&parent);

			//Definição das informações do novo nó pai
		parent->leaf 		= 0;
		parent->branches[0] = aux;
		(*root) 			= parent;

		splitting(root, 0, &aux);

		
		insert_nonfull(&parent, element);
		
		return FUNCTION_OK;
	}else{
		// NÓ NÃO ESTÁ CHEIO
		insert_nonfull(&aux, element);

	}
	return FUNCTION_OK;
}
예제 #11
0
int main(int argc, char *argv[])
{
	btree_tree *tmp;
	FILE *f;
	char urlBuffer[2048], *data;
	uint64_t id;
	uint64_t i = 0;
	uint32_t data_idx;

	tmp = btree_create("test.mmap", 128, 700000, 2048);
	if (!tmp) {
		printf("Couldn't create tree from disk image.\n");
		exit(1);
	}

	f = fopen(argv[1], "r");
	while (!feof(f)) {
		fgets(urlBuffer, 2048, f);
		data = strchr(urlBuffer, ' ');
		if (data) {
			data++;
			data[-1] = '\0';
			id = atoll(urlBuffer);
			if (btree_insert(tmp, id, &data_idx) == 1) {
				btree_set_data(tmp, data_idx, data, strlen(data), time(NULL));
			}
		}
		i++;
	}

	btree_free(tmp);

	return 0;
}
예제 #12
0
int main(void)
{
	btree_tree *tmp;
	int error = 0;

	tmp = btree_create("test.mmap", 3, 400, 1024, &error);
	if (!tmp) {
		printf("Couldn't create tree from disk image error %d.\n", error);
		exit(1);
	}

	setup(tmp);
	btree_insert(tmp, 'd');
	btree_insert(tmp, 'f');
	btree_insert(tmp, 'v');

	btree_delete(tmp, 'i');
	btree_delete(tmp, 'f');
	btree_delete(tmp, 'e');
	btree_delete(tmp, 'y');
	btree_delete(tmp, 't');
	btree_dump_dot(tmp);

	btree_close(tmp);

	return 0;
}
예제 #13
0
int main(void)
{
	btree_tree *tmp;
	uint32_t data_idx;

	tmp = btree_create("test.mmap", 3, 400, 1024);
	if (!tmp) {
		printf("Couldn't create tree from disk image.\n");
		exit(1);
	}

	setup(tmp);
	btree_insert(tmp, 'd', &data_idx);
	btree_insert(tmp, 'f', &data_idx);
	btree_insert(tmp, 'v', &data_idx);

	btree_delete(tmp, 'i');
	btree_delete(tmp, 'f');
	btree_delete(tmp, 'e');
	btree_delete(tmp, 'y');
	btree_delete(tmp, 't');
	btree_dump_dot(tmp);


	btree_free(tmp);

	return 0;
}
int main(void)
{
	btree_tree *tmp;
	uint32_t data_idx;
	size_t *size;
	time_t *ts;
	char *data;
	int i, tmp_key;
	char testdata[11];
	int error = 0;

	/* testing too large data */
	tmp = btree_create("test.mmap", 3, 6, 10, &error);
	if (!tmp) {
		printf("Couldn't create tree from disk image, errno %d.\n", error);
		exit(1);
	}

	for (i = 0; i < 205; i++) {
		tmp_key = i * 3;
		if (0 == btree_insert(tmp, tmp_key)) {
			sprintf(testdata, "H: %07d", i);
			btree_set_data(tmp, tmp_key, testdata, 10, time(NULL));
			btree_get_data(tmp, tmp_key, &data_idx, (void **)&data, &size, &ts);
			printf("%s %zd\n", data, *size);
			btree_data_unlock(tmp, data_idx);
		}
	}

	btree_dump(tmp);
	btree_close(tmp);

	return 0;
}
BPlusTree::BPlusTree(void)
{
	// 先判断文件是否存在
 	// windows下,是io.h文件,linux下是 unistd.h文件 
  	// int access(const char *pathname, int mode);
   	if(-1==access("define.Bdb",F_OK))
    {
	   	// 不存在 ,创建 
//	   	pfile = fopen("bplus.bp","w");
   		roots = btree_create();
	}
 	else
  	{
//	   	pfile = fopen("bplus.bp","r+");
	   	roots = btree_create();
//	   	fread(roots,sizeof(roots),1,pfile);
   	}
}
예제 #16
0
파일: vfs.c 프로젝트: helgefmi/termos
struct vfs *create_empty_vfs(int fsnum)
{
    struct vfs *ret = (struct vfs*) kmalloc(sizeof(struct vfs));
    memset(ret, 0, sizeof(struct vfs));
    ret->vfs_ops = fstypes[fsnum].vfs_ops;
    ret->vfs_mounts = btree_create(&btree_cmp_u32);

    return ret;
}
예제 #17
0
파일: bstree.c 프로젝트: hungly/Pacman
void bstree_insert(int value, struct bstree_node *node)
{
	if (node != NULL)
	{
		struct btree_node *current;
		if (node->root == NULL)
		{
			node->root = btree_create(value, NULL);
		}
		else
		{
			current = node->root;
			while (current != NULL)
			{
				if (value < current->value)
				{
					if (current->left == NULL)
					{
						current->left = btree_create(value, current);
						break;
					}
					else
					{
						current = current->left;
					}
				}
				else
				{
					if (current->right == NULL)
					{
						current->right = btree_create(value, current);
						break;
					}
					else
					{
						current = current->right;
					}
				}
			}
		}
	}
}
예제 #18
0
int main() {
  printf("Test BTree\n");

  btree_t *btree = btree_create();
  if (!btree)
    return 1;
  btree_free(btree);

  printf("Done.\n");
  return 0;
}
예제 #19
0
/**
* @brief test case for single insert, search and delete method.
*/
void testcase_for_single() {
	TREE* T = btree_create();

	printf("btree_insert(T, 32) = %d\n", btree_insert(T, 32));

	printf("btree_search(T, 32) = %d\n", btree_search(T, 32));

	printf("btree_delete(T, 32) = %d\n", btree_delete(T, 32));

	printf("btree_search(T, 32) = %d\n", btree_search(T, 32));

	printf("btree_traveral: ");
	btree_traveral(T, printout_node);
	printf("\n");

	btree_destory(T);
}
예제 #20
0
int
main()
{
    btree_t *b;
    uint32_t i, *x;
    uint32_t v[] = {15, 5, 16, 3, 12, 20, 10, 13, 18, 23, 6, 7};
    uint32_t nv = sizeof(v) / sizeof(v[0]);

    btree_create(&b);

    for(i = 0; i < nv; i++) {
        x = (uint32_t*)xmalloc(sizeof(uint32_t));
        *x = (uint32_t)random();
        if (btree_add(b, v[i], (void*)x) != TRUE) {
            printf("Fail Add %lu %lu\n", v[i], *x);
        }
    }

    printf("depth %d\n", btree_depth(b->root));
    btree_dump(b);

    sleep(3);
    btree_remove(b, 5, (void*)&x);
    btree_dump(b);
    sleep(3);
    btree_remove(b, 16, (void*)&x);
    btree_dump(b);
    sleep(3);
    btree_remove(b, 13, (void*)&x);
    btree_dump(b);

    while (btree_get_root_key(b, &i)) {
        if (btree_remove(b, i, (void*)&x) == FALSE) {
            fprintf(stderr, "Failed to remove %lu\n", i);
        }
        btree_dump(b);
        sleep(1);
    }

    if (btree_destroy(&b) == FALSE) {
        printf("Failed to destroy \n");
    }

    return 0;
}
예제 #21
0
파일: main.c 프로젝트: liexusong/btree-1
int main(int ac,char * av[])
{
	int i = 0;
	btree * tree;
	bt_key_val * kv;
	int item = 0x43;
	int count = 0;
	int order;
	
	srandom(time(NULL));

	if (ac > 1) {
		count = atoi(av[1]);
	}
	
	for(order=60;order<61;order++) {

            
	    tree = btree_create(order);	
            tree->value = value;
            tree->key_size = keysize;
            tree->data_size = datasize;
	    
	    for (i=0;i<count;i++) {	
		    kv = (bt_key_val*)malloc(sizeof(*kv));
		    kv->key = malloc(sizeof(int));		
		    int rval = random()%1024;
		    *(int *)kv->key = rval;
		    kv->val = malloc(sizeof(int));
		    *(int *)kv->val = rval;
		    btree_insert_key(tree,kv);
	    }
	    
	    /*
	    for (i= count - 1; i > -1; i-= (random()%5)) {	
		    item = values[i];
		    btree_delete_key(tree,tree->root,&item);
	    }
	    */
            // btree_destroy(tree);
	}
	return 0;
}
예제 #22
0
int main(int argc, char **argv)
{
        printf("-------------------------------------------------\n");
        printf("starts to have a test of binary tree.\n");
        printf("-------------------------------------------------\n");
        btree tree = btree_create();
        btree_node *dataone = btree_node_make("hello");
        btree_insert_child_tree(tree, PRE_ORDER, dataone);
        btree_node *datatwo = btree_node_make("World");
        btree_insert_child_tree(dataone, PRE_ORDER, datatwo);
        btree_traverse(tree, IN_ORDER, btree_node_print);
        printf("now length of tree is %d\n", btree_depth(tree));
        printf("-------------------------------------------------\n");
        printf("test is over, everything is gone be alright.\n");
        printf("-------------------------------------------------\n");
        printf("\n");

        return EXIT_SUCCESS;
}
예제 #23
0
int main(int argc, char **argv)
{
  BTree *tree = btree_create(int_compare);
  int n = atoi(argv[1]);
  int a[n];
  //int a[] = {1, 3, 2, 5, -1, 19, 15, 45, 9, 6, -4};
  n = sizeof(a) / sizeof(a[0]);
  //n = 3;
  for (int i = 0; i < n; ++i) {
    //a[i] = i + 1;
    a[i] = rand() % 1000;
    btree_insert(tree, (void*)&a[i]);
  }
  for (int i = 0; i < n / 2; ++i) {
    btree_remove(btree_find(tree, &a[i]));
  }
  int expected_height = 2 * ceil(log(n + 1) / log(2)) + 1;
  btree_dump_dot(tree, node_attrs);
  btree_destroy(tree);
}
예제 #24
0
파일: pdb.c 프로젝트: uclmediatools/rat
int
pdb_create(pdb_t **pp)
{
        pdb_t *p;

        p = (pdb_t*)xmalloc(sizeof(pdb_t));
        if (p == NULL) {
                *pp = NULL;
                return FALSE;
        }

        if (btree_create(&p->db) == FALSE) {
                xfree(p);
                *pp = NULL;
                return FALSE;
        }

        p->nelem = 0;
        *pp = p;
        return TRUE;
}
/*
 * Main - Try inserting / searching / deleting some nodes from a tree.
 */
int main(void) {
  printf("-- Simple Binary Search Tree --\n");

  /* Populate a tree */
  struct btree_tree *test = btree_create();
  btree_insert(test, 10);
  btree_insert(test, 3);
  btree_insert(test, 15);
  btree_insert(test, 9);
  btree_insert(test, 14);
  btree_insert(test, 20);
  btree_insert(test, 12);
  btree_insert(test, 21);
  btree_insert(test, 16);
  btree_insert(test, 17);
  btree_insert(test, 18);
  btree_insert(test, 11);
  btree_insert(test, 13);
  btree_insert(test, 2);

  printf("\nThere are now %i items in the tree.\n\n", test->count);

  int item;

  /* Remove an item with no right child */
  item = 2;
  test_remove(test, item);

  /* Remove an item with a right child that has no left child */
  item = 12;
  test_remove(test, item);

  /* Remove an item with a right child that has a left child */
  item = 20;
  test_remove(test, item);

  printf("There are now %i items in the tree.", test->count);

  return EXIT_SUCCESS;
}
예제 #26
0
파일: btree.c 프로젝트: tobytobsen/RRLoader
int main(void) {
	btree_t bt;
	btree_node_t *n;
	char datatbl[] = {'a', 'b', 'd', 'd', 'a'};

	btree_create(&bt);
	btree_insert(&bt, btree_node_create(&datatbl[0]));
	btree_insert(&bt, btree_node_create(&datatbl[1]));
	btree_insert(&bt, btree_node_create(&datatbl[2]));
	
	n = btree_node_create(&datatbl[3]);
	btree_insert(&bt, n);
	btree_remove(&bt, n, false);
	btree_node_release(n);

	btree_insert(&bt, btree_node_create(&datatbl[4]));
	btree_release(&bt);

	printf("Last Error: %s (%d)\r\n", 
		libnet_str_error(libnet_error_get()), libnet_error_get());
	return 0;
}
예제 #27
0
int main(void)
{
	btree_tree *tmp;
	uint32_t data_idx;
	size_t size;
	time_t ts;
	char *data;

	// testing too large data
	tmp = btree_create("test.mmap", 3, 6, 10);
	if (!tmp) {
		printf("Couldn't create tree from disk image.\n");
		exit(1);
	}
	if (btree_insert(tmp, 'X', &data_idx)) {
		btree_set_data(tmp, data_idx, "HelloWorl1", 10, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	if (btree_insert(tmp, 'Q', &data_idx)) {
		btree_set_data(tmp, data_idx, "HelloWorld2", 10, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	if (btree_insert(tmp, 'D', &data_idx)) {
		btree_set_data(tmp, data_idx, "HelloWorld3", 11, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	if (btree_insert(tmp, 'Z', &data_idx)) {
		btree_set_data(tmp, data_idx, "HelloWorl4", 11, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	if (btree_insert(tmp, 'A', &data_idx)) {
		btree_set_data(tmp, data_idx, "HelloWorl5", -1, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	if (btree_insert(tmp, 'C', &data_idx)) {
		btree_set_data(tmp, data_idx, "HelloWorl6", 0, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	if (btree_insert(tmp, 'G', &data_idx)) {
		btree_set_data(tmp, data_idx, "TooMany1", 8, time(NULL));
		data = (char*) btree_get_data(tmp, data_idx, &size, &ts);
		printf("%s %zd\n", data, size);
	}

	btree_dump(tmp);
	btree_free(tmp);

	return 0;
}
예제 #28
0
b_tree* splitting(b_tree** root, int position, b_tree** splitting_target){	

	/*	VARIÁVEIS:
			~ root: endereço do nó que se torna o novo pai.
			~ position: posição de separação
			~ splitting_target: endereço do nó que será dividido
	*/

	int j;
	b_tree *target, *parent;

	target 	= *splitting_target;
	parent 	= *root;


		/*Definição de aux: nó irmão do nó que está sendo 
			dividido (target). Compartilha o nó pai (parent),
		*/
	b_tree* aux;
	btree_create(&aux);

	aux->leaf 		= target->leaf;
	aux->i_counter 	= 0;

	
		//Transferência de filhos
	if ( (target->leaf) == 0 ){
		
		for(j = 0; j + DIVISOR + 1 < ORDEM; j++){
			aux->branches[j] = target->branches[j + DIVISOR + 1];

		target->branches[j + DIVISOR + 1] = NULL;
		}
	}


		//Transferência de chaves imediatas
	for(j = 0; j + DIVISOR + 1< ORDEM - 1; j++){
		aux->index[j] 	= target->index[j + (DIVISOR + 1)];
		target->index[j + (DIVISOR + 1)] = NULL;
		

		if (aux->index[j] != NULL)
			aux->i_counter++;	

	}





		//Posicionamento dos filhos
	for(j = parent->i_counter; j > position; j--)
		parent->branches[j+1] = parent->branches[j];
	parent->branches[position + 1] 		= aux;
	parent->branches[position] 			= target;




		//Eleição do divisor
	for(j = parent->i_counter + 1; j > position; j--)
		parent->index[j] = parent->index[j-1];	//a função não entrou nesse loop durante o primeiro split. propenso a erros futuros


	parent->index[position] = target->index[DIVISOR];
	parent->i_counter++;
	target->index[DIVISOR] 	= NULL;
	target->i_counter 		= DIVISOR;
	

		(*root)				= parent;
		(*splitting_target)	= target;

	return parent;
}
예제 #29
0
int main(void)
{
    btree_tree *tmp;
    uint32_t data_idx;
    char data[1024];
    int error = 0;

    memset(data, 4, 1023);
    memset(data+1023, 0, 1);

    tmp = btree_create("test.mmap", 3, 400, 1024, &error);
    if (!tmp) {
        printf("Couldn't create tree from disk image, errno %d.\n", error);
        exit(1);
    }

    insert_item(tmp, 'A');
    data_idx = insert_item(tmp, 'L');
    memcpy(tmp->data + data_idx * 1024, data, 1024);
    data_idx = insert_item(tmp, 'D');
    memcpy(tmp->data + data_idx * 1024, data, 1024);
    insert_item(tmp, 'F');

    insert_item(tmp, '4');
    insert_item(tmp, '2');
    insert_item(tmp, '3');
    insert_item(tmp, '5');
    insert_item(tmp, '1');

    insert_item(tmp, 'N');
    insert_item(tmp, 'P');
    insert_item(tmp, 'd');
    insert_item(tmp, 'f');
    insert_item(tmp, 'n');
    insert_item(tmp, 'p');
    insert_item(tmp, 'H');
    insert_item(tmp, 'C');
    insert_item(tmp, 'B');
    insert_item(tmp, 'E');
    insert_item(tmp, 'G');

    insert_item(tmp, 'I');
    insert_item(tmp, 'K');
    insert_item(tmp, 'J');
    insert_item(tmp, 'M');
    insert_item(tmp, 'o');

    insert_item(tmp, 'q');
    insert_item(tmp, 'r');
    insert_item(tmp, 'i');

    insert_item(tmp, 'j');
    insert_item(tmp, 'k');
    insert_item(tmp, 'd');
    insert_item(tmp, 't');
    insert_item(tmp, 'm');

    insert_item(tmp, 'O');
    insert_item(tmp, 'Q');
    insert_item(tmp, 'R');
    insert_item(tmp, 'S');
    insert_item(tmp, 'T');
    insert_item(tmp, 'U');

    insert_item(tmp, 'x');
    insert_item(tmp, 'w');
    insert_item(tmp, 'y');
    insert_item(tmp, 'u');
    insert_item(tmp, 'v');

    btree_dump_dot(tmp);
    btree_close(tmp);

    return 0;
}
예제 #30
0
파일: sync.c 프로젝트: atikinn/db165
static
void restore_btree(struct column *col) {
    /* For now recreate from scratch */
    col->index->index = btree_create(col->clustered);
    btree_load(col->index->index, &col->data);
}