robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

bfredlMerge pull request #38128 from bfredl/neodamage6535353b6d

master
2.2 KiB100 linesraw
1#pragma once
2
3#include <stdbool.h>
4#include <stddef.h>
5#include <stdint.h>
6
7#include "nvim/decoration_defs.h"
8#include "nvim/map_defs.h"
9
10enum {
11  MT_MAX_DEPTH     = 20,
12  MT_BRANCH_FACTOR = 10,
13  // note max branch is actually 2*MT_BRANCH_FACTOR
14  // and strictly this is ceil(log2(2*MT_BRANCH_FACTOR + 1))
15  // as we need a pseudo-index for "right before this node"
16  MT_LOG2_BRANCH   = 5,
17};
18
19typedef struct {
20  int32_t row;
21  int32_t col;
22} MTPos;
23#define MTPos(r, c) ((MTPos){ .row = (r), .col = (c) })
24
25typedef enum {
26  kMTMetaInline,
27  kMTMetaLines,
28  kMTMetaSignHL,
29  kMTMetaSignText,
30  kMTMetaConcealLines,
31  kMTMetaCount,  // sentinel, must be last
32} MetaIndex;
33
34#define kMTFilterSelect ((uint32_t)-1)
35
36// a filter should be set to kMTFilterSelect for the selected kinds, zero otherwise
37typedef const uint32_t *MetaFilter;
38
39typedef struct {
40  MTPos pos;
41  int lvl;
42  MTNode *x;
43  int i;
44  struct {
45    int oldcol;
46    int i;
47  } s[MT_MAX_DEPTH];
48
49  size_t intersect_idx;
50  MTPos intersect_pos;
51  MTPos intersect_pos_x;
52} MarkTreeIter;
53
54#define marktree_itr_valid(itr) ((itr)->x != NULL)
55// access raw key: flags in MT_FLAG_EXTERNAL_MASK and decor_data are safe to modify.
56#define mt_itr_rawkey(itr) ((itr)->x->key[(itr)->i])
57
58// Internal storage
59//
60// NB: actual marks have flags > 0, so we can use (row,col,0) pseudo-key for
61// "space before (row,col)"
62typedef struct {
63  MTPos pos;
64  uint32_t ns;
65  uint32_t id;
66  uint16_t flags;
67  DecorInlineData decor_data;  // "ext" tag in flags
68} MTKey;
69
70typedef struct {
71  MTKey start;
72  MTPos end_pos;
73  bool end_right_gravity;
74} MTPair;
75
76typedef kvec_withinit_t(uint64_t, 4) Intersection;
77
78// part of mtnode_s which is only allocated for inner nodes:
79// pointer to children as well as their meta counts
80struct mtnode_inner_s {
81  MTNode *i_ptr[2 * MT_BRANCH_FACTOR];
82  uint32_t i_meta[2 * MT_BRANCH_FACTOR][kMTMetaCount];
83};
84
85struct mtnode_s {
86  int32_t n;
87  int16_t level;
88  int16_t p_idx;  // index in parent
89  Intersection intersect;
90  MTNode *parent;
91  MTKey key[2 * MT_BRANCH_FACTOR - 1];
92  struct mtnode_inner_s s[];
93};
94
95typedef struct {
96  MTNode *root;
97  uint32_t meta_root[kMTMetaCount];
98  size_t n_keys, n_nodes;
99  PMap(uint64_t) id2node[1];
100} MarkTree;