Beispiel #1
0
    void write_int(Properties &properties, int nbits, int val) {
#ifdef STATS
        symbols++;
#endif
        CompoundSymbolChances<BitChance,bits> &chances = find_leaf(properties);
        set_selection_and_update_property_sums(properties,chances);
        CompoundSymbolChances<BitChance,bits> &chances2 = find_leaf(properties);
        coder.write_int(chances2, selection, nbits, val);
    }
Beispiel #2
0
    int read_int(Properties &properties, int nbits) {
#ifdef STATS
        symbols++;
#endif
        CompoundSymbolChances<BitChance,bits> &chances = find_leaf(properties);
        set_selection_and_update_property_sums(properties,chances);
        CompoundSymbolChances<BitChance,bits> &chances2 = find_leaf(properties);
        return coder.read_int(chances2, selection, nbits);
    }
Beispiel #3
0
//{{{void test_split_node_non_root_parent_has_room(void)
void test_split_node_non_root_parent_has_room(void)
{
    int V[5] = {2,3,4,5,6};
    struct node *l1 = new_node();
    l1->is_leaf = 1;
    l1->num_keys = 4;
    l1->keys[0] = 1;
    l1->keys[1] = 2;
    l1->keys[2] = 3;
    l1->keys[3] = 4;

    l1->pointers[0] = (void*)V;
    l1->pointers[1] = (void*)(V + 1);
    l1->pointers[2] = (void*)(V + 2);
    l1->pointers[3] = (void*)(V + 2);

    struct node *n1 = new_node();
    n1->keys[0] = 6;
    n1->num_keys = 1;
    n1->pointers[0] = (void *)l1;
    l1->parent = n1;

    struct node *root = new_node();
    root->keys[0] = 9;
    root->num_keys = 1;
    root->pointers[0] = (void *)n1;
    n1->parent = root;

    l1->num_keys = 5;
    l1->keys[4] = 5;

    root = split_node(root, l1);

    TEST_ASSERT_EQUAL(2, l1->num_keys);
    TEST_ASSERT_EQUAL(3, l1->next->num_keys);
    TEST_ASSERT_EQUAL(2, n1->num_keys);

    int A_n1[2] = {3,6};

    int i;
    for (i = 0; i < n1->num_keys; ++i)
        TEST_ASSERT_EQUAL(A_n1[i], n1->keys[i]);

    TEST_ASSERT_EQUAL(l1, find_leaf(root, 1));
    TEST_ASSERT_EQUAL(l1, find_leaf(root, 2));
    TEST_ASSERT_EQUAL(l1->next, find_leaf(root, 3));
    TEST_ASSERT_EQUAL(l1->next, find_leaf(root, 4));
    TEST_ASSERT_EQUAL(l1->next, find_leaf(root, 5));

    TEST_ASSERT_EQUAL(l1, n1->pointers[0]);
    TEST_ASSERT_EQUAL(l1->next, n1->pointers[1]);

}
Beispiel #4
0
RC index_btree::index_read(idx_key_t key, itemid_t *& item, 
	uint64_t thd_id, int64_t part_id) 
{
	RC rc = Abort;
	glob_param params;
	assert(part_id != -1);
	params.part_id = part_id;
	bt_node * leaf;
	find_leaf(params, key, INDEX_READ, leaf);
	if (leaf == NULL)
		M_ASSERT(false, "the leaf does not exist!");
	for (UInt32 i = 0; i < leaf->num_keys; i++) 
		if (leaf->keys[i] == key) {
			item = (itemid_t *)leaf->pointers[i];
			release_latch(leaf);
			(*cur_leaf_per_thd[thd_id]) = leaf;
			*cur_idx_per_thd[thd_id] = i;
			return RCOK;
		}
	// release the latch after reading the node

	printf("key = %ld\n", key);
	M_ASSERT(false, "the key does not exist!");
	return rc;
}
Beispiel #5
0
/*
 * Generate two lists for all places and workers below the place pl in the HPT:
 * a list of places that are leaves in the tree (i.e. have no child places) and
 * a list of all workers in the HPT (which are implicitly leaves, by the
 * definition of a worker).
 *
 * This is done recursively to find all leaf places and workers in a global HPT.
 */
void find_leaf(place_t *pl, place_node_t **pl_list_cur,
               worker_node_t **wk_list_cur) {
    place_t *child = pl->child;
    if (child == NULL) {
        // Leaf, add it to the pl_list
        place_node_t *new_pl = (place_node_t *)malloc(sizeof(place_node_t));
        HASSERT(new_pl);
        memset(new_pl, 0x00, sizeof(place_node_t));
        new_pl->data = pl;
        (*pl_list_cur)->next = new_pl;
        *pl_list_cur = new_pl;
    } else {
        while (child != NULL) {
            find_leaf(child, pl_list_cur, wk_list_cur);
            child = child->nnext;
        }
    }

    hclib_worker_state *wk = pl->workers;
    while (wk != NULL) {
        // Add any workers to wk_list
        worker_node_t *new_ws = (worker_node_t *) malloc(sizeof(worker_node_t));
        HASSERT(new_ws);
        memset(new_ws, 0x00, sizeof(worker_node_t));
        new_ws->data = wk;
        (*wk_list_cur)->next = new_ws;
        *wk_list_cur = new_ws;
        wk = wk->next_worker;
    }
}
Beispiel #6
0
void Worker::find_leaf_wrapper(const ANNcoord x, const ANNcoord y, const ANNcoord side) {
  //Just a little dumb function to fill in the missing information of x and y
  //Call the inserter to quadtree for each "true" set of coordinates"

  for (int i=0; i<Globals::pow2dimm2; i++) {
    leaf_centers[i][0]=x;
    leaf_centers[i][1]=y;
  }
 
 
//  for (int i=0; i<Globals::pow2dimm2; i++) {
//    kdtree->annkSearch(leaf_centers[i],1,nnIdx,dists);
//    leaf_reprs[i]=nnIdx[0];

//    leaf_reprs[i]=kdtree->ann1Search(leaf_centers[i],asdf);
//  }


//  {boost::mutex::scoped_lock lock(leaf_mutex);
  for (int i=0; i<Globals::pow2dimm2; i++) {
    if (leaf_centers[i][0]*Globals::wspd_vectors[private_index][0] + 
        leaf_centers[i][1]*Globals::wspd_vectors[private_index][1] + 
     //   leaf_centers[i][3]*Globals::wspd_vectors[private_index][3] + 
        leaf_centers[i][2]*Globals::wspd_vectors[private_index][2] < 2*side)
    find_leaf(side,i);
//  }}
  }
}
Beispiel #7
0
/* re-locate the leaf if the point get out of the leaf */
kdtree* kdtree::backtrack_leaf(vector3f &point) {
	if (bbox.is_inside(point))
		return find_leaf(point);
	else if (is_root())
		return NULL;
	else
		return parent_kdtree->backtrack_leaf(point);
}
Beispiel #8
0
int octree_nearest(octree_t* tree, point_t* point)
{
  if (tree->root == NULL)
    return -1;

  octree_node_t* leaf = find_leaf(tree->root, &tree->bbox, point);
  if (leaf == 0) 
    return -1;
  else return leaf->leaf_node.index;
}
Beispiel #9
0
/**
 * Finds and returns the record to which a key refers.
 * 
 * @param root the root node
 * @param key the key of the object to find
 * @param verbose true to print info
 * @return 
 */
BtreeRecord_t * BTreeFind(BtreeNode_t * root, void *key, int (*keyCMP)(void *key1, void *key2)) {
    int i = 0;
    BtreeNode_t * c = find_leaf(root, key, keyCMP);
    if (c == NULL) return NULL;
    for (i = 0; i < c->num_keys; i++)
        if (keyCMP(key, c->keys[i]) == 0) break; //c->keys[i] == key
    if (i == c->num_keys)
        return NULL;
    else
        return (BtreeRecord_t *) c->pointers[i];
}
Beispiel #10
0
// Finds and returns the record to which a key refers.
record * find( node * root, int key, bool verbose ) {
    int i = 0;
    node * c = find_leaf( root, key, verbose );
    if (c == NULL) return NULL;
    for (i = 0; i < c->num_keys; i++)
        if (c->keys[i] == key) break;
    if (i == c->num_keys)
        return NULL;
    else
        return (record *)c->pointers[i];
}
Beispiel #11
0
/* Master deletion function.
 */
node * deletee(node * root, int key, int * value) {

  node * key_leaf;
  record * key_record;

  key_record = find(root, key, false, value);
  key_leaf = find_leaf(root, key, false);
  if (key_record != NULL && key_leaf != NULL) {
    root = delete_entry(root, key_leaf, key, key_record);
    free(key_record);
  }
  return root;
}
Beispiel #12
0
int is_data_in_mem(node *root,char *key)
{
    node *leaf;
    int i;
    leaf = find_leaf(root, key);
    if (leaf == NULL)
        return 0;
    for (i = 0; i < leaf->num_keys && strcmp(leaf->keys[i], key) != 0; i++)
        ;
    if (i == leaf->num_keys || NULL == leaf->pointers[i])
        return 0;
    return 1;
}
Beispiel #13
0
int is_key_exist(node *root,char *key)
{
    node *leaf;
    int i;
    leaf = find_leaf(root, key);
    if (leaf == NULL)
        return 0;
    for (i = 0; i < leaf->num_keys && strcmp(leaf->keys[i], key) != 0; i++)
        ;
    if (i == leaf->num_keys)
        return 0;
    return 1;
}
Beispiel #14
0
record *find(node *root, char *key)
{
    node *leaf;
    int i;
    leaf = find_leaf(root, key);
    if (leaf == NULL)
        return NULL;
    for (i = 0; i < leaf->num_keys && strcmp(leaf->keys[i], key) != 0; i++)
        ;
    if (i == leaf->num_keys)
        return NULL;
    return (record *)leaf->pointers[i];
}
Beispiel #15
0
/* Finds and returns the record to which
 * a key refers.
 */
record * find( node * root, int key, bool verbose, int * value ) {
  int i = 0;
  node * c = find_leaf( root, key, verbose );
  if (c == NULL) return NULL;
  int aux = 0;
  for (i = 0; i < c->num_keys; i++)
  {
    if (c->keys[i] == key && ((record *)c->pointers[i])->value[0] == value[0] && ((record *)c->pointers[i])->value[1] == value[1] && ((record *)c->pointers[i])->value[2] == value[2]) break;
  }
  if (i == c->num_keys) 
    return NULL;
  else
    return (record *)c->pointers[i];
}
Beispiel #16
0
RC index_btree::index_insert(idx_key_t key, itemid_t * item, int part_id) {
	glob_param params;
	if (WORKLOAD == TPCC) assert(part_id != -1);
	assert(part_id != -1);
	params.part_id = part_id;
	// create a tree if there does not exist one already
	RC rc = RCOK;
	bt_node * root = find_root(params.part_id);
	assert(root != NULL);
	int depth = 0;
	// TODO tree depth < 100
	bt_node * ex_list[100];
	bt_node * leaf = NULL;
	bt_node * last_ex = NULL;
	rc = find_leaf(params, key, INDEX_INSERT, leaf, last_ex);
	assert(rc == RCOK);
	
	bt_node * tmp_node = leaf;
	if (last_ex != NULL) {
		while (tmp_node != last_ex) {
	//		assert( tmp_node->latch_type == LATCH_EX );
			ex_list[depth++] = tmp_node;
			tmp_node = tmp_node->parent;
			assert (depth < 100);
		}
		ex_list[depth ++] = last_ex;
	} else
		ex_list[depth++] = leaf;
	// from this point, the required data structures are all latched,
	// so the system should not abort anymore.
//	M_ASSERT(!index_exist(key), "the index does not exist!");
	// insert into btree if the leaf is not full
	if (leaf->num_keys < order - 1 || leaf_has_key(leaf, key) >= 0) {
		rc = insert_into_leaf(params, leaf, key, item);
		// only the leaf should be ex latched.
//		assert( release_latch(leaf) == LATCH_EX );
		for (int i = 0; i < depth; i++)
			release_latch(ex_list[i]);
//			assert( release_latch(ex_list[i]) == LATCH_EX );
	}
	else { // split the nodes when necessary
		rc = split_lf_insert(params, leaf, key, item);
		for (int i = 0; i < depth; i++)
			release_latch(ex_list[i]);
//			assert( release_latch(ex_list[i]) == LATCH_EX );
	}
//	assert(leaf->latch_type == LATCH_NONE);
	return rc;
}
Beispiel #17
0
bool index_btree::index_exist(idx_key_t key) {
	assert(false); // part_id is not correct now.
	glob_param params;
	params.part_id = key_to_part(key) % part_cnt;
	bt_node * leaf;
	// does not matter which thread check existence
	find_leaf(params, key, INDEX_NONE, leaf);
	if (leaf == NULL) return false;
	for (UInt32 i = 0; i < leaf->num_keys; i++)
    	if (leaf->keys[i] == key) {
            // the record is found!
			return true;
        }
	return false;
}
Beispiel #18
0
void *find(node *root, char *key)
{
    node *leaf;
    int i;
    leaf = find_leaf(root, key);
    if (leaf == NULL)
        return NULL;
    for (i = 0; i < leaf->num_keys && strcmp(leaf->keys[i], key) != 0; i++)
        ;
    if (i == leaf->num_keys)
        return NULL;
    if(NULL == leaf->pointers[i]){
       leaf->pointers[i] =  load_wireway_node(leaf->block->pointers_id[i]);
    }
    return leaf->pointers[i];
}
Beispiel #19
0
/**
 *	@brief Render the full map from the camera's current position.
 *	@param camera	The camera to render from
 */
void EQ3Map::render(RCamera* camera) {
    vector3 pos;
    int leaf, cluster;

    /* find the leaf and cluster the camera is at */
    camera->get_position(&pos);
    leaf = find_leaf(&pos);
    cluster = leafs[leaf].cluster;
    //DEBUG("[Render::Q3Map] cluster = %i", cluster);

#if 0

    /* render everything */
    int face = 0;

    for (; face < num_faces; ++face) {
        if (faces[face].type == Q3_FACETYPE_POLYGON)
            render_face(face);
    }

#else

    int i = num_leafs;
    struct q3bsp_leaf_t* t_leaf = NULL;

    for (; i >= 0; --i) {
        t_leaf = &leafs[i];

        /* check if this leaf cluster is visable from here */
        if (!is_cluster_visable(cluster, t_leaf->cluster))
            continue;

        /* if this cluster is not in the camera frustum, skip it */
        if (!camera->is_box_visable(t_leaf->mins[0], t_leaf->mins[1], t_leaf->mins[2],
                                    t_leaf->maxs[0], t_leaf->maxs[1], t_leaf->maxs[2]))
            continue;

        /* render all the faces in this leaf */
        int f = t_leaf->num_leaffaces;
        for (; f >= 0; --f) {
            int f_index = leaffaces[t_leaf->leafface + f].face;
            render_face(f_index);
        }
    }

#endif
}
Beispiel #20
0
//Main insertion function
node * insert( node * root, int key, int value ) {
 
    record * pointer;
    node * leaf;
 
    /* The current implementation ignores
     * duplicates.
     */
 
    if (find(root, key, false) != NULL)
        return root;
 
    /* Create a new record for the
     * value.
     */
    pointer = make_record(value);
 
 
    /* Case: the tree does not exist yet.
     * Start a new tree.
     */
 
    if (root == NULL)
        return start_new_tree(key, pointer);
 
 
    /* Case: the tree already exists.
     * (Rest of function body.)
     */
 
    leaf = find_leaf(root, key, false);
 
    /* Case: leaf has room for key and pointer.
     */
 
    if (leaf->num_keys < order - 1) {
        leaf = insert_into_leaf(leaf, key, pointer);
        return root;
    }
 
 
    /* Case:  leaf must be split.
     */
 
    return insert_into_leaf_after_splitting(root, leaf, key, pointer);
}
Beispiel #21
0
node *insert(node *root, char *key, void *data)
{
    node *leaf;
    int index, cond;
    leaf = find_leaf(root, key);
    if (!leaf){  // cannot find the leaf, the tree is empty
        return make_new_tree(key, data);
    }
    for (index = 0; index < leaf->num_keys && (cond = strcmp(leaf->keys[index], key)) < 0; index++)
        ;
    if (cond == 0)  // ignore duplicates
        return root;
    if (leaf->num_keys < size - 1){
        insert_into_leaf(leaf, index, key, data);
        return root;  // the root remains unchanged
    }
    return insert_into_leaf_after_splitting(root, leaf, index, key, data);
}
Beispiel #22
0
int find_range( node * root, int key_start, int key_end, bool verbose,
        int returned_keys[], void * returned_pointers[]) {
    int i, num_found;
    num_found = 0;
    node * n = find_leaf( root, key_start, verbose );
    if (n == NULL) return 0;
    for (i = 0; i < n->num_keys && n->keys[i] < key_start; i++) ;
    if (i == n->num_keys) return 0;
    while (n != NULL) {
        for ( ; i < n->num_keys && n->keys[i] <= key_end; i++) {
            returned_keys[num_found] = n->keys[i];
            returned_pointers[num_found] = n->pointers[i];
            num_found++;
        }
        n = n->pointers[order - 1];
        i = 0;
    }
    return num_found;
}
Beispiel #23
0
/**
 * Master insertion function.
 * Inserts a key and an associated value into
 * the B+ tree, causing the tree to be adjusted
 * however necessary to maintain the B+ tree
 * properties.
 * 
 * @param root the root nodes
 * @param key the key to be used to identify the object
 * @param value the pointer to the object
 * @return the new root node
 */
BtreeNode_t * BtreeInsert(BtreeNode_t * root, void *key, void *value, int (*keyCMP)(void *key1, void *key2)) {

    BtreeRecord_t * pointer;
    BtreeNode_t * leaf;

    /* The current implementation ignores
     * duplicates.
     */
    if ((pointer = BTreeFind(root, key, keyCMP)) != NULL) {
        return root;
    }

    /* Create a new record for the
     * value.
     */
    pointer = make_record(value);

    /* Case: the tree does not exist yet.
     * Start a new tree.
     */
    if (root == NULL)
        return start_new_tree(key, pointer);

    /* Case: the tree already exists.
     * (Rest of function body.)
     */

    leaf = find_leaf(root, key, keyCMP);

    /* Case: leaf has room for key and pointer.
     */

    if (leaf->num_keys < order - 1) {
        leaf = insert_into_leaf(leaf, key, pointer, keyCMP);
        return root;
    }


    /* Case:  leaf must be split.
     */

    return insert_into_leaf_after_splitting(root, leaf, key, pointer, keyCMP);
}
Beispiel #24
0
node * insert(node *root, int key, int value)
{
	record* pointer;
	node* leaf;
	
	pointer = make_record(value);

	if (root == NULL) 
		return start_new_tree(key, pointer);

	leaf = find_leaf(root, key);

	if (leaf->num_keys < order - 1) {
		leaf = insert_into_leaf(leaf, key, pointer);
		return root;
	}


	return insert_into_leaf_after_splitting(root, leaf, key, pointer);

	 
}
Beispiel #25
0
 //this function find a leaf with the specified key if it exists and returns the pointer to the record found, returns NULL otherwise
record * find( node * root, key_type key, bool verbose ) {
	int i = 0;
	record * pp, *first;
	std::cout << key << "\n";
	uint32_t rec_next;
	node * c = find_leaf( root, key, verbose );
	std::cout << "found leaf\n";
	if (c == NULL) return NULL;
	for (i = 0; i < c->num_keys; i++) {
		std::cout << "key " <<  c->keys[i] << " " << c->sectors[i] << "\n";
		if (c->keys[i] == key) break;
	}
	//std::cout << "asdadsada "<< i << " " << c->num_keys << "\n";
	if (i == c->num_keys) 
		return NULL;
	else {
		/* this points to the first record with that key */
		//std::cout << "asfdsadf" << c->sectors[i] << "\n";
		//here I have to manage the pointers
		//rec_next = c->sectors[i];
		pp = (record *)retrieveDataFake(socketfd, c->sectors[i], true, c, i);
		print_record(pp);
		first = pp;
		std::cout << pp->next_sect << std::endl;
		std::cout << pp->next << std::endl;
		while(pp->next_sect > 0){
			//std::cout << "ciao" << std::endl;
			pp = pp->next;
			print_record(pp);
			//std::cout << pp->next_sect;
		}
		//pp->parent = c;
		//std::cout << pp << std::endl;
		//print_record(pp);
		return first;
	}
}
Beispiel #26
0
RC index_btree::find_leaf(glob_param params, idx_key_t key, idx_acc_t access_type, bt_node *& leaf) {
	bt_node * last_ex = NULL;
	assert(access_type != INDEX_INSERT);
	RC rc = find_leaf(params, key, access_type, leaf, last_ex);
	return rc;
}
Beispiel #27
0
//{{{ void test_find_leaf(void)
void test_find_leaf(void)
{

    struct node *l1 = new_node();
    l1->is_leaf = 1;
    l1->num_keys = 4;
    l1->keys[0] = 1;
    l1->keys[1] = 2;
    l1->keys[2] = 3;
    l1->keys[3] = 4;

    struct node *l2 = new_node();
    l2->is_leaf = 1;
    l2->num_keys = 4;
    l2->keys[0] = 5;
    l2->keys[1] = 6;
    l2->keys[2] = 7;
    l2->keys[3] = 8;

    struct node *l3 = new_node();
    l3->is_leaf = 1;
    l3->num_keys = 4;
    l3->keys[0] = 9;
    l3->keys[1] = 10;
    l3->keys[2] = 11;
    l3->keys[3] = 12;

    l1->next = l2;
    l2->next = l3;

    struct node *n1 = new_node();
    n1->keys[0] = 5;
    n1->num_keys = 1;
    n1->pointers[0] = (void *)l1;
    n1->pointers[1] = (void *)l2;
    l1->parent = n1;
    l2->parent = n1;

    struct node *root = new_node();
    root->keys[0] = 9;
    root->num_keys = 1;
    root->pointers[0] = (void *)n1;
    root->pointers[1] = (void *)l3;
    n1->parent = root;
    l3->parent = root;

    /*
    fprintf(stderr, "l1:%p\t"
                    "l2:%p\t"
                    "l3:%p\t"
                    "n1:%p\t"
                    "root:%p\n",
                    l1, l2, l3, n1, root);
    */

    int i;
    for (i = 1; i <= 4; ++i)
        TEST_ASSERT_EQUAL(l1, find_leaf(root, i));

    for (i = 5; i <= 8; ++i) 
        TEST_ASSERT_EQUAL(l2, find_leaf(root, i));

    for (i = 9; i <= 12; ++i) 
        TEST_ASSERT_EQUAL(l3, find_leaf(root, i));
}
Beispiel #28
0
 void write_int(Properties &properties, int min, int max, int val) {
     CompoundSymbolChances<BitChance,bits> &chances = find_leaf(properties);
     set_selection_and_update_property_sums(properties,chances);
     CompoundSymbolChances<BitChance,bits> &chances2 = find_leaf(properties);
     coder.write_int(chances2, selection, min, max, val);
 }
Beispiel #29
0
 int read_int(Properties &properties, int min, int max) {
     CompoundSymbolChances<BitChance,bits> &chances = find_leaf(properties);
     set_selection_and_update_property_sums(properties,chances);
     CompoundSymbolChances<BitChance,bits> &chances2 = find_leaf(properties);
     return coder.read_int(chances2, selection, min, max);
 }
Beispiel #30
0
void FinalPropertySymbolCoder<BitChance,RAC,bits>::write_int(const Properties &properties, int nbits, int val) {
        assert(properties.size() == nb_properties);
        FinalCompoundSymbolChances<BitChance,bits> &chances = find_leaf(properties);
        coder.write_int(chances, nbits, val);
    }