Skip to content

Commit

Permalink
Switch to improved binary_search
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Nov 14, 2023
1 parent 6abff1d commit c480c02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ROOTNTupleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void ROOTNTupleWriter::writeFrame(const podio::Frame& frame, const std::string&
const bool new_category = (catInfo.writer == nullptr);
if (new_category) {
// This is the minimal information that we need for now
catInfo.name = collsToWrite;
catInfo.name = root_utils::sortAlphabeticaly(collsToWrite);
}

std::vector<StoreCollection> collections;
Expand Down
11 changes: 9 additions & 2 deletions src/rootUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,16 @@ inline bool checkConsistentColls(const std::vector<std::string>& existingColls,

// Since we are guaranteed to have unique names here, we can just look for
// collisions brute force, which seems to be quickest approach for vector
// sizes we typically have here (few hundred)
// sizes we typically have (few hundred). We can take advantage of the fact
// that the existingColls are ordered (alphabetically and case-insensitive),
// so we can do a binary_search
for (const auto& id : candidateColls) {
if (std::find(existingColls.begin(), existingColls.end(), id) == existingColls.end()) {
if (!std::binary_search(existingColls.begin(), existingColls.end(), id, [](const auto& lhs, const auto& rhs) {
return lhs.size() == rhs.size() &&
std::lexicographical_compare(
lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
[](const auto cl, const auto cr) { return std::tolower(cl) < std::tolower(cr); });
})) {
return false;
}
}
Expand Down

0 comments on commit c480c02

Please sign in to comment.