clang-tools  12.0.0git
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>
17 RelationSlab::lookup(const SymbolID &Subject, RelationKind Predicate) const {
18  auto IterPair = std::equal_range(Relations.begin(), Relations.end(),
19  Relation{Subject, Predicate, SymbolID{}},
20  [](const Relation &A, const Relation &B) {
21  return std::tie(A.Subject, A.Predicate) <
22  std::tie(B.Subject, B.Predicate);
23  });
24  return {IterPair.first, IterPair.second};
25 }
26 
28  // Sort in SPO order.
29  llvm::sort(Relations);
30 
31  // Remove duplicates.
32  Relations.erase(std::unique(Relations.begin(), Relations.end()),
33  Relations.end());
34 
35  return RelationSlab{std::move(Relations)};
36 }
37 
38 } // namespace clangd
39 } // namespace clang
Represents a relation between two symbols.
Definition: Relation.h:29
llvm::iterator_range< iterator > lookup(const SymbolID &Subject, RelationKind Predicate) const
Lookup all relations matching the given subject and predicate.
Definition: Relation.cpp:17
RelationKind Predicate
Definition: Relation.h:31
RelationSlab build() &&
Consumes the builder to finalize the slab.
Definition: Relation.cpp:27
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//