robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
6535353b6d
master
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 { 11MT_MAX_DEPTH = 20 , 12MT_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" 16MT_LOG2_BRANCH = 5 , 17}; 18 19typedef struct { 20int32_t row ; 21int32_t col ; 22}MTPos ; 23#define MTPos (r ,c ) ((MTPos){ .row = (r), .col = (c) }) 24 25typedef enum { 26kMTMetaInline , 27kMTMetaLines , 28kMTMetaSignHL , 29kMTMetaSignText , 30kMTMetaConcealLines , 31kMTMetaCount ,// 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 { 40MTPos pos ; 41int lvl ; 42MTNode * x ; 43int i ; 44struct { 45int oldcol ; 46int i ; 47 }s [MT_MAX_DEPTH ]; 48 49size_t intersect_idx ; 50MTPos intersect_pos ; 51MTPos 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 { 63MTPos pos ; 64uint32_t ns ; 65uint32_t id ; 66uint16_t flags ; 67DecorInlineData decor_data ;// "ext" tag in flags 68}MTKey ; 69 70typedef struct { 71MTKey start ; 72MTPos end_pos ; 73bool 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 { 81MTNode * i_ptr [2 * MT_BRANCH_FACTOR ]; 82uint32_t i_meta [2 * MT_BRANCH_FACTOR ][kMTMetaCount ]; 83}; 84 85struct mtnode_s { 86int32_t n ; 87int16_t level ; 88int16_t p_idx ;// index in parent 89Intersection intersect ; 90MTNode * parent ; 91MTKey key [2 * MT_BRANCH_FACTOR - 1 ]; 92struct mtnode_inner_s s []; 93}; 94 95typedef struct { 96MTNode * root ; 97uint32_t meta_root [kMTMetaCount ]; 98size_t n_keys ,n_nodes ; 99PMap (uint64_t )id2node [1 ]; 100}MarkTree ;