9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
13#include "llvm/ADT/StringSet.h"
24 template <
typename SymbolRange,
typename RefRange,
typename RelationRange>
28 for (
const std::pair<
SymbolID, llvm::ArrayRef<Ref>> &R : Refs)
29 this->Refs.try_emplace(R.first, R.second.begin(), R.second.end());
31 this->Relations[std::make_pair(R.Subject,
32 static_cast<uint8_t
>(R.Predicate))]
36 template <
typename SymbolRange,
typename RefRange,
typename RelationRange,
39 Payload &&BackingData,
size_t BackingDataSize)
41 std::forward<RefRange>(Refs),
42 std::forward<RelationRange>(Relations)) {
43 KeepAlive = std::shared_ptr<void>(
44 std::make_shared<Payload>(std::move(BackingData)),
nullptr);
45 this->BackingDataSize = BackingDataSize;
48 template <
typename SymbolRange,
typename RefRange,
typename RelationRange,
49 typename FileRange,
typename Payload>
52 size_t BackingDataSize)
54 std::forward<RefRange>(Refs),
55 std::forward<RelationRange>(Relations),
56 std::forward<
Payload>(BackingData), BackingDataSize) {
57 this->Files = std::forward<FileRange>(Files);
58 this->IdxContents = IdxContents;
73 llvm::function_ref<
void(
const Ref &)>
Callback)
const override;
86 llvm::DenseMap<SymbolID, const Symbol *> Index;
88 llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> Refs;
91 "RelationKind should be of same size as a uint8_t");
92 llvm::DenseMap<std::pair<SymbolID, uint8_t>, std::vector<SymbolID>> Relations;
94 llvm::StringSet<> Files;
97 std::shared_ptr<void> KeepAlive;
99 size_t BackingDataSize = 0;
MemIndex is a naive in-memory index suitable for a small set of symbols.
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
void lookup(const LookupRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol.
bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref< void(const Symbol &)> Callback) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning.
MemIndex(SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations, Payload &&BackingData, size_t BackingDataSize)
void relations(const RelationsRequest &Req, llvm::function_ref< void(const SymbolID &, const Symbol &)> Callback) const override
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
MemIndex(SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations, FileRange &&Files, IndexContents IdxContents, Payload &&BackingData, size_t BackingDataSize)
MemIndex(SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations)
static std::unique_ptr< SymbolIndex > build(SymbolSlab Symbols, RefSlab Refs, RelationSlab Relations)
Builds an index from slabs. The index takes ownership of the data.
bool refs(const RefsRequest &Req, llvm::function_ref< void(const Ref &)> Callback) const override
Finds all occurrences (e.g.
An efficient structure of storing large set of symbol references in memory.
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
An immutable symbol container that stores a set of symbols.
IndexContents
Describes what data is covered by an index.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Represents a symbol occurrence in the source file.
Represents a relation between two symbols.
Represents a symbol range where the symbol can potentially have multiple tokens.
The class presents a C++ symbol, e.g.