get all elements without offset

This commit is contained in:
andrew (from workstation) 2021-01-03 12:07:48 +01:00
parent 0eedaeea3a
commit c66972354a
3 changed files with 29 additions and 1 deletions

View File

@ -140,6 +140,14 @@ vector<FileSourceId> FileReferenceManager::get_some_file_sources(NodeId node_id)
return it->second.file_source_ids.get_some_elements(); return it->second.file_source_ids.get_some_elements();
} }
vector<FileSourceId> FileReferenceManager::get_all_file_sources(NodeId node_id) {
auto it = nodes_.find(node_id);
if (it == nodes_.end()) {
return {};
}
return it->second.file_source_ids.get_all_elements();
}
vector<FullMessageId> FileReferenceManager::get_some_message_file_sources(NodeId node_id) { vector<FullMessageId> FileReferenceManager::get_some_message_file_sources(NodeId node_id) {
auto file_source_ids = get_some_file_sources(node_id); auto file_source_ids = get_some_file_sources(node_id);
@ -372,7 +380,7 @@ void FileReferenceManager::memory_cleanup() {
auto remove = true; auto remove = true;
while (file_nodes_it != nodes_.end() && remove) { while (file_nodes_it != nodes_.end() && remove) {
auto elements = get_some_file_sources(file_nodes_it->first); auto elements = get_all_file_sources(file_nodes_it->first);
auto elements_it = elements.begin(); auto elements_it = elements.begin();
while (elements_it != elements.end()) { while (elements_it != elements.end()) {

View File

@ -159,6 +159,8 @@ class FileReferenceManager : public Actor {
template <class T> template <class T>
FileSourceId add_file_source_id(T source, Slice source_str); FileSourceId add_file_source_id(T source, Slice source_str);
vector<FileSourceId> FileReferenceManager::get_all_file_sources(NodeId node_id);
FileSourceId get_current_file_source_id() const; FileSourceId get_current_file_source_id() const;
}; };

View File

@ -18,6 +18,14 @@ namespace td {
template <class T> template <class T>
class FastSetWithPosition { class FastSetWithPosition {
public: public:
std::vector<T> get_unchecked() const {
std::vector<T> res;
res.insert(res.end(), checked_.begin(), checked_.end());
res.insert(res.end(), not_checked_.begin(), not_checked_.end());
td::unique(res);
return res;
}
std::vector<T> get_some_elements() const { std::vector<T> get_some_elements() const {
std::vector<T> res; std::vector<T> res;
res.reserve(4); res.reserve(4);
@ -106,6 +114,16 @@ class FastSetWithPosition {
template <class T> template <class T>
class SetWithPosition { class SetWithPosition {
public: public:
std::vector<T> get_all_elements() const {
if (fast_) {
return fast_->get_unchecked();
}
if (has_value_) {
return {value_};
}
return {};
}
std::vector<T> get_some_elements() const { std::vector<T> get_some_elements() const {
if (fast_) { if (fast_) {
return fast_->get_some_elements(); return fast_->get_some_elements();