aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/marktree.h
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2020-08-08 08:57:35 -0400
committerJames McCoy <jamessan@jamessan.com>2020-08-08 08:57:35 -0400
commit840c12c10741d8f70e1787534fb6ea6d2b70edee (patch)
treef89ad27acbbf0b36db7ac08eeae0b8362da1fabb /src/nvim/marktree.h
parente813ec79c201c85c5af3b10c051ae92ab5cb8606 (diff)
parentf26df8bb66158baacb79c79822babaf137607cd6 (diff)
downloadrneovim-840c12c10741d8f70e1787534fb6ea6d2b70edee.tar.gz
rneovim-840c12c10741d8f70e1787534fb6ea6d2b70edee.tar.bz2
rneovim-840c12c10741d8f70e1787534fb6ea6d2b70edee.zip
Merge remote-tracking branch 'upstream/master' into libcallnr
Diffstat (limited to 'src/nvim/marktree.h')
-rw-r--r--src/nvim/marktree.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/nvim/marktree.h b/src/nvim/marktree.h
new file mode 100644
index 0000000000..0c73e75b2e
--- /dev/null
+++ b/src/nvim/marktree.h
@@ -0,0 +1,76 @@
+#ifndef NVIM_MARKTREE_H
+#define NVIM_MARKTREE_H
+
+#include <stdint.h>
+#include "nvim/map.h"
+#include "nvim/garray.h"
+
+#define MT_MAX_DEPTH 20
+#define MT_BRANCH_FACTOR 10
+
+typedef struct {
+ int32_t row;
+ int32_t col;
+} mtpos_t;
+
+typedef struct {
+ int32_t row;
+ int32_t col;
+ uint64_t id;
+ bool right_gravity;
+} mtmark_t;
+
+typedef struct mtnode_s mtnode_t;
+typedef struct {
+ int oldcol;
+ int i;
+} iterstate_t;
+
+typedef struct {
+ mtpos_t pos;
+ int lvl;
+ mtnode_t *node;
+ int i;
+ iterstate_t s[MT_MAX_DEPTH];
+} MarkTreeIter;
+
+
+// Internal storage
+//
+// NB: actual marks have id > 0, so we can use (row,col,0) pseudo-key for
+// "space before (row,col)"
+typedef struct {
+ mtpos_t pos;
+ uint64_t id;
+} mtkey_t;
+
+struct mtnode_s {
+ int32_t n;
+ int32_t level;
+ // TODO(bfredl): we could consider having a only-sometimes-valid
+ // index into parent for faster "chached" lookup.
+ mtnode_t *parent;
+ mtkey_t key[2 * MT_BRANCH_FACTOR - 1];
+ mtnode_t *ptr[];
+};
+
+// TODO(bfredl): the iterator is pretty much everpresent, make it part of the
+// tree struct itself?
+typedef struct {
+ mtnode_t *root;
+ size_t n_keys, n_nodes;
+ uint64_t next_id;
+ // TODO(bfredl): the pointer to node could be part of the larger
+ // Map(uint64_t, ExtmarkItem) essentially;
+ PMap(uint64_t) *id2node;
+} MarkTree;
+
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "marktree.h.generated.h"
+#endif
+
+#define MARKTREE_PAIRED_FLAG (((uint64_t)1) << 1)
+#define MARKTREE_END_FLAG (((uint64_t)1) << 0)
+
+#endif // NVIM_MARKTREE_H