xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ADT/DeltaTree.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- DeltaTree.h - B-Tree for Rewrite Delta tracking ----------*- 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 // This file defines the DeltaTree class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ADT_DELTATREE_H
14 #define LLVM_ADT_DELTATREE_H
15 
16 #include "llvm/Support/Compiler.h"
17 
18 namespace llvm {
19 
20 /// DeltaTree - a multiway search tree (BTree) structure with some fancy
21 /// features.  B-Trees are generally more memory and cache efficient than
22 /// binary trees, because they store multiple keys/values in each node.  This
23 /// implements a key/value mapping from index to delta, and allows fast lookup
24 /// on index.  However, an added (important) bonus is that it can also
25 /// efficiently tell us the full accumulated delta for a specific file offset
26 /// as well, without traversing the whole tree.
27 class DeltaTree {
28   void *Root; // "DeltaTreeNode *"
29 
30 public:
31   LLVM_ABI DeltaTree();
32 
33   // Note: Currently we only support copying when the RHS is empty.
34   LLVM_ABI DeltaTree(const DeltaTree &RHS);
35 
36   DeltaTree &operator=(const DeltaTree &) = delete;
37   LLVM_ABI ~DeltaTree();
38 
39   /// getDeltaAt - Return the accumulated delta at the specified file offset.
40   /// This includes all insertions or delections that occurred *before* the
41   /// specified file index.
42   LLVM_ABI int getDeltaAt(unsigned FileIndex) const;
43 
44   /// AddDelta - When a change is made that shifts around the text buffer,
45   /// this method is used to record that info.  It inserts a delta of 'Delta'
46   /// into the current DeltaTree at offset FileIndex.
47   LLVM_ABI void AddDelta(unsigned FileIndex, int Delta);
48 };
49 
50 } // namespace llvm
51 
52 #endif // LLVM_ADT_DELTATREE_H
53