diff options
Diffstat (limited to 'src/nvim/marktree.h')
-rw-r--r-- | src/nvim/marktree.h | 103 |
1 files changed, 22 insertions, 81 deletions
diff --git a/src/nvim/marktree.h b/src/nvim/marktree.h index c76359d3f9..8e5cf30ff3 100644 --- a/src/nvim/marktree.h +++ b/src/nvim/marktree.h @@ -1,69 +1,16 @@ #pragma once #include <stdbool.h> -#include <stddef.h> +#include <stddef.h> // IWYU pragma: keep #include <stdint.h> -#include "klib/kvec.h" +#include "nvim/buffer_defs.h" #include "nvim/decoration_defs.h" -#include "nvim/garray_defs.h" // IWYU pragma: keep -#include "nvim/map_defs.h" +#include "nvim/marktree_defs.h" // IWYU pragma: keep #include "nvim/pos_defs.h" // IWYU pragma: keep // only for debug functions: #include "nvim/api/private/defs.h" // IWYU pragma: keep -#define MT_MAX_DEPTH 20 -#define MT_BRANCH_FACTOR 10 -// note max branch is actually 2*MT_BRANCH_FACTOR -// and strictly this is ceil(log2(2*MT_BRANCH_FACTOR + 1)) -// as we need a pseudo-index for "right before this node" -#define MT_LOG2_BRANCH 5 - -typedef struct { - int32_t row; - int32_t col; -} MTPos; -#define MTPos(r, c) ((MTPos){ .row = (r), .col = (c) }) - -typedef struct mtnode_s MTNode; - -typedef struct { - MTPos pos; - int lvl; - MTNode *x; - int i; - struct { - int oldcol; - int i; - } s[MT_MAX_DEPTH]; - - size_t intersect_idx; - MTPos intersect_pos; - MTPos intersect_pos_x; -} MarkTreeIter; - -#define marktree_itr_valid(itr) ((itr)->x != NULL) -// access raw key: flags in MT_FLAG_EXTERNAL_MASK and decor_data are safe to modify. -#define mt_itr_rawkey(itr) ((itr)->x->key[(itr)->i]) - -// Internal storage -// -// NB: actual marks have flags > 0, so we can use (row,col,0) pseudo-key for -// "space before (row,col)" -typedef struct { - MTPos pos; - uint32_t ns; - uint32_t id; - uint16_t flags; - DecorInlineData decor_data; // "ext" tag in flags -} MTKey; - -typedef struct { - MTKey start; - MTPos end_pos; - bool end_right_gravity; -} MTPair; - #define MT_INVALID_KEY (MTKey) { { -1, -1 }, 0, 0, 0, { .hl = DECOR_HIGHLIGHT_INLINE_INIT } } #define MT_FLAG_REAL (((uint16_t)1) << 0) @@ -88,6 +35,8 @@ typedef struct { #define MT_FLAG_DECOR_VIRT_LINES (((uint16_t)1) << 11) #define MT_FLAG_DECOR_VIRT_TEXT_INLINE (((uint16_t)1) << 12) +#define MT_FLAG_SCOPED (((uint16_t)1) << 13) + // These _must_ be last to preserve ordering of marks #define MT_FLAG_RIGHT_GRAVITY (((uint16_t)1) << 14) #define MT_FLAG_LAST (((uint16_t)1) << 15) @@ -97,7 +46,7 @@ typedef struct { | MT_FLAG_DECOR_VIRT_TEXT_INLINE) #define MT_FLAG_EXTERNAL_MASK (MT_FLAG_DECOR_MASK | MT_FLAG_NO_UNDO \ - | MT_FLAG_INVALIDATE | MT_FLAG_INVALID) + | MT_FLAG_INVALIDATE | MT_FLAG_INVALID | MT_FLAG_SCOPED) // this is defined so that start and end of the same range have adjacent ids #define MARKTREE_END_FLAG ((uint64_t)1) @@ -161,12 +110,24 @@ static inline bool mt_decor_sign(MTKey key) return key.flags & (MT_FLAG_DECOR_SIGNTEXT | MT_FLAG_DECOR_SIGNHL); } -static inline uint16_t mt_flags(bool right_gravity, bool no_undo, bool invalidate, bool decor_ext) +static inline bool mt_scoped(MTKey key) +{ + return key.flags & MT_FLAG_SCOPED; +} + +static inline bool mt_scoped_in_win(MTKey key, win_T *wp) +{ + return !mt_scoped(key) || set_has(uint32_t, &wp->w_ns_set, key.ns); +} + +static inline uint16_t mt_flags(bool right_gravity, bool no_undo, bool invalidate, bool decor_ext, + bool scoped) { return (uint16_t)((right_gravity ? MT_FLAG_RIGHT_GRAVITY : 0) | (no_undo ? MT_FLAG_NO_UNDO : 0) | (invalidate ? MT_FLAG_INVALIDATE : 0) - | (decor_ext ? MT_FLAG_DECOR_EXT : 0)); + | (decor_ext ? MT_FLAG_DECOR_EXT : 0) + | (scoped ? MT_FLAG_SCOPED : 0)); } static inline MTPair mtpair_from(MTKey start, MTKey end) @@ -179,31 +140,11 @@ static inline DecorInline mt_decor(MTKey key) return (DecorInline){ .ext = key.flags & MT_FLAG_DECOR_EXT, .data = key.decor_data }; } -typedef kvec_withinit_t(uint64_t, 4) Intersection; - -struct mtnode_s { - int32_t n; - int16_t level; - int16_t p_idx; // index in parent - Intersection intersect; - // TODO(bfredl): we could consider having a only-sometimes-valid - // index into parent for faster "cached" lookup. - MTNode *parent; - MTKey key[2 * MT_BRANCH_FACTOR - 1]; - MTNode *ptr[]; -}; - -static inline uint64_t mt_dbg_id(uint64_t id) +static inline DecorVirtText *mt_decor_virt(MTKey mark) { - return (id>>1)&0xffffffff; + return (mark.flags & MT_FLAG_DECOR_EXT) ? mark.decor_data.ext.vt : NULL; } -typedef struct { - MTNode *root; - size_t n_keys, n_nodes; - PMap(uint64_t) id2node[1]; -} MarkTree; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "marktree.h.generated.h" #endif |