Skip to content

Commit

Permalink
Swap out vector with hash set
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Nov 21, 2024
1 parent d53d4f9 commit f78f64d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/engine/LocalVocab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "engine/LocalVocab.h"

#include "absl/strings/str_cat.h"
#include "global/Id.h"
#include "global/ValueId.h"
#include "util/TransparentFunctors.h"

Expand Down
15 changes: 8 additions & 7 deletions src/engine/LocalVocab.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#pragma once

#include <absl/container/flat_hash_set.h>
#include <absl/container/node_hash_set.h>

#include <algorithm>
#include <cstdlib>
#include <memory>
Expand All @@ -13,9 +16,7 @@
#include <string>
#include <vector>

#include "absl/container/node_hash_set.h"
#include "global/Id.h"
#include "parser/LiteralOrIri.h"
#include "index/LocalVocabEntry.h"
#include "util/BlankNodeManager.h"
#include "util/Exception.h"

Expand Down Expand Up @@ -43,7 +44,7 @@ class LocalVocab {
std::shared_ptr<Set> primaryWordSet_ = std::make_shared<Set>();

// The other sets of `LocalVocabEntry`s, which are static.
std::vector<std::shared_ptr<const Set>> otherWordSets_;
absl::flat_hash_set<std::shared_ptr<const Set>> otherWordSets_;

// The number of words (so that we can compute `size()` in constant time).
size_t size_ = 0;
Expand Down Expand Up @@ -111,11 +112,11 @@ class LocalVocab {
// primary set of this `LocalVocab` remains unchanged.
template <std::ranges::range R>
void mergeWith(const R& vocabs) {
auto inserter = std::back_inserter(otherWordSets_);
using std::views::filter;
for (const auto& vocab : vocabs | filter(std::not_fn(&LocalVocab::empty))) {
std::ranges::copy(vocab.otherWordSets_, inserter);
*inserter = vocab.primaryWordSet_;
otherWordSets_.insert(vocab.otherWordSets_.begin(),
vocab.otherWordSets_.end());
otherWordSets_.insert(vocab.primaryWordSet_);

Check warning on line 119 in src/engine/LocalVocab.h

View check run for this annotation

Codecov / codecov/patch

src/engine/LocalVocab.h#L117-L119

Added lines #L117 - L119 were not covered by tests
size_ += vocab.size_;
}

Expand Down
3 changes: 0 additions & 3 deletions src/parser/LiteralOrIri.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

#pragma once

#include <absl/strings/str_cat.h>

#include <variant>

#include "parser/Iri.h"
#include "parser/Literal.h"
#include "util/Exception.h"

namespace ad_utility::triple_component {
static constexpr char literalPrefixChar = '"';
Expand Down

0 comments on commit f78f64d

Please sign in to comment.