1 //===- DeltaTree.h - B-Tree for Rewrite Delta tracking ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the DeltaTree class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_REWRITE_CORE_DELTATREE_H
14 #define LLVM_CLANG_REWRITE_CORE_DELTATREE_H
18 /// DeltaTree - a multiway search tree (BTree) structure with some fancy
19 /// features. B-Trees are generally more memory and cache efficient than
20 /// binary trees, because they store multiple keys/values in each node. This
21 /// implements a key/value mapping from index to delta, and allows fast lookup
22 /// on index. However, an added (important) bonus is that it can also
23 /// efficiently tell us the full accumulated delta for a specific file offset
24 /// as well, without traversing the whole tree.
26 void *Root; // "DeltaTreeNode *"
31 // Note: Currently we only support copying when the RHS is empty.
32 DeltaTree(const DeltaTree &RHS);
34 DeltaTree &operator=(const DeltaTree &) = delete;
37 /// getDeltaAt - Return the accumulated delta at the specified file offset.
38 /// This includes all insertions or delections that occurred *before* the
39 /// specified file index.
40 int getDeltaAt(unsigned FileIndex) const;
42 /// AddDelta - When a change is made that shifts around the text buffer,
43 /// this method is used to record that info. It inserts a delta of 'Delta'
44 /// into the current DeltaTree at offset FileIndex.
45 void AddDelta(unsigned FileIndex, int Delta);
50 #endif // LLVM_CLANG_REWRITE_CORE_DELTATREE_H