void clear_nodes(RB_node *node, RB_node *nil){ if(node != nil){ clear_nodes(node->left, nil); clear_nodes(node->right, nil); free(node); } }
void ntree<tree_dim, world_dim, elem_t, common_data_t>:: clear() { clear_nodes(); m_entries.clear(); m_numDelayedElements = 0; }
void ntree<tree_dim, world_dim, elem_t, common_data_t>:: rebalance() { // push all elements into the root node, calculate its bounding box // and call split_leaf_node if the element threshold is surpassed. clear_nodes(); Node& root = m_nodes.back(); if(!m_entries.empty()){ root.firstEntryInd = 0; root.lastEntryInd = m_entries.size() - 1; root.numEntries = m_entries.size(); for(size_t i = 0; i < m_entries.size(); ++i) m_entries[i].nextEntryInd = i+1; m_entries.back().nextEntryInd = s_invalidIndex; // the tight bounding box and the loose bounding box of the root node // should be the same. update_loose_bounding_box(root); root.tightBox = root.looseBox; if(root.numEntries >= m_desc.splitThreshold) split_leaf_node(0); } }
void RB_destroy_tree(RB_tree *tree){ if(tree->root != tree->nil){ clear_nodes(tree->root, tree->nil); } free(tree->nil); }
void clear_tree(RB_tree *tree){ if(tree->root != tree->nil){ clear_nodes(tree->root, tree->nil); tree->root = tree->nil; } }
void clear() { clear_nodes(); clear_records(); }
CNodeTable::~CNodeTable() { clear_nodes(); delete []_node_array; }
void CNodeTable::load(const char* filename, bool ignore_duplicate) { FILE* fp = fopen(filename, "r"); if (NULL == fp) throw sys::CSyscallException(errno, __FILE__, __LINE__); sys::CloseHelper<FILE*> ch(fp); sys::WriteLockHelper write_lock(_lock); try { int idc_id = 0; int node_id = 0; int rack_id = 0; int node_type = 0; char node_ip_str[IP_ADDRESS_MAX]; char check_field[100]; /** 用来探测是否多了一些字段 */ char line[LINE_MAX]; int line_number = 0; while (fgets(line, sizeof(line)-1, fp)) { ++line_number; // 跳过注释 if ('#' == line[0]) continue; // 跳过空行 if ('\n' == line[0]) continue; // 共5个有效字段 int field_count = sscanf(line, "%d%s%d%d%d%s", &node_id, node_ip_str, &node_type, &rack_id, &idc_id, check_field); if (field_count != 5) // 字段个数不对 throw util::CFileFormatException(filename, line_number, field_count); // 节点ID过大 if (!is_valid_node_id(node_id)) throw util::CFileFormatException(filename, line_number, 1); // IP格式不对 if (!net::CUtil::valid_ipv4(node_ip_str)) throw util::CFileFormatException(filename, line_number, 2); int node_ip = net::CUtil::convert_ipv4(node_ip_str); if (0 == node_ip) throw util::CFileFormatException(filename, line_number, 2); // 节点类型不对 if ((node_type != 0) && (node_type != 1)) throw util::CFileFormatException(filename, line_number, 3); // rack error if ((rack_id != -1) && (!is_valid_rack_id(rack_id))) throw util::CFileFormatException(filename, line_number, 4); // idc error if ((idc_id != -1) && (!is_valid_idc_id(idc_id))) throw util::CFileFormatException(filename, line_number, 5); // node_type等于1表示为受控节点,如果等于0则表示为非控节点 CNode* node = do_add_node(node_id, node_ip, 1==node_type); if (NULL == node) // 除非节点已经存在,否则不会为NULL { if (!ignore_duplicate) throw util::CFileFormatException(filename, line_number, 0); } else { if (idc_id > -1) node->set_owner_idc_id(idc_id); if (rack_id > -1) node->set_owner_rack_id(rack_id); } } } catch (util::CFileFormatException& ex) { //fclose(fp); // 使用了CloseHelper,会自动关闭的 clear_nodes(); throw; } }