clang-tools  9.0.0
Relation.cpp
Go to the documentation of this file.
1 //===--- Relation.cpp --------------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Relation.h"
10 
11 #include <algorithm>
12 
13 namespace clang {
14 namespace clangd {
15 
16 llvm::iterator_range<RelationSlab::iterator>
18  index::SymbolRole Predicate) const {
19  auto IterPair = std::equal_range(Relations.begin(), Relations.end(),
20  Relation{Subject, Predicate, SymbolID{}},
21  [](const Relation &A, const Relation &B) {
22  return std::tie(A.Subject, A.Predicate) <
23  std::tie(B.Subject, B.Predicate);
24  });
25  return {IterPair.first, IterPair.second};
26 }
27 
29  // Sort in SPO order.
30  std::sort(Relations.begin(), Relations.end());
31 
32  // Remove duplicates.
33  Relations.erase(std::unique(Relations.begin(), Relations.end()),
34  Relations.end());
35 
36  return RelationSlab{std::move(Relations)};
37 }
38 
39 } // namespace clangd
40 } // namespace clang
Represents a relation between two symbols.
Definition: Relation.h:25
llvm::iterator_range< iterator > lookup(const SymbolID &Subject, index::SymbolRole Predicate) const
Lookup all relations matching the given subject and predicate.
Definition: Relation.cpp:17
RelationSlab build() &&
Consumes the builder to finalize the slab.
Definition: Relation.cpp:28
index::SymbolRole Predicate
Definition: Relation.h:27
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//