void RStarTreeNode::reinsert_elements(RStarTreePtr tree, const BoundedObjectPtr element, BoundedObjectPtrVector &reinsert) { Uint32 i, reinsert_count; assert(get_count() == get_max_count()); reinsert_count = static_cast<Sint32>(get_max_count() * tree->get_reinsert_factor()); assert(reinsert_count < get_count()); reinsert.reserve(reinsert_count + 1); for (i = 0; i < reinsert_count; i++) { reinsert.push_back(get_element(i)); } for (i = 0; i < reinsert_count; i++) { assert(get_index(reinsert[i]) == i); remove_element(i); } reinsert.push_back(element); assert(get_count() > 0); }
void RStarTreeNode::split(RStarTreePtr tree, const BoundedObjectPtr element, RStarTreeNodePtr new_node) { BoundedObjectPtrArray9 split_data; Sint32 i, node_spf, new_size, split_point; Uint32 j; assert(get_count() == get_max_count()); assert(new_node); assert(element); assert(tree); new_size = get_max_count() + 1; node_spf = boost::numeric_cast<Sint32>(new_size * tree->m_split_distribution_factor); for (j = 0; j < get_max_count(); j++) { split_data[j] = get_element(j); } split_data[get_max_count()] = element; split_point = split_array9(split_data, node_spf); assert(split_point > 0); assert(split_point < static_cast<Sint32>(get_max_count())); clear(); for (i = 0; i < split_point; i++) { new_node->add_element(split_data[i]); } for (i = split_point; i < new_size; i++) { add_element(split_data[i]); } update_enclosing_bounding_box(); new_node->update_enclosing_bounding_box(); assert(new_node->get_count() > 0); assert(get_count() > 0); }
bool RStarTreeNode::add_element(const BoundedObjectPtr element) { Uint32 index; assert(element); if (get_count() < get_max_count()) { index = get_count(); m_count++; assert(get_count() <= get_max_count()); set_element(element, index); return true; } else { return false; } }
/* reads up to `count' bytes starting from `offset' using error correction and integrity validation, if available */ ssize_t fec_pread(struct fec_handle *f, void *buf, size_t count, uint64_t offset) { check(f); check(buf); if (unlikely(offset > UINT64_MAX - count)) { errno = EOVERFLOW; return -1; } if (f->verity.hash) { return process(f, (uint8_t *)buf, get_max_count(offset, count, f->data_size), offset, verity_read); } else if (f->ecc.start) { check(f->ecc.start < f->size); count = get_max_count(offset, count, f->data_size); ssize_t rc = process(f, (uint8_t *)buf, count, offset, ecc_read); if (rc >= 0) { return rc; } /* return raw data if pure ecc read fails; due to interleaving the specific blocks the caller wants may still be fine */ } else { count = get_max_count(offset, count, f->size); } if (raw_pread(f, buf, count, offset)) { return count; } return -1; }
bool RStarTreeNode::insert_element(RStarTreePtr tree, const BoundedObjectPtr element, RStarTreeNodePtrStack &path_buffer, _32BitSet &oft) { RStarTreeNodePtr node; RStarTreeNodePtr new_node; BoundedObjectPtrVector reinsert; Uint32 i; assert(tree); if (get_count() < get_max_count()) { add_element(element); if (!path_buffer.empty()) { adjust_tree(path_buffer); return true; } else { return false; } } else { assert(get_level() < oft.size()); if (!path_buffer.empty() && !oft[get_level()]) { oft[get_level()] = true; reinsert_elements(tree, element, reinsert); adjust_tree(path_buffer); for (i = 0; i < reinsert.size(); i++) { tree->add_data(reinsert[i], get_level(), oft); } return true; } else { new_node = tree->new_node(get_level()); split(tree, element, new_node); assert(new_node); assert(new_node->get_count() > 0); assert(get_count() > 0); if (path_buffer.empty()) { node = tree->add_new_root_node( get_level() + 1); assert(node); node->add_element(this); node->add_element(new_node); node->update_enclosing_bounding_box(); assert(node->get_count() > 0); } else { node = path_buffer.top(); path_buffer.pop(); assert(node); node->adjust_tree(tree, new_node, path_buffer, oft); assert(node->get_count() > 0); } assert(new_node->get_count() > 0); return true; } } }