| 992 | } |
| 993 | |
| 994 | uint64_t |
| 995 | HGraph::EstimateMemory(uint64_t num_elements) const { |
| 996 | uint64_t estimate_memory = 0; |
| 997 | auto block_size = Options::Instance().block_size_limit(); |
| 998 | auto element_count = |
| 999 | next_multiple_of_power_of_two(num_elements, this->resize_increase_count_bit_); |
| 1000 | |
| 1001 | auto block_memory_ceil = [](uint64_t memory, uint64_t block_size) -> uint64_t { |
| 1002 | return static_cast<uint64_t>( |
| 1003 | std::ceil(static_cast<double>(memory) / static_cast<double>(block_size)) * |
| 1004 | static_cast<double>(block_size)); |
| 1005 | }; |
| 1006 | |
| 1007 | if (this->basic_flatten_codes_->InMemory()) { |
| 1008 | auto base_memory = this->basic_flatten_codes_->code_size_ * element_count; |
| 1009 | estimate_memory += block_memory_ceil(base_memory, block_size); |
| 1010 | } |
| 1011 | |
| 1012 | if (bottom_graph_->InMemory()) { |
| 1013 | auto bottom_graph_memory = |
| 1014 | (this->bottom_graph_->maximum_degree_ + 1) * sizeof(InnerIdType) * element_count; |
| 1015 | estimate_memory += block_memory_ceil(bottom_graph_memory, block_size); |
| 1016 | } |
| 1017 | |
| 1018 | if (use_reorder_ && this->high_precise_codes_->InMemory() && not this->ignore_reorder_) { |
| 1019 | auto precise_memory = this->high_precise_codes_->code_size_ * element_count; |
| 1020 | estimate_memory += block_memory_ceil(precise_memory, block_size); |
| 1021 | } |
| 1022 | |
| 1023 | if (extra_info_size_ > 0 && this->extra_infos_ != nullptr && this->extra_infos_->InMemory()) { |
| 1024 | auto extra_info_memory = this->extra_infos_->ExtraInfoSize() * element_count; |
| 1025 | estimate_memory += block_memory_ceil(extra_info_memory, block_size); |
| 1026 | } |
| 1027 | |
| 1028 | auto label_map_memory = |
| 1029 | element_count * (sizeof(std::pair<LabelType, InnerIdType>) + 2 * sizeof(void*)); |
| 1030 | estimate_memory += label_map_memory; |
| 1031 | |
| 1032 | auto sparse_graph_memory = (this->mult_ * 0.05 * static_cast<double>(element_count)) * |
| 1033 | sizeof(InnerIdType) * |
| 1034 | (static_cast<double>(this->bottom_graph_->maximum_degree_) / 2 + 1); |
| 1035 | estimate_memory += static_cast<uint64_t>(sparse_graph_memory); |
| 1036 | |
| 1037 | auto other_memory = element_count * (sizeof(LabelType) + sizeof(std::shared_mutex) + |
| 1038 | sizeof(std::shared_ptr<std::shared_mutex>)); |
| 1039 | estimate_memory += other_memory; |
| 1040 | |
| 1041 | return estimate_memory; |
| 1042 | } |
| 1043 | |
| 1044 | GraphInterfacePtr |
| 1045 | HGraph::generate_one_route_graph() { |
no test coverage detected