@fairyhunter13/opentui-core 0.1.114 → 0.1.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3d/SpriteResourceManager.d.ts +74 -0
- package/3d/SpriteUtils.d.ts +13 -0
- package/3d/TextureUtils.d.ts +24 -0
- package/3d/ThreeRenderable.d.ts +40 -0
- package/3d/WGPURenderer.d.ts +61 -0
- package/3d/animation/ExplodingSpriteEffect.d.ts +71 -0
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +76 -0
- package/3d/animation/SpriteAnimator.d.ts +124 -0
- package/3d/animation/SpriteParticleGenerator.d.ts +62 -0
- package/3d/canvas.d.ts +44 -0
- package/3d/index.d.ts +12 -0
- package/3d/physics/PlanckPhysicsAdapter.d.ts +19 -0
- package/3d/physics/RapierPhysicsAdapter.d.ts +19 -0
- package/3d/physics/physics-interface.d.ts +27 -0
- package/3d.d.ts +2 -0
- package/3d.js +34041 -0
- package/3d.js.map +155 -0
- package/LICENSE +21 -0
- package/NativeSpanFeed.d.ts +41 -0
- package/Renderable.d.ts +334 -0
- package/animation/Timeline.d.ts +126 -0
- package/ansi.d.ts +13 -0
- package/buffer.d.ts +111 -0
- package/console.d.ts +144 -0
- package/edit-buffer.d.ts +98 -0
- package/editor-view.d.ts +73 -0
- package/index-j4m38kjn.js +411 -0
- package/index-j4m38kjn.js.map +10 -0
- package/index-tse8gzh0.js +20614 -0
- package/index-tse8gzh0.js.map +67 -0
- package/index-vv2jcd4r.js +12299 -0
- package/index-vv2jcd4r.js.map +42 -0
- package/index.d.ts +23 -0
- package/index.js +478 -0
- package/index.js.map +9 -0
- package/lib/KeyHandler.d.ts +61 -0
- package/lib/RGBA.d.ts +25 -0
- package/lib/ascii.font.d.ts +508 -0
- package/lib/border.d.ts +51 -0
- package/lib/bunfs.d.ts +7 -0
- package/lib/clipboard.d.ts +17 -0
- package/lib/clock.d.ts +15 -0
- package/lib/data-paths.d.ts +26 -0
- package/lib/debounce.d.ts +42 -0
- package/lib/detect-links.d.ts +6 -0
- package/lib/env.d.ts +42 -0
- package/lib/extmarks-history.d.ts +17 -0
- package/lib/extmarks.d.ts +89 -0
- package/lib/hast-styled-text.d.ts +17 -0
- package/lib/index.d.ts +21 -0
- package/lib/keymapping.d.ts +25 -0
- package/lib/objects-in-viewport.d.ts +24 -0
- package/lib/output.capture.d.ts +24 -0
- package/lib/parse.keypress-kitty.d.ts +2 -0
- package/lib/parse.keypress.d.ts +26 -0
- package/lib/parse.mouse.d.ts +30 -0
- package/lib/paste.d.ts +7 -0
- package/lib/queue.d.ts +15 -0
- package/lib/renderable.validations.d.ts +12 -0
- package/lib/scroll-acceleration.d.ts +43 -0
- package/lib/selection.d.ts +63 -0
- package/lib/singleton.d.ts +7 -0
- package/lib/stdin-parser.d.ts +87 -0
- package/lib/styled-text.d.ts +63 -0
- package/lib/terminal-capability-detection.d.ts +30 -0
- package/lib/terminal-palette.d.ts +50 -0
- package/lib/tree-sitter/assets/update.d.ts +11 -0
- package/lib/tree-sitter/client.d.ts +47 -0
- package/lib/tree-sitter/default-parsers.d.ts +2 -0
- package/lib/tree-sitter/download-utils.d.ts +21 -0
- package/lib/tree-sitter/index.d.ts +8 -0
- package/lib/tree-sitter/parser.worker.d.ts +1 -0
- package/lib/tree-sitter/parsers-config.d.ts +53 -0
- package/lib/tree-sitter/resolve-ft.d.ts +5 -0
- package/lib/tree-sitter/types.d.ts +82 -0
- package/lib/tree-sitter-styled-text.d.ts +14 -0
- package/lib/validate-dir-name.d.ts +1 -0
- package/lib/yoga.options.d.ts +32 -0
- package/package.json +50 -62
- package/parser.worker.js +899 -0
- package/parser.worker.js.map +12 -0
- package/plugins/core-slot.d.ts +72 -0
- package/plugins/registry.d.ts +42 -0
- package/plugins/types.d.ts +34 -0
- package/post/effects.d.ts +147 -0
- package/post/filters.d.ts +65 -0
- package/post/matrices.d.ts +20 -0
- package/renderables/ASCIIFont.d.ts +52 -0
- package/renderables/Box.d.ts +81 -0
- package/renderables/Code.d.ts +78 -0
- package/renderables/Diff.d.ts +142 -0
- package/renderables/EditBufferRenderable.d.ts +237 -0
- package/renderables/FrameBuffer.d.ts +16 -0
- package/renderables/Input.d.ts +67 -0
- package/renderables/LineNumberRenderable.d.ts +78 -0
- package/renderables/Markdown.d.ts +185 -0
- package/renderables/ScrollBar.d.ts +77 -0
- package/renderables/ScrollBox.d.ts +124 -0
- package/renderables/Select.d.ts +115 -0
- package/renderables/Slider.d.ts +47 -0
- package/renderables/TabSelect.d.ts +96 -0
- package/renderables/Text.d.ts +36 -0
- package/renderables/TextBufferRenderable.d.ts +105 -0
- package/renderables/TextNode.d.ts +91 -0
- package/renderables/TextTable.d.ts +140 -0
- package/renderables/Textarea.d.ts +63 -0
- package/renderables/TimeToFirstDraw.d.ts +24 -0
- package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
- package/renderables/composition/VRenderable.d.ts +16 -0
- package/renderables/composition/constructs.d.ts +35 -0
- package/renderables/composition/vnode.d.ts +46 -0
- package/renderables/index.d.ts +23 -0
- package/renderables/markdown-parser.d.ts +10 -0
- package/renderer.d.ts +419 -0
- package/runtime-plugin-support.d.ts +3 -0
- package/runtime-plugin-support.js +29 -0
- package/runtime-plugin-support.js.map +10 -0
- package/runtime-plugin.d.ts +16 -0
- package/runtime-plugin.js +16 -0
- package/runtime-plugin.js.map +9 -0
- package/syntax-style.d.ts +54 -0
- package/testing/manual-clock.d.ts +17 -0
- package/testing/mock-keys.d.ts +81 -0
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/mock-tree-sitter-client.d.ts +23 -0
- package/testing/spy.d.ts +7 -0
- package/testing/test-recorder.d.ts +61 -0
- package/testing/test-renderer.d.ts +23 -0
- package/testing.d.ts +6 -0
- package/testing.js +697 -0
- package/testing.js.map +15 -0
- package/text-buffer-view.d.ts +42 -0
- package/text-buffer.d.ts +67 -0
- package/types.d.ts +139 -0
- package/utils.d.ts +14 -0
- package/zig-structs.d.ts +155 -0
- package/zig.d.ts +353 -0
- package/dev/keypress-debug-renderer.ts +0 -148
- package/dev/keypress-debug.ts +0 -43
- package/dev/print-env-vars.ts +0 -32
- package/dev/test-tmux-graphics-334.sh +0 -68
- package/dev/thai-debug-test.ts +0 -68
- package/docs/development.md +0 -144
- package/scripts/build.ts +0 -400
- package/scripts/publish.ts +0 -60
- package/src/3d/SpriteResourceManager.ts +0 -286
- package/src/3d/SpriteUtils.ts +0 -70
- package/src/3d/TextureUtils.ts +0 -196
- package/src/3d/ThreeRenderable.ts +0 -197
- package/src/3d/WGPURenderer.ts +0 -294
- package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
- package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
- package/src/3d/animation/SpriteAnimator.ts +0 -633
- package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
- package/src/3d/canvas.ts +0 -464
- package/src/3d/index.ts +0 -12
- package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
- package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
- package/src/3d/physics/physics-interface.ts +0 -31
- package/src/3d/shaders/supersampling.wgsl +0 -201
- package/src/3d.ts +0 -3
- package/src/NativeSpanFeed.ts +0 -300
- package/src/Renderable.ts +0 -1704
- package/src/__snapshots__/buffer.test.ts.snap +0 -28
- package/src/animation/Timeline.test.ts +0 -2709
- package/src/animation/Timeline.ts +0 -598
- package/src/ansi.ts +0 -18
- package/src/benchmark/attenuation-benchmark.ts +0 -81
- package/src/benchmark/colormatrix-benchmark.ts +0 -128
- package/src/benchmark/gain-benchmark.ts +0 -80
- package/src/benchmark/latest-all-bench-run.json +0 -707
- package/src/benchmark/latest-async-bench-run.json +0 -336
- package/src/benchmark/latest-default-bench-run.json +0 -657
- package/src/benchmark/latest-large-bench-run.json +0 -707
- package/src/benchmark/latest-quick-bench-run.json +0 -207
- package/src/benchmark/markdown-benchmark.ts +0 -1796
- package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
- package/src/benchmark/native-span-feed-benchmark.md +0 -56
- package/src/benchmark/native-span-feed-benchmark.ts +0 -596
- package/src/benchmark/native-span-feed-compare.ts +0 -280
- package/src/benchmark/renderer-benchmark.ts +0 -754
- package/src/benchmark/text-table-benchmark.ts +0 -948
- package/src/buffer.test.ts +0 -291
- package/src/buffer.ts +0 -554
- package/src/console.test.ts +0 -612
- package/src/console.ts +0 -1254
- package/src/edit-buffer.test.ts +0 -1769
- package/src/edit-buffer.ts +0 -411
- package/src/editor-view.test.ts +0 -1032
- package/src/editor-view.ts +0 -284
- package/src/examples/ascii-font-selection-demo.ts +0 -245
- package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
- package/src/examples/assets/concrete.png +0 -0
- package/src/examples/assets/crate.png +0 -0
- package/src/examples/assets/crate_emissive.png +0 -0
- package/src/examples/assets/forrest_background.png +0 -0
- package/src/examples/assets/hast-example.json +0 -1018
- package/src/examples/assets/heart.png +0 -0
- package/src/examples/assets/main_char_heavy_attack.png +0 -0
- package/src/examples/assets/main_char_idle.png +0 -0
- package/src/examples/assets/main_char_jump_end.png +0 -0
- package/src/examples/assets/main_char_jump_landing.png +0 -0
- package/src/examples/assets/main_char_jump_start.png +0 -0
- package/src/examples/assets/main_char_run_loop.png +0 -0
- package/src/examples/assets/roughness_map.jpg +0 -0
- package/src/examples/build.ts +0 -115
- package/src/examples/code-demo.ts +0 -924
- package/src/examples/console-demo.ts +0 -358
- package/src/examples/core-plugin-slots-demo.ts +0 -759
- package/src/examples/diff-demo.ts +0 -701
- package/src/examples/draggable-three-demo.ts +0 -259
- package/src/examples/editor-demo.ts +0 -322
- package/src/examples/extmarks-demo.ts +0 -196
- package/src/examples/focus-restore-demo.ts +0 -310
- package/src/examples/fonts.ts +0 -245
- package/src/examples/fractal-shader-demo.ts +0 -268
- package/src/examples/framebuffer-demo.ts +0 -674
- package/src/examples/full-unicode-demo.ts +0 -241
- package/src/examples/golden-star-demo.ts +0 -933
- package/src/examples/grayscale-buffer-demo.ts +0 -249
- package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
- package/src/examples/index.ts +0 -926
- package/src/examples/input-demo.ts +0 -377
- package/src/examples/input-select-layout-demo.ts +0 -425
- package/src/examples/install.sh +0 -143
- package/src/examples/keypress-debug-demo.ts +0 -452
- package/src/examples/lib/HexList.ts +0 -122
- package/src/examples/lib/PaletteGrid.ts +0 -125
- package/src/examples/lib/standalone-keys.ts +0 -25
- package/src/examples/lib/tab-controller.ts +0 -243
- package/src/examples/lights-phong-demo.ts +0 -290
- package/src/examples/link-demo.ts +0 -220
- package/src/examples/live-state-demo.ts +0 -480
- package/src/examples/markdown-demo.ts +0 -725
- package/src/examples/mouse-interaction-demo.ts +0 -428
- package/src/examples/nested-zindex-demo.ts +0 -357
- package/src/examples/opacity-example.ts +0 -235
- package/src/examples/opentui-demo.ts +0 -1057
- package/src/examples/physx-planck-2d-demo.ts +0 -623
- package/src/examples/physx-rapier-2d-demo.ts +0 -655
- package/src/examples/relative-positioning-demo.ts +0 -323
- package/src/examples/scroll-example.ts +0 -214
- package/src/examples/scrollbox-mouse-test.ts +0 -112
- package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
- package/src/examples/select-demo.ts +0 -237
- package/src/examples/shader-cube-demo.ts +0 -1015
- package/src/examples/simple-layout-example.ts +0 -591
- package/src/examples/slider-demo.ts +0 -617
- package/src/examples/split-mode-demo.ts +0 -453
- package/src/examples/sprite-animation-demo.ts +0 -443
- package/src/examples/sprite-particle-generator-demo.ts +0 -486
- package/src/examples/static-sprite-demo.ts +0 -193
- package/src/examples/sticky-scroll-example.ts +0 -308
- package/src/examples/styled-text-demo.ts +0 -282
- package/src/examples/tab-select-demo.ts +0 -219
- package/src/examples/terminal-title.ts +0 -29
- package/src/examples/terminal.ts +0 -305
- package/src/examples/text-node-demo.ts +0 -416
- package/src/examples/text-selection-demo.ts +0 -377
- package/src/examples/text-table-demo.ts +0 -503
- package/src/examples/text-truncation-demo.ts +0 -481
- package/src/examples/text-wrap.ts +0 -757
- package/src/examples/texture-loading-demo.ts +0 -259
- package/src/examples/timeline-example.ts +0 -670
- package/src/examples/transparency-demo.ts +0 -400
- package/src/examples/vnode-composition-demo.ts +0 -404
- package/src/examples/wide-grapheme-overlay-demo.ts +0 -280
- package/src/index.ts +0 -24
- package/src/lib/KeyHandler.integration.test.ts +0 -292
- package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
- package/src/lib/KeyHandler.test.ts +0 -662
- package/src/lib/KeyHandler.ts +0 -222
- package/src/lib/RGBA.test.ts +0 -984
- package/src/lib/RGBA.ts +0 -204
- package/src/lib/ascii.font.ts +0 -330
- package/src/lib/border.test.ts +0 -83
- package/src/lib/border.ts +0 -170
- package/src/lib/bunfs.test.ts +0 -27
- package/src/lib/bunfs.ts +0 -18
- package/src/lib/clipboard.test.ts +0 -41
- package/src/lib/clipboard.ts +0 -47
- package/src/lib/clock.ts +0 -35
- package/src/lib/data-paths.test.ts +0 -133
- package/src/lib/data-paths.ts +0 -109
- package/src/lib/debounce.ts +0 -106
- package/src/lib/detect-links.test.ts +0 -98
- package/src/lib/detect-links.ts +0 -56
- package/src/lib/env.test.ts +0 -228
- package/src/lib/env.ts +0 -209
- package/src/lib/extmarks-history.ts +0 -51
- package/src/lib/extmarks-multiwidth.test.ts +0 -322
- package/src/lib/extmarks.test.ts +0 -3457
- package/src/lib/extmarks.ts +0 -843
- package/src/lib/fonts/block.json +0 -405
- package/src/lib/fonts/grid.json +0 -265
- package/src/lib/fonts/huge.json +0 -741
- package/src/lib/fonts/pallet.json +0 -314
- package/src/lib/fonts/shade.json +0 -591
- package/src/lib/fonts/slick.json +0 -321
- package/src/lib/fonts/tiny.json +0 -69
- package/src/lib/hast-styled-text.ts +0 -59
- package/src/lib/index.ts +0 -21
- package/src/lib/keymapping.test.ts +0 -317
- package/src/lib/keymapping.ts +0 -115
- package/src/lib/objects-in-viewport.test.ts +0 -787
- package/src/lib/objects-in-viewport.ts +0 -153
- package/src/lib/output.capture.ts +0 -58
- package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
- package/src/lib/parse.keypress-kitty.test.ts +0 -663
- package/src/lib/parse.keypress-kitty.ts +0 -439
- package/src/lib/parse.keypress.test.ts +0 -1849
- package/src/lib/parse.keypress.ts +0 -397
- package/src/lib/parse.mouse.test.ts +0 -552
- package/src/lib/parse.mouse.ts +0 -232
- package/src/lib/paste.ts +0 -16
- package/src/lib/queue.ts +0 -65
- package/src/lib/renderable.validations.test.ts +0 -87
- package/src/lib/renderable.validations.ts +0 -83
- package/src/lib/scroll-acceleration.ts +0 -98
- package/src/lib/selection.ts +0 -240
- package/src/lib/singleton.ts +0 -28
- package/src/lib/stdin-parser.test.ts +0 -2290
- package/src/lib/stdin-parser.ts +0 -1810
- package/src/lib/styled-text.ts +0 -178
- package/src/lib/terminal-capability-detection.test.ts +0 -202
- package/src/lib/terminal-capability-detection.ts +0 -79
- package/src/lib/terminal-palette.test.ts +0 -878
- package/src/lib/terminal-palette.ts +0 -383
- package/src/lib/tree-sitter/assets/README.md +0 -118
- package/src/lib/tree-sitter/assets/update.ts +0 -334
- package/src/lib/tree-sitter/assets.d.ts +0 -9
- package/src/lib/tree-sitter/cache.test.ts +0 -273
- package/src/lib/tree-sitter/client.test.ts +0 -1165
- package/src/lib/tree-sitter/client.ts +0 -607
- package/src/lib/tree-sitter/default-parsers.ts +0 -86
- package/src/lib/tree-sitter/download-utils.ts +0 -148
- package/src/lib/tree-sitter/index.ts +0 -28
- package/src/lib/tree-sitter/parser.worker.ts +0 -1042
- package/src/lib/tree-sitter/parsers-config.ts +0 -81
- package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
- package/src/lib/tree-sitter/resolve-ft.ts +0 -189
- package/src/lib/tree-sitter/types.ts +0 -82
- package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
- package/src/lib/tree-sitter-styled-text.ts +0 -306
- package/src/lib/validate-dir-name.ts +0 -55
- package/src/lib/yoga.options.test.ts +0 -628
- package/src/lib/yoga.options.ts +0 -346
- package/src/plugins/core-slot.ts +0 -579
- package/src/plugins/registry.ts +0 -402
- package/src/plugins/types.ts +0 -46
- package/src/post/effects.ts +0 -930
- package/src/post/filters.ts +0 -489
- package/src/post/matrices.ts +0 -288
- package/src/renderables/ASCIIFont.ts +0 -219
- package/src/renderables/Box.test.ts +0 -205
- package/src/renderables/Box.ts +0 -326
- package/src/renderables/Code.test.ts +0 -2062
- package/src/renderables/Code.ts +0 -357
- package/src/renderables/Diff.regression.test.ts +0 -226
- package/src/renderables/Diff.test.ts +0 -3101
- package/src/renderables/Diff.ts +0 -1211
- package/src/renderables/EditBufferRenderable.test.ts +0 -288
- package/src/renderables/EditBufferRenderable.ts +0 -1166
- package/src/renderables/FrameBuffer.ts +0 -47
- package/src/renderables/Input.test.ts +0 -1228
- package/src/renderables/Input.ts +0 -247
- package/src/renderables/LineNumberRenderable.ts +0 -724
- package/src/renderables/Markdown.ts +0 -1393
- package/src/renderables/ScrollBar.ts +0 -422
- package/src/renderables/ScrollBox.ts +0 -883
- package/src/renderables/Select.test.ts +0 -1033
- package/src/renderables/Select.ts +0 -524
- package/src/renderables/Slider.test.ts +0 -456
- package/src/renderables/Slider.ts +0 -342
- package/src/renderables/TabSelect.test.ts +0 -197
- package/src/renderables/TabSelect.ts +0 -455
- package/src/renderables/Text.selection-buffer.test.ts +0 -123
- package/src/renderables/Text.test.ts +0 -2660
- package/src/renderables/Text.ts +0 -147
- package/src/renderables/TextBufferRenderable.ts +0 -518
- package/src/renderables/TextNode.test.ts +0 -1058
- package/src/renderables/TextNode.ts +0 -325
- package/src/renderables/TextTable.test.ts +0 -1421
- package/src/renderables/TextTable.ts +0 -1344
- package/src/renderables/Textarea.ts +0 -430
- package/src/renderables/TimeToFirstDraw.ts +0 -89
- package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
- package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
- package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1865
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
- package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -242
- package/src/renderables/__tests__/Markdown.test.ts +0 -2518
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
- package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
- package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
- package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
- package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
- package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
- package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1866
- package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
- package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
- package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
- package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
- package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
- package/src/renderables/composition/README.md +0 -8
- package/src/renderables/composition/VRenderable.ts +0 -32
- package/src/renderables/composition/constructs.ts +0 -127
- package/src/renderables/composition/vnode.ts +0 -289
- package/src/renderables/index.ts +0 -23
- package/src/renderables/markdown-parser.ts +0 -66
- package/src/renderer.ts +0 -2681
- package/src/runtime-plugin-support.ts +0 -39
- package/src/runtime-plugin.ts +0 -615
- package/src/syntax-style.test.ts +0 -841
- package/src/syntax-style.ts +0 -257
- package/src/testing/README.md +0 -210
- package/src/testing/capture-spans.test.ts +0 -194
- package/src/testing/integration.test.ts +0 -276
- package/src/testing/manual-clock.ts +0 -117
- package/src/testing/mock-keys.test.ts +0 -1378
- package/src/testing/mock-keys.ts +0 -457
- package/src/testing/mock-mouse.test.ts +0 -218
- package/src/testing/mock-mouse.ts +0 -247
- package/src/testing/mock-tree-sitter-client.ts +0 -73
- package/src/testing/spy.ts +0 -13
- package/src/testing/test-recorder.test.ts +0 -415
- package/src/testing/test-recorder.ts +0 -145
- package/src/testing/test-renderer.ts +0 -132
- package/src/testing.ts +0 -7
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
- package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
- package/src/tests/allocator-stats.test.ts +0 -38
- package/src/tests/destroy-during-render.test.ts +0 -200
- package/src/tests/destroy-on-exit.fixture.ts +0 -36
- package/src/tests/destroy-on-exit.test.ts +0 -41
- package/src/tests/hover-cursor.test.ts +0 -98
- package/src/tests/native-span-feed-async.test.ts +0 -173
- package/src/tests/native-span-feed-close.test.ts +0 -120
- package/src/tests/native-span-feed-coverage.test.ts +0 -227
- package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
- package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
- package/src/tests/opacity.test.ts +0 -123
- package/src/tests/renderable.snapshot.test.ts +0 -524
- package/src/tests/renderable.test.ts +0 -1281
- package/src/tests/renderer.clock.test.ts +0 -158
- package/src/tests/renderer.console-startup.test.ts +0 -185
- package/src/tests/renderer.control.test.ts +0 -425
- package/src/tests/renderer.core-slot-binding.test.ts +0 -952
- package/src/tests/renderer.cursor.test.ts +0 -26
- package/src/tests/renderer.destroy-during-render.test.ts +0 -147
- package/src/tests/renderer.focus-restore.test.ts +0 -257
- package/src/tests/renderer.focus.test.ts +0 -294
- package/src/tests/renderer.idle.test.ts +0 -219
- package/src/tests/renderer.input.test.ts +0 -2237
- package/src/tests/renderer.kitty-flags.test.ts +0 -195
- package/src/tests/renderer.mouse.test.ts +0 -1274
- package/src/tests/renderer.palette.test.ts +0 -629
- package/src/tests/renderer.selection.test.ts +0 -49
- package/src/tests/renderer.slot-registry.test.ts +0 -684
- package/src/tests/renderer.useMouse.test.ts +0 -47
- package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
- package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
- package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
- package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
- package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
- package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
- package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
- package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
- package/src/tests/runtime-plugin-support.fixture.ts +0 -11
- package/src/tests/runtime-plugin-support.test.ts +0 -19
- package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
- package/src/tests/runtime-plugin.fixture.ts +0 -40
- package/src/tests/runtime-plugin.test.ts +0 -354
- package/src/tests/scrollbox-culling-bug.test.ts +0 -114
- package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
- package/src/tests/scrollbox-hitgrid.test.ts +0 -909
- package/src/tests/scrollbox.test.ts +0 -1530
- package/src/tests/wrap-resize-perf.test.ts +0 -276
- package/src/tests/yoga-setters.test.ts +0 -921
- package/src/text-buffer-view.test.ts +0 -705
- package/src/text-buffer-view.ts +0 -189
- package/src/text-buffer.test.ts +0 -347
- package/src/text-buffer.ts +0 -250
- package/src/types.ts +0 -161
- package/src/utils.ts +0 -88
- package/src/zig/ansi.zig +0 -268
- package/src/zig/bench/README.md +0 -50
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
- package/src/zig/bench/edit-buffer_bench.zig +0 -476
- package/src/zig/bench/native-span-feed_bench.zig +0 -100
- package/src/zig/bench/rope-markers_bench.zig +0 -713
- package/src/zig/bench/rope_bench.zig +0 -514
- package/src/zig/bench/styled-text_bench.zig +0 -470
- package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
- package/src/zig/bench/text-buffer-view_bench.zig +0 -459
- package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
- package/src/zig/bench/utf8_bench.zig +0 -799
- package/src/zig/bench-utils.zig +0 -431
- package/src/zig/bench.zig +0 -217
- package/src/zig/buffer-methods.zig +0 -211
- package/src/zig/buffer.zig +0 -2281
- package/src/zig/build.zig +0 -289
- package/src/zig/build.zig.zon +0 -16
- package/src/zig/edit-buffer.zig +0 -825
- package/src/zig/editor-view.zig +0 -802
- package/src/zig/event-bus.zig +0 -13
- package/src/zig/event-emitter.zig +0 -65
- package/src/zig/file-logger.zig +0 -92
- package/src/zig/grapheme.zig +0 -599
- package/src/zig/lib.zig +0 -1854
- package/src/zig/link.zig +0 -333
- package/src/zig/logger.zig +0 -43
- package/src/zig/mem-registry.zig +0 -125
- package/src/zig/native-span-feed-bench-lib.zig +0 -7
- package/src/zig/native-span-feed.zig +0 -708
- package/src/zig/renderer.zig +0 -1393
- package/src/zig/rope.zig +0 -1220
- package/src/zig/syntax-style.zig +0 -161
- package/src/zig/terminal.zig +0 -987
- package/src/zig/test.zig +0 -72
- package/src/zig/tests/README.md +0 -18
- package/src/zig/tests/buffer-methods_test.zig +0 -1109
- package/src/zig/tests/buffer_test.zig +0 -2557
- package/src/zig/tests/edit-buffer-history_test.zig +0 -271
- package/src/zig/tests/edit-buffer_test.zig +0 -1689
- package/src/zig/tests/editor-view_test.zig +0 -3299
- package/src/zig/tests/event-emitter_test.zig +0 -249
- package/src/zig/tests/grapheme_test.zig +0 -1304
- package/src/zig/tests/link_test.zig +0 -190
- package/src/zig/tests/mem-registry_test.zig +0 -473
- package/src/zig/tests/memory_leak_regression_test.zig +0 -159
- package/src/zig/tests/native-span-feed_test.zig +0 -1264
- package/src/zig/tests/renderer_test.zig +0 -1017
- package/src/zig/tests/rope-nested_test.zig +0 -712
- package/src/zig/tests/rope_fuzz_test.zig +0 -238
- package/src/zig/tests/rope_test.zig +0 -2362
- package/src/zig/tests/segment-merge.test.zig +0 -148
- package/src/zig/tests/syntax-style_test.zig +0 -557
- package/src/zig/tests/terminal_test.zig +0 -754
- package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
- package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
- package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
- package/src/zig/tests/text-buffer-segment_test.zig +0 -320
- package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
- package/src/zig/tests/text-buffer-view_test.zig +0 -3649
- package/src/zig/tests/text-buffer_test.zig +0 -2191
- package/src/zig/tests/unicode-width-map.zon +0 -3909
- package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
- package/src/zig/tests/utf8_test.zig +0 -4057
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
- package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
- package/src/zig/tests/word-wrap-editing_test.zig +0 -498
- package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
- package/src/zig/text-buffer-iterators.zig +0 -499
- package/src/zig/text-buffer-segment.zig +0 -404
- package/src/zig/text-buffer-view.zig +0 -1371
- package/src/zig/text-buffer.zig +0 -1180
- package/src/zig/utf8.zig +0 -1948
- package/src/zig/utils.zig +0 -9
- package/src/zig-structs.ts +0 -261
- package/src/zig.ts +0 -3884
- package/tsconfig.build.json +0 -24
- package/tsconfig.json +0 -27
- /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
- /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
package/src/zig/rope.zig
DELETED
|
@@ -1,1220 +0,0 @@
|
|
|
1
|
-
const std = @import("std");
|
|
2
|
-
const Allocator = std.mem.Allocator;
|
|
3
|
-
|
|
4
|
-
/// This is a persistent/immutable rope - operations create new nodes without
|
|
5
|
-
/// freeing old ones. Use an ArenaAllocator to avoid manual memory management:
|
|
6
|
-
///
|
|
7
|
-
/// var arena = std.heap.ArenaAllocator.init(allocator);
|
|
8
|
-
/// defer arena.deinit();
|
|
9
|
-
/// var rope = try Rope(T).init(arena.allocator());
|
|
10
|
-
///
|
|
11
|
-
/// TODO: Needs a startTransaction and endTransaction to track changes
|
|
12
|
-
/// -> used to trigger a change event _after_ a batch of changes is complete (group as operation)
|
|
13
|
-
/// -> used to group history operations (undo/redo), so not everything is a single history entry
|
|
14
|
-
///
|
|
15
|
-
pub fn Rope(comptime T: type) type {
|
|
16
|
-
return struct {
|
|
17
|
-
const Self = @This();
|
|
18
|
-
|
|
19
|
-
pub const max_imbalance = 7;
|
|
20
|
-
|
|
21
|
-
pub const Config = struct {
|
|
22
|
-
max_undo_depth: ?usize = null, // null = unlimited
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const marker_enabled = @typeInfo(T) == .@"union" and @hasDecl(T, "MarkerTypes");
|
|
26
|
-
const MarkerTagCount = if (marker_enabled) T.MarkerTypes.len else 0;
|
|
27
|
-
|
|
28
|
-
const boundary_enabled = @hasDecl(T, "BoundaryAction");
|
|
29
|
-
pub const BoundaryAction = if (boundary_enabled) T.BoundaryAction else struct {
|
|
30
|
-
delete_left: bool = false,
|
|
31
|
-
delete_right: bool = false,
|
|
32
|
-
insert_between: []const T = &[_]T{},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
pub const MarkerPosition = struct {
|
|
36
|
-
leaf_index: u32,
|
|
37
|
-
global_weight: u32,
|
|
38
|
-
};
|
|
39
|
-
pub const MarkerCache = if (marker_enabled) struct {
|
|
40
|
-
// Flat arrays of positions for each marker type
|
|
41
|
-
positions: std.AutoHashMap(std.meta.Tag(T), std.ArrayListUnmanaged(MarkerPosition)),
|
|
42
|
-
version: u64, // Rope version when cache was built
|
|
43
|
-
allocator: Allocator,
|
|
44
|
-
|
|
45
|
-
pub fn init(allocator: Allocator) MarkerCache {
|
|
46
|
-
return .{
|
|
47
|
-
.positions = std.AutoHashMap(std.meta.Tag(T), std.ArrayListUnmanaged(MarkerPosition)).init(allocator),
|
|
48
|
-
.version = std.math.maxInt(u64), // Sentinel: cache is invalid until first rebuild
|
|
49
|
-
.allocator = allocator,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
pub fn deinit(self: *MarkerCache) void {
|
|
54
|
-
var iter = self.positions.valueIterator();
|
|
55
|
-
while (iter.next()) |list| {
|
|
56
|
-
list.deinit(self.allocator);
|
|
57
|
-
}
|
|
58
|
-
self.positions.deinit();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
fn clear(self: *MarkerCache) void {
|
|
62
|
-
var iter = self.positions.valueIterator();
|
|
63
|
-
while (iter.next()) |list| {
|
|
64
|
-
list.clearRetainingCapacity();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else struct {
|
|
68
|
-
pub fn init(_: Allocator) @This() {
|
|
69
|
-
return .{};
|
|
70
|
-
}
|
|
71
|
-
pub fn deinit(_: *@This()) void {}
|
|
72
|
-
fn clear(_: *@This()) void {}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
pub const Metrics = struct {
|
|
76
|
-
count: u32 = 0,
|
|
77
|
-
depth: u32 = 1,
|
|
78
|
-
custom: if (@hasDecl(T, "Metrics")) T.Metrics else void = if (@hasDecl(T, "Metrics")) .{} else {},
|
|
79
|
-
|
|
80
|
-
marker_counts: if (marker_enabled) [MarkerTagCount]u32 else void = if (marker_enabled) [_]u32{0} ** MarkerTagCount else {},
|
|
81
|
-
|
|
82
|
-
pub fn add(self: *Metrics, other: Metrics) void {
|
|
83
|
-
self.count += other.count;
|
|
84
|
-
self.depth = @max(self.depth, other.depth);
|
|
85
|
-
|
|
86
|
-
if (@hasDecl(T, "Metrics")) {
|
|
87
|
-
if (@hasDecl(T.Metrics, "add")) {
|
|
88
|
-
self.custom.add(other.custom);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (marker_enabled) {
|
|
93
|
-
inline for (&self.marker_counts, 0..) |*dst, i| {
|
|
94
|
-
dst.* += other.marker_counts[i];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
pub fn weight(self: *const Metrics) u32 {
|
|
100
|
-
if (@hasDecl(T, "Metrics")) {
|
|
101
|
-
if (@hasDecl(T.Metrics, "weight")) {
|
|
102
|
-
return self.custom.weight();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return self.count;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
pub const Branch = struct {
|
|
110
|
-
left: *const Node,
|
|
111
|
-
right: *const Node,
|
|
112
|
-
left_metrics: Metrics,
|
|
113
|
-
total_metrics: Metrics,
|
|
114
|
-
|
|
115
|
-
fn is_balanced(self: *const Branch) bool {
|
|
116
|
-
const left_weight = self.left.metrics().weight();
|
|
117
|
-
const right_weight = self.right.metrics().weight();
|
|
118
|
-
const total_weight = left_weight + right_weight;
|
|
119
|
-
|
|
120
|
-
if (total_weight == 0) return true;
|
|
121
|
-
|
|
122
|
-
const max_side = (total_weight * 3) / 4;
|
|
123
|
-
return left_weight <= max_side and right_weight <= max_side;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
pub const Leaf = struct {
|
|
128
|
-
data: T,
|
|
129
|
-
is_sentinel: bool = false,
|
|
130
|
-
|
|
131
|
-
fn metrics(self: *const Leaf) Metrics {
|
|
132
|
-
var m = Metrics{
|
|
133
|
-
.count = if (self.is_sentinel) 0 else 1,
|
|
134
|
-
.depth = 1,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
if (@hasDecl(T, "Metrics")) {
|
|
138
|
-
if (@hasDecl(T, "measure")) {
|
|
139
|
-
m.custom = self.data.measure();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (!self.is_sentinel and marker_enabled) {
|
|
144
|
-
const tag = std.meta.activeTag(self.data);
|
|
145
|
-
inline for (T.MarkerTypes, 0..) |mt, i| {
|
|
146
|
-
if (tag == mt) {
|
|
147
|
-
m.marker_counts[i] = 1;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return m;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
pub const Node = union(enum) {
|
|
158
|
-
branch: Branch,
|
|
159
|
-
leaf: Leaf,
|
|
160
|
-
|
|
161
|
-
pub fn metrics(self: *const Node) Metrics {
|
|
162
|
-
return switch (self.*) {
|
|
163
|
-
.branch => |*b| b.total_metrics,
|
|
164
|
-
.leaf => |*l| l.metrics(),
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
pub fn depth(self: *const Node) u32 {
|
|
169
|
-
return self.metrics().depth;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
pub fn count(self: *const Node) u32 {
|
|
173
|
-
return self.metrics().count;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
pub fn is_balanced(self: *const Node) bool {
|
|
177
|
-
return switch (self.*) {
|
|
178
|
-
.branch => |*b| b.is_balanced(),
|
|
179
|
-
.leaf => true,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
pub fn is_empty(self: *const Node) bool {
|
|
184
|
-
return switch (self.*) {
|
|
185
|
-
.branch => |*b| b.left.is_empty() and b.right.is_empty(),
|
|
186
|
-
.leaf => |*l| {
|
|
187
|
-
if (@hasDecl(T, "is_empty")) {
|
|
188
|
-
return l.data.is_empty();
|
|
189
|
-
}
|
|
190
|
-
return false;
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
pub fn is_sentinel(self: *const Node, empty_leaf: *const Node) bool {
|
|
196
|
-
return self == empty_leaf;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
pub fn new_branch(allocator: Allocator, left: *const Node, right: *const Node) !*const Node {
|
|
200
|
-
const node = try allocator.create(Node);
|
|
201
|
-
errdefer allocator.destroy(node);
|
|
202
|
-
|
|
203
|
-
const left_metrics = left.metrics();
|
|
204
|
-
var total_metrics = Metrics{};
|
|
205
|
-
total_metrics.add(left_metrics);
|
|
206
|
-
total_metrics.add(right.metrics());
|
|
207
|
-
total_metrics.depth += 1;
|
|
208
|
-
|
|
209
|
-
node.* = .{ .branch = .{
|
|
210
|
-
.left = left,
|
|
211
|
-
.right = right,
|
|
212
|
-
.left_metrics = left_metrics,
|
|
213
|
-
.total_metrics = total_metrics,
|
|
214
|
-
} };
|
|
215
|
-
|
|
216
|
-
return node;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
pub fn new_leaf(allocator: Allocator, data: T) !*const Node {
|
|
220
|
-
const node = try allocator.create(Node);
|
|
221
|
-
errdefer allocator.destroy(node);
|
|
222
|
-
|
|
223
|
-
node.* = .{ .leaf = .{ .data = data } };
|
|
224
|
-
return node;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
pub fn get(self: *const Node, index: u32) ?*const T {
|
|
228
|
-
return switch (self.*) {
|
|
229
|
-
.branch => |*b| {
|
|
230
|
-
const left_count = b.left_metrics.count;
|
|
231
|
-
if (index < left_count) {
|
|
232
|
-
return b.left.get(index);
|
|
233
|
-
}
|
|
234
|
-
return b.right.get(index - left_count);
|
|
235
|
-
},
|
|
236
|
-
.leaf => |*l| if (index == 0) &l.data else null,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
pub const WalkerFn = *const fn (ctx: *anyopaque, data: *const T, index: u32) WalkerResult;
|
|
241
|
-
|
|
242
|
-
pub const WalkerResult = struct {
|
|
243
|
-
keep_walking: bool = true,
|
|
244
|
-
err: ?anyerror = null,
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
pub fn walk(self: *const Node, ctx: *anyopaque, f: WalkerFn, current_index: *u32) WalkerResult {
|
|
248
|
-
return switch (self.*) {
|
|
249
|
-
.branch => |*b| {
|
|
250
|
-
const left_result = b.left.walk(ctx, f, current_index);
|
|
251
|
-
if (!left_result.keep_walking or left_result.err != null) {
|
|
252
|
-
return left_result;
|
|
253
|
-
}
|
|
254
|
-
return b.right.walk(ctx, f, current_index);
|
|
255
|
-
},
|
|
256
|
-
.leaf => |*l| {
|
|
257
|
-
const result = f(ctx, &l.data, current_index.*);
|
|
258
|
-
current_index.* += 1;
|
|
259
|
-
return result;
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
pub fn walk_from(self: *const Node, start_index: u32, ctx: *anyopaque, f: WalkerFn) WalkerResult {
|
|
265
|
-
var current_index: u32 = start_index;
|
|
266
|
-
return self.walk_from_internal(start_index, ctx, f, ¤t_index);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
fn walk_from_internal(self: *const Node, start_index: u32, ctx: *anyopaque, f: WalkerFn, current_index: *u32) WalkerResult {
|
|
270
|
-
return switch (self.*) {
|
|
271
|
-
.branch => |*b| {
|
|
272
|
-
const left_count = b.left_metrics.count;
|
|
273
|
-
if (start_index >= left_count) {
|
|
274
|
-
return b.right.walk_from_internal(start_index - left_count, ctx, f, current_index);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const left_result = b.left.walk_from_internal(start_index, ctx, f, current_index);
|
|
278
|
-
if (!left_result.keep_walking or left_result.err != null) {
|
|
279
|
-
return left_result;
|
|
280
|
-
}
|
|
281
|
-
return b.right.walk(ctx, f, current_index);
|
|
282
|
-
},
|
|
283
|
-
.leaf => |*l| {
|
|
284
|
-
if (start_index == 0) {
|
|
285
|
-
const result = f(ctx, &l.data, current_index.*);
|
|
286
|
-
current_index.* += 1;
|
|
287
|
-
return result;
|
|
288
|
-
}
|
|
289
|
-
return .{};
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
fn collect(self: *const Node, list: *std.ArrayListUnmanaged(*const Node), allocator: Allocator) !void {
|
|
295
|
-
switch (self.*) {
|
|
296
|
-
.branch => |*b| {
|
|
297
|
-
try b.left.collect(list, allocator);
|
|
298
|
-
try b.right.collect(list, allocator);
|
|
299
|
-
},
|
|
300
|
-
.leaf => try list.append(allocator, self),
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
fn merge_leaves(leaves: []*const Node, allocator: Allocator) error{OutOfMemory}!*const Node {
|
|
305
|
-
const len = leaves.len;
|
|
306
|
-
if (len == 0) return error.OutOfMemory; // Should not happen
|
|
307
|
-
if (len == 1) return leaves[0];
|
|
308
|
-
if (len == 2) return try Node.new_branch(allocator, leaves[0], leaves[1]);
|
|
309
|
-
|
|
310
|
-
const mid = len / 2;
|
|
311
|
-
return try Node.new_branch(
|
|
312
|
-
allocator,
|
|
313
|
-
try merge_leaves(leaves[0..mid], allocator),
|
|
314
|
-
try merge_leaves(leaves[mid..], allocator),
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
pub fn rebalance(self: *const Node, allocator: Allocator, tmp_allocator: Allocator) !*const Node {
|
|
319
|
-
if (self.is_balanced()) return self;
|
|
320
|
-
|
|
321
|
-
var leaves: std.ArrayListUnmanaged(*const Node) = .{};
|
|
322
|
-
defer leaves.deinit(tmp_allocator);
|
|
323
|
-
|
|
324
|
-
try leaves.ensureTotalCapacity(tmp_allocator, self.count());
|
|
325
|
-
try self.collect(&leaves, tmp_allocator);
|
|
326
|
-
|
|
327
|
-
return try merge_leaves(leaves.items, allocator);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/// Structural split at index - returns (left, right) without flattening
|
|
331
|
-
pub fn split_at(node: *const Node, index: u32, allocator: Allocator, empty_leaf: *const Node) error{OutOfMemory}!struct { left: *const Node, right: *const Node } {
|
|
332
|
-
return switch (node.*) {
|
|
333
|
-
.leaf => {
|
|
334
|
-
if (index == 0) {
|
|
335
|
-
return .{ .left = empty_leaf, .right = node };
|
|
336
|
-
} else {
|
|
337
|
-
return .{ .left = node, .right = empty_leaf };
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
.branch => |*b| {
|
|
341
|
-
const left_count = b.left_metrics.count;
|
|
342
|
-
if (index < left_count) {
|
|
343
|
-
const result = try split_at(b.left, index, allocator, empty_leaf);
|
|
344
|
-
const new_right = try join_balanced(result.right, b.right, allocator);
|
|
345
|
-
return .{ .left = result.left, .right = new_right };
|
|
346
|
-
} else if (index > left_count) {
|
|
347
|
-
const result = try split_at(b.right, index - left_count, allocator, empty_leaf);
|
|
348
|
-
const new_left = try join_balanced(b.left, result.left, allocator);
|
|
349
|
-
return .{ .left = new_left, .right = result.right };
|
|
350
|
-
} else {
|
|
351
|
-
return .{ .left = b.left, .right = b.right };
|
|
352
|
-
}
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
pub fn join_balanced(left: *const Node, right: *const Node, allocator: Allocator) error{OutOfMemory}!*const Node {
|
|
358
|
-
const left_count = left.metrics().count;
|
|
359
|
-
const right_count = right.metrics().count;
|
|
360
|
-
|
|
361
|
-
if (left_count == 0) return right;
|
|
362
|
-
if (right_count == 0) return left;
|
|
363
|
-
|
|
364
|
-
const left_weight = left.metrics().weight();
|
|
365
|
-
const right_weight = right.metrics().weight();
|
|
366
|
-
const total_weight = left_weight + right_weight;
|
|
367
|
-
|
|
368
|
-
if (total_weight > 0) {
|
|
369
|
-
const max_side = (total_weight * 3) / 4;
|
|
370
|
-
if (left_weight <= max_side and right_weight <= max_side) {
|
|
371
|
-
return try new_branch(allocator, left, right);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (left_weight > right_weight * 3) {
|
|
376
|
-
return switch (left.*) {
|
|
377
|
-
.leaf => try new_branch(allocator, left, right),
|
|
378
|
-
.branch => |*b| {
|
|
379
|
-
const new_right = try join_balanced(b.right, right, allocator);
|
|
380
|
-
return try new_branch(allocator, b.left, new_right);
|
|
381
|
-
},
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return switch (right.*) {
|
|
386
|
-
.leaf => try new_branch(allocator, left, right),
|
|
387
|
-
.branch => |*b| {
|
|
388
|
-
const new_left = try join_balanced(left, b.left, allocator);
|
|
389
|
-
return try new_branch(allocator, new_left, b.right);
|
|
390
|
-
},
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
pub const LeafSplitResult = struct { left: T, right: T };
|
|
395
|
-
|
|
396
|
-
pub const LeafSplitFn = struct {
|
|
397
|
-
ctx: ?*anyopaque = null,
|
|
398
|
-
splitFn: *const fn (ctx: ?*anyopaque, allocator: Allocator, leaf: *const T, weight_in_leaf: u32) error{ OutOfBounds, OutOfMemory }!LeafSplitResult,
|
|
399
|
-
|
|
400
|
-
pub fn call(self: *const @This(), allocator: Allocator, leaf: *const T, weight: u32) error{ OutOfBounds, OutOfMemory }!LeafSplitResult {
|
|
401
|
-
return self.splitFn(self.ctx, allocator, leaf, weight);
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
pub fn split_at_weight(
|
|
406
|
-
node: *const Node,
|
|
407
|
-
target_weight: u32,
|
|
408
|
-
allocator: Allocator,
|
|
409
|
-
empty_leaf: *const Node,
|
|
410
|
-
split_leaf_fn: *const LeafSplitFn,
|
|
411
|
-
) error{ OutOfMemory, OutOfBounds }!struct { left: *const Node, right: *const Node } {
|
|
412
|
-
return switch (node.*) {
|
|
413
|
-
.leaf => |*l| {
|
|
414
|
-
const leaf_weight = node.metrics().weight();
|
|
415
|
-
|
|
416
|
-
if (target_weight == 0) {
|
|
417
|
-
return .{ .left = empty_leaf, .right = node };
|
|
418
|
-
} else if (target_weight >= leaf_weight) {
|
|
419
|
-
return .{ .left = node, .right = empty_leaf };
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
const split_result = try split_leaf_fn.call(allocator, &l.data, target_weight);
|
|
423
|
-
const left_node = try new_leaf(allocator, split_result.left);
|
|
424
|
-
const right_node = try new_leaf(allocator, split_result.right);
|
|
425
|
-
return .{ .left = left_node, .right = right_node };
|
|
426
|
-
},
|
|
427
|
-
.branch => |*b| {
|
|
428
|
-
const left_weight = b.left_metrics.weight();
|
|
429
|
-
|
|
430
|
-
if (target_weight < left_weight) {
|
|
431
|
-
const result = try split_at_weight(b.left, target_weight, allocator, empty_leaf, split_leaf_fn);
|
|
432
|
-
const new_right = try join_balanced(result.right, b.right, allocator);
|
|
433
|
-
return .{ .left = result.left, .right = new_right };
|
|
434
|
-
} else if (target_weight > left_weight) {
|
|
435
|
-
const result = try split_at_weight(b.right, target_weight - left_weight, allocator, empty_leaf, split_leaf_fn);
|
|
436
|
-
const new_left = try join_balanced(b.left, result.left, allocator);
|
|
437
|
-
return .{ .left = new_left, .right = result.right };
|
|
438
|
-
} else {
|
|
439
|
-
return .{ .left = b.left, .right = b.right };
|
|
440
|
-
}
|
|
441
|
-
},
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
pub const UndoNode = struct {
|
|
447
|
-
root: *const Node,
|
|
448
|
-
next: ?*UndoNode = null,
|
|
449
|
-
branches: ?*UndoBranch = null,
|
|
450
|
-
meta: []const u8,
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
pub const UndoBranch = struct {
|
|
454
|
-
redo: *UndoNode,
|
|
455
|
-
next: ?*UndoBranch,
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
root: *const Node,
|
|
459
|
-
allocator: Allocator,
|
|
460
|
-
empty_leaf: *const Node,
|
|
461
|
-
undo_history: ?*UndoNode = null,
|
|
462
|
-
redo_history: ?*UndoNode = null,
|
|
463
|
-
curr_history: ?*UndoNode = null,
|
|
464
|
-
config: Config = .{},
|
|
465
|
-
undo_depth: usize = 0,
|
|
466
|
-
version: u64 = 0,
|
|
467
|
-
marker_cache: MarkerCache,
|
|
468
|
-
|
|
469
|
-
pub fn init(allocator: Allocator) error{OutOfMemory}!Self {
|
|
470
|
-
return initWithConfig(allocator, .{});
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
pub fn initWithConfig(allocator: Allocator, config: Config) error{OutOfMemory}!Self {
|
|
474
|
-
const empty_data = if (@hasDecl(T, "empty"))
|
|
475
|
-
T.empty()
|
|
476
|
-
else
|
|
477
|
-
std.mem.zeroes(T);
|
|
478
|
-
|
|
479
|
-
const node = try allocator.create(Node);
|
|
480
|
-
node.* = .{ .leaf = .{ .data = empty_data, .is_sentinel = true } };
|
|
481
|
-
|
|
482
|
-
var self = Self{
|
|
483
|
-
.root = node,
|
|
484
|
-
.allocator = allocator,
|
|
485
|
-
.empty_leaf = node,
|
|
486
|
-
.config = config,
|
|
487
|
-
.marker_cache = MarkerCache.init(allocator),
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
try self.applyEndsInvariant();
|
|
491
|
-
|
|
492
|
-
return self;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
pub fn from_item(allocator: Allocator, data: T) !Self {
|
|
496
|
-
return from_itemWithConfig(allocator, data, .{});
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
pub fn from_itemWithConfig(allocator: Allocator, data: T, config: Config) !Self {
|
|
500
|
-
const root = try Node.new_leaf(allocator, data);
|
|
501
|
-
const empty_data = if (@hasDecl(T, "empty"))
|
|
502
|
-
T.empty()
|
|
503
|
-
else
|
|
504
|
-
std.mem.zeroes(T);
|
|
505
|
-
|
|
506
|
-
const empty_node = try allocator.create(Node);
|
|
507
|
-
empty_node.* = .{ .leaf = .{ .data = empty_data, .is_sentinel = true } };
|
|
508
|
-
|
|
509
|
-
return .{
|
|
510
|
-
.root = root,
|
|
511
|
-
.allocator = allocator,
|
|
512
|
-
.empty_leaf = empty_node,
|
|
513
|
-
.config = config,
|
|
514
|
-
.marker_cache = MarkerCache.init(allocator),
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
pub fn from_slice(allocator: Allocator, items: []const T) !Self {
|
|
519
|
-
return from_sliceWithConfig(allocator, items, .{});
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
pub fn from_sliceWithConfig(allocator: Allocator, items: []const T, config: Config) !Self {
|
|
523
|
-
if (items.len == 0) {
|
|
524
|
-
return try initWithConfig(allocator, config);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
var leaves: std.ArrayListUnmanaged(*const Node) = .{};
|
|
528
|
-
defer leaves.deinit(allocator);
|
|
529
|
-
try leaves.ensureTotalCapacity(allocator, items.len);
|
|
530
|
-
|
|
531
|
-
for (items) |item| {
|
|
532
|
-
const leaf = try Node.new_leaf(allocator, item);
|
|
533
|
-
try leaves.append(allocator, leaf);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
const root = try Node.merge_leaves(leaves.items, allocator);
|
|
537
|
-
const empty_data = if (@hasDecl(T, "empty"))
|
|
538
|
-
T.empty()
|
|
539
|
-
else
|
|
540
|
-
std.mem.zeroes(T);
|
|
541
|
-
|
|
542
|
-
const empty_node = try allocator.create(Node);
|
|
543
|
-
empty_node.* = .{ .leaf = .{ .data = empty_data, .is_sentinel = true } };
|
|
544
|
-
|
|
545
|
-
return .{
|
|
546
|
-
.root = root,
|
|
547
|
-
.allocator = allocator,
|
|
548
|
-
.empty_leaf = empty_node,
|
|
549
|
-
.config = config,
|
|
550
|
-
.marker_cache = MarkerCache.init(allocator),
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
pub fn count(self: *const Self) u32 {
|
|
555
|
-
return self.root.count();
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
pub fn get(self: *const Self, index: u32) ?*const T {
|
|
559
|
-
return self.root.get(index);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
pub fn walk(self: *const Self, ctx: *anyopaque, f: Node.WalkerFn) !void {
|
|
563
|
-
var index: u32 = 0;
|
|
564
|
-
const result = self.walkNode(self.root, ctx, f, &index);
|
|
565
|
-
if (result.err) |e| return e;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
fn walkNode(self: *const Self, node: *const Node, ctx: *anyopaque, f: Node.WalkerFn, current_index: *u32) Node.WalkerResult {
|
|
569
|
-
return switch (node.*) {
|
|
570
|
-
.branch => |*b| {
|
|
571
|
-
const left_result = self.walkNode(b.left, ctx, f, current_index);
|
|
572
|
-
if (!left_result.keep_walking or left_result.err != null) {
|
|
573
|
-
return left_result;
|
|
574
|
-
}
|
|
575
|
-
return self.walkNode(b.right, ctx, f, current_index);
|
|
576
|
-
},
|
|
577
|
-
.leaf => |*l| {
|
|
578
|
-
if (node.count() == 0) {
|
|
579
|
-
return .{};
|
|
580
|
-
}
|
|
581
|
-
const result = f(ctx, &l.data, current_index.*);
|
|
582
|
-
current_index.* += 1;
|
|
583
|
-
return result;
|
|
584
|
-
},
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
pub fn walk_from(self: *const Self, start_index: u32, ctx: *anyopaque, f: Node.WalkerFn) !void {
|
|
589
|
-
var current_index: u32 = 0;
|
|
590
|
-
const result = self.walkFromNode(self.root, start_index, ctx, f, ¤t_index);
|
|
591
|
-
if (result.err) |e| return e;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
fn walkFromNode(self: *const Self, node: *const Node, start_index: u32, ctx: *anyopaque, f: Node.WalkerFn, current_index: *u32) Node.WalkerResult {
|
|
595
|
-
return switch (node.*) {
|
|
596
|
-
.branch => |*b| {
|
|
597
|
-
const left_count = b.left_metrics.count;
|
|
598
|
-
if (start_index >= left_count) {
|
|
599
|
-
return self.walkFromNode(b.right, start_index - left_count, ctx, f, current_index);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
const left_result = self.walkFromNode(b.left, start_index, ctx, f, current_index);
|
|
603
|
-
if (!left_result.keep_walking or left_result.err != null) {
|
|
604
|
-
return left_result;
|
|
605
|
-
}
|
|
606
|
-
return self.walkNode(b.right, ctx, f, current_index);
|
|
607
|
-
},
|
|
608
|
-
.leaf => |*l| {
|
|
609
|
-
if (node.count() == 0) {
|
|
610
|
-
return .{};
|
|
611
|
-
}
|
|
612
|
-
if (start_index == 0) {
|
|
613
|
-
const result = f(ctx, &l.data, current_index.*);
|
|
614
|
-
current_index.* += 1;
|
|
615
|
-
return result;
|
|
616
|
-
}
|
|
617
|
-
return .{};
|
|
618
|
-
},
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
pub fn rebalance(self: *Self, tmp_allocator: Allocator) !void {
|
|
623
|
-
self.root = try self.root.rebalance(self.allocator, tmp_allocator);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
pub fn insert(self: *Self, index: u32, data: T) !void {
|
|
627
|
-
try self.insert_slice(index, &[_]T{data});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
pub fn delete(self: *Self, index: u32) !void {
|
|
631
|
-
try self.delete_range(index, index + 1);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
pub fn replace(self: *Self, index: u32, data: T) !void {
|
|
635
|
-
if (index >= self.count()) return;
|
|
636
|
-
|
|
637
|
-
try self.delete_range(index, index + 1);
|
|
638
|
-
try self.insert_slice(index, &[_]T{data});
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
pub fn append(self: *Self, data: T) !void {
|
|
642
|
-
try self.insert(self.count(), data);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
pub fn prepend(self: *Self, data: T) !void {
|
|
646
|
-
try self.insert(0, data);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
pub fn concat(self: *Self, other: *const Self) !void {
|
|
650
|
-
self.root = try self.joinWithBoundary(self.root, other.root);
|
|
651
|
-
self.version += 1;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
pub fn split(self: *Self, index: u32) !Self {
|
|
655
|
-
const result = try Node.split_at(self.root, index, self.allocator, self.empty_leaf);
|
|
656
|
-
self.root = result.left;
|
|
657
|
-
self.version += 1;
|
|
658
|
-
return Self{
|
|
659
|
-
.root = result.right,
|
|
660
|
-
.allocator = self.allocator,
|
|
661
|
-
.empty_leaf = self.empty_leaf,
|
|
662
|
-
.undo_history = null,
|
|
663
|
-
.redo_history = null,
|
|
664
|
-
.curr_history = null,
|
|
665
|
-
.marker_cache = MarkerCache.init(self.allocator),
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
pub fn slice(self: *const Self, start: u32, end: u32, allocator: Allocator) ![]T {
|
|
670
|
-
if (start >= end) return &[_]T{};
|
|
671
|
-
|
|
672
|
-
const SliceContext = struct {
|
|
673
|
-
items: std.ArrayListUnmanaged(T),
|
|
674
|
-
allocator: Allocator,
|
|
675
|
-
start: u32,
|
|
676
|
-
end: u32,
|
|
677
|
-
current_index: u32 = 0,
|
|
678
|
-
|
|
679
|
-
fn walker(ctx: *anyopaque, data: *const T, idx: u32) Node.WalkerResult {
|
|
680
|
-
_ = idx;
|
|
681
|
-
const context = @as(*@This(), @ptrCast(@alignCast(ctx)));
|
|
682
|
-
if (context.current_index >= context.start and context.current_index < context.end) {
|
|
683
|
-
context.items.append(context.allocator, data.*) catch |e| return .{ .err = e };
|
|
684
|
-
}
|
|
685
|
-
context.current_index += 1;
|
|
686
|
-
if (context.current_index >= context.end) {
|
|
687
|
-
return .{ .keep_walking = false };
|
|
688
|
-
}
|
|
689
|
-
return .{};
|
|
690
|
-
}
|
|
691
|
-
};
|
|
692
|
-
|
|
693
|
-
var context = SliceContext{
|
|
694
|
-
.items = .{},
|
|
695
|
-
.allocator = allocator,
|
|
696
|
-
.start = start,
|
|
697
|
-
.end = end,
|
|
698
|
-
};
|
|
699
|
-
errdefer context.items.deinit(allocator);
|
|
700
|
-
|
|
701
|
-
try self.walk(&context, SliceContext.walker);
|
|
702
|
-
return context.items.toOwnedSlice(allocator);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
pub fn delete_range(self: *Self, start: u32, end: u32) !void {
|
|
706
|
-
if (start >= end) return;
|
|
707
|
-
|
|
708
|
-
const first_split = try Node.split_at(self.root, start, self.allocator, self.empty_leaf);
|
|
709
|
-
const second_split = try Node.split_at(first_split.right, end - start, self.allocator, self.empty_leaf);
|
|
710
|
-
|
|
711
|
-
self.root = try self.joinWithBoundary(first_split.left, second_split.right);
|
|
712
|
-
|
|
713
|
-
self.version += 1;
|
|
714
|
-
try self.applyEndsInvariant();
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
pub fn insert_slice(self: *Self, index: u32, items: []const T) !void {
|
|
718
|
-
if (items.len == 0) return;
|
|
719
|
-
|
|
720
|
-
const insert_rope = try Self.from_slice(self.allocator, items);
|
|
721
|
-
|
|
722
|
-
const split_result = try Node.split_at(self.root, index, self.allocator, self.empty_leaf);
|
|
723
|
-
|
|
724
|
-
const left_joined = try self.joinWithBoundary(split_result.left, insert_rope.root);
|
|
725
|
-
self.root = try self.joinWithBoundary(left_joined, split_result.right);
|
|
726
|
-
|
|
727
|
-
self.version += 1;
|
|
728
|
-
try self.applyEndsInvariant();
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
pub fn to_array(self: *const Self, allocator: Allocator) ![]T {
|
|
732
|
-
const ToArrayContext = struct {
|
|
733
|
-
items: std.ArrayListUnmanaged(T),
|
|
734
|
-
allocator: Allocator,
|
|
735
|
-
|
|
736
|
-
fn walker(ctx: *anyopaque, data: *const T, idx: u32) Node.WalkerResult {
|
|
737
|
-
_ = idx;
|
|
738
|
-
const context = @as(*@This(), @ptrCast(@alignCast(ctx)));
|
|
739
|
-
context.items.append(context.allocator, data.*) catch |e| return .{ .err = e };
|
|
740
|
-
return .{};
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
|
|
744
|
-
var context = ToArrayContext{
|
|
745
|
-
.items = .{},
|
|
746
|
-
.allocator = allocator,
|
|
747
|
-
};
|
|
748
|
-
errdefer context.items.deinit(allocator);
|
|
749
|
-
|
|
750
|
-
try self.walk(&context, ToArrayContext.walker);
|
|
751
|
-
return context.items.toOwnedSlice(allocator);
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
pub fn toText(self: *const Self, allocator: Allocator) ![]u8 {
|
|
755
|
-
var buffer: std.ArrayListUnmanaged(u8) = .{};
|
|
756
|
-
errdefer buffer.deinit(allocator);
|
|
757
|
-
|
|
758
|
-
try buffer.appendSlice(allocator, "[root");
|
|
759
|
-
try nodeToText(self.root, &buffer, allocator);
|
|
760
|
-
try buffer.append(allocator, ']');
|
|
761
|
-
|
|
762
|
-
return buffer.toOwnedSlice(allocator);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
fn nodeToText(node: *const Node, buffer: *std.ArrayListUnmanaged(u8), allocator: Allocator) !void {
|
|
766
|
-
switch (node.*) {
|
|
767
|
-
.branch => |*b| {
|
|
768
|
-
try buffer.appendSlice(allocator, "[branch");
|
|
769
|
-
try nodeToText(b.left, buffer, allocator);
|
|
770
|
-
try nodeToText(b.right, buffer, allocator);
|
|
771
|
-
try buffer.append(allocator, ']');
|
|
772
|
-
},
|
|
773
|
-
.leaf => |*l| {
|
|
774
|
-
if (l.is_sentinel) {
|
|
775
|
-
try buffer.appendSlice(allocator, "[empty]");
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
if (@typeInfo(T) == .@"union") {
|
|
780
|
-
const tag = std.meta.activeTag(l.data);
|
|
781
|
-
const tag_name = @tagName(tag);
|
|
782
|
-
|
|
783
|
-
try buffer.append(allocator, '[');
|
|
784
|
-
try buffer.appendSlice(allocator, tag_name);
|
|
785
|
-
|
|
786
|
-
if (@hasDecl(T, "Metrics")) {
|
|
787
|
-
const metrics = l.metrics();
|
|
788
|
-
try buffer.append(allocator, ':');
|
|
789
|
-
try buffer.writer(allocator).print("w{d}", .{metrics.weight()});
|
|
790
|
-
|
|
791
|
-
if (@hasDecl(T.Metrics, "total_width")) {
|
|
792
|
-
try buffer.writer(allocator).print(",tw{d}", .{metrics.custom.total_width});
|
|
793
|
-
}
|
|
794
|
-
if (@hasDecl(T.Metrics, "total_bytes")) {
|
|
795
|
-
try buffer.writer(allocator).print(",b{d}", .{metrics.custom.total_bytes});
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
try buffer.append(allocator, ']');
|
|
800
|
-
} else {
|
|
801
|
-
try buffer.appendSlice(allocator, "[leaf");
|
|
802
|
-
if (@hasDecl(T, "Metrics")) {
|
|
803
|
-
const metrics = l.metrics();
|
|
804
|
-
try buffer.append(allocator, ':');
|
|
805
|
-
try buffer.writer(allocator).print("w{d}", .{metrics.weight()});
|
|
806
|
-
}
|
|
807
|
-
try buffer.append(allocator, ']');
|
|
808
|
-
}
|
|
809
|
-
},
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
pub fn totalWeight(self: *const Self) u32 {
|
|
814
|
-
return self.root.metrics().weight();
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
pub fn splitByWeight(self: *Self, weight: u32, split_leaf_fn: *const Node.LeafSplitFn) !Self {
|
|
818
|
-
const result = try Node.split_at_weight(self.root, weight, self.allocator, self.empty_leaf, split_leaf_fn);
|
|
819
|
-
self.root = result.left;
|
|
820
|
-
self.version += 1;
|
|
821
|
-
return Self{
|
|
822
|
-
.root = result.right,
|
|
823
|
-
.allocator = self.allocator,
|
|
824
|
-
.empty_leaf = self.empty_leaf,
|
|
825
|
-
.undo_history = null,
|
|
826
|
-
.redo_history = null,
|
|
827
|
-
.curr_history = null,
|
|
828
|
-
.marker_cache = MarkerCache.init(self.allocator),
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
fn getLastLeaf(self: *const Self) ?*const T {
|
|
833
|
-
if (self.count() == 0) return null;
|
|
834
|
-
return self.get(self.count() - 1);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
fn getFirstLeaf(self: *const Self) ?*const T {
|
|
838
|
-
if (self.count() == 0) return null;
|
|
839
|
-
return self.get(0);
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
fn getFirstLeafIn(node: *const Node) ?*const T {
|
|
843
|
-
return switch (node.*) {
|
|
844
|
-
.branch => |*b| getFirstLeafIn(b.left),
|
|
845
|
-
.leaf => |*l| if (node.count() == 0) null else &l.data,
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
fn getLastLeafIn(node: *const Node) ?*const T {
|
|
850
|
-
return switch (node.*) {
|
|
851
|
-
.branch => |*b| getLastLeafIn(b.right),
|
|
852
|
-
.leaf => |*l| if (node.count() == 0) null else &l.data,
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
fn dropFirst(node: *const Node, allocator: Allocator, empty_leaf: *const Node) error{OutOfMemory}!*const Node {
|
|
857
|
-
if (node.count() == 0) return node;
|
|
858
|
-
const split_result = try Node.split_at(node, 1, allocator, empty_leaf);
|
|
859
|
-
return split_result.right;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
fn dropLast(node: *const Node, allocator: Allocator, empty_leaf: *const Node) error{OutOfMemory}!*const Node {
|
|
863
|
-
const cnt = node.count();
|
|
864
|
-
if (cnt == 0) return node;
|
|
865
|
-
const split_result = try Node.split_at(node, cnt - 1, allocator, empty_leaf);
|
|
866
|
-
return split_result.left;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
fn joinWithBoundary(self: *Self, left: *const Node, right: *const Node) error{OutOfMemory}!*const Node {
|
|
870
|
-
if (!boundary_enabled or !@hasDecl(T, "rewriteBoundary")) {
|
|
871
|
-
return try Node.join_balanced(left, right, self.allocator);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
const l_last = getLastLeafIn(left);
|
|
875
|
-
const r_first = getFirstLeafIn(right);
|
|
876
|
-
|
|
877
|
-
if (@hasDecl(T, "canMerge") and @hasDecl(T, "merge")) {
|
|
878
|
-
if (l_last != null and r_first != null) {
|
|
879
|
-
if (T.canMerge(l_last.?, r_first.?)) {
|
|
880
|
-
const merged = T.merge(self.allocator, l_last.?, r_first.?);
|
|
881
|
-
const merged_leaf = try Node.new_leaf(self.allocator, merged);
|
|
882
|
-
|
|
883
|
-
const L = try dropLast(left, self.allocator, self.empty_leaf);
|
|
884
|
-
const R = try dropFirst(right, self.allocator, self.empty_leaf);
|
|
885
|
-
|
|
886
|
-
const left_with_merged = try Node.join_balanced(L, merged_leaf, self.allocator);
|
|
887
|
-
return try Node.join_balanced(left_with_merged, R, self.allocator);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
const action = try T.rewriteBoundary(self.allocator, l_last, r_first);
|
|
893
|
-
|
|
894
|
-
var L = left;
|
|
895
|
-
var R = right;
|
|
896
|
-
|
|
897
|
-
if (action.delete_left) {
|
|
898
|
-
L = try dropLast(L, self.allocator, self.empty_leaf);
|
|
899
|
-
}
|
|
900
|
-
if (action.delete_right) {
|
|
901
|
-
R = try dropFirst(R, self.allocator, self.empty_leaf);
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
if (action.insert_between.len > 0) {
|
|
905
|
-
const insert_rope = try Self.from_slice(self.allocator, action.insert_between);
|
|
906
|
-
const left_with_insert = try Node.join_balanced(L, insert_rope.root, self.allocator);
|
|
907
|
-
return try Node.join_balanced(left_with_insert, R, self.allocator);
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
return try Node.join_balanced(L, R, self.allocator);
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
fn applyEndsInvariant(self: *Self) !void {
|
|
914
|
-
if (!boundary_enabled or !@hasDecl(T, "rewriteEnds")) return;
|
|
915
|
-
|
|
916
|
-
const first = self.getFirstLeaf();
|
|
917
|
-
const last = self.getLastLeaf();
|
|
918
|
-
const action = try T.rewriteEnds(self.allocator, first, last);
|
|
919
|
-
|
|
920
|
-
// Handle deletion operations first
|
|
921
|
-
if (action.delete_left and self.count() > 0) {
|
|
922
|
-
const split_result = try Node.split_at(self.root, 1, self.allocator, self.empty_leaf);
|
|
923
|
-
self.root = split_result.right;
|
|
924
|
-
}
|
|
925
|
-
if (action.delete_right and self.count() > 0) {
|
|
926
|
-
const cnt = self.count();
|
|
927
|
-
const split_result = try Node.split_at(self.root, cnt - 1, self.allocator, self.empty_leaf);
|
|
928
|
-
self.root = split_result.left;
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// Handle insertion
|
|
932
|
-
if (action.insert_between.len > 0) {
|
|
933
|
-
var leaves: std.ArrayListUnmanaged(*const Node) = .{};
|
|
934
|
-
defer leaves.deinit(self.allocator);
|
|
935
|
-
try leaves.ensureTotalCapacity(self.allocator, action.insert_between.len);
|
|
936
|
-
|
|
937
|
-
for (action.insert_between) |item| {
|
|
938
|
-
const leaf = try Node.new_leaf(self.allocator, item);
|
|
939
|
-
try leaves.append(self.allocator, leaf);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
const insert_root = try Node.merge_leaves(leaves.items, self.allocator);
|
|
943
|
-
self.root = try Node.join_balanced(insert_root, self.root, self.allocator);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
pub fn deleteRangeByWeight(self: *Self, start: u32, end: u32, split_leaf_fn: *const Node.LeafSplitFn) !void {
|
|
948
|
-
if (start >= end) return;
|
|
949
|
-
|
|
950
|
-
const first_split = try Node.split_at_weight(self.root, start, self.allocator, self.empty_leaf, split_leaf_fn);
|
|
951
|
-
const second_split = try Node.split_at_weight(first_split.right, end - start, self.allocator, self.empty_leaf, split_leaf_fn);
|
|
952
|
-
|
|
953
|
-
self.root = try self.joinWithBoundary(first_split.left, second_split.right);
|
|
954
|
-
|
|
955
|
-
self.version += 1;
|
|
956
|
-
try self.applyEndsInvariant();
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
pub fn insertSliceByWeight(self: *Self, weight: u32, items: []const T, split_leaf_fn: *const Node.LeafSplitFn) !void {
|
|
960
|
-
if (items.len == 0) return;
|
|
961
|
-
|
|
962
|
-
const insert_rope = try Self.from_slice(self.allocator, items);
|
|
963
|
-
|
|
964
|
-
const split_result = try Node.split_at_weight(self.root, weight, self.allocator, self.empty_leaf, split_leaf_fn);
|
|
965
|
-
|
|
966
|
-
const left_joined = try self.joinWithBoundary(split_result.left, insert_rope.root);
|
|
967
|
-
self.root = try self.joinWithBoundary(left_joined, split_result.right);
|
|
968
|
-
|
|
969
|
-
self.version += 1;
|
|
970
|
-
try self.applyEndsInvariant();
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
pub const WeightFindResult = struct { leaf: *const T, start_weight: u32 };
|
|
974
|
-
|
|
975
|
-
pub fn findByWeight(self: *const Self, weight: u32) ?WeightFindResult {
|
|
976
|
-
return self.findByWeightInNode(self.root, weight, 0);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
fn findByWeightInNode(self: *const Self, node: *const Node, target_weight: u32, current_weight: u32) ?WeightFindResult {
|
|
980
|
-
return switch (node.*) {
|
|
981
|
-
.branch => |*b| {
|
|
982
|
-
const left_weight = b.left_metrics.weight();
|
|
983
|
-
if (target_weight < current_weight + left_weight) {
|
|
984
|
-
return self.findByWeightInNode(b.left, target_weight, current_weight);
|
|
985
|
-
}
|
|
986
|
-
return self.findByWeightInNode(b.right, target_weight, current_weight + left_weight);
|
|
987
|
-
},
|
|
988
|
-
.leaf => |*l| {
|
|
989
|
-
const leaf_weight = node.metrics().weight();
|
|
990
|
-
if (target_weight < current_weight + leaf_weight) {
|
|
991
|
-
return .{ .leaf = &l.data, .start_weight = current_weight };
|
|
992
|
-
}
|
|
993
|
-
return null;
|
|
994
|
-
},
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
/// Undo/Redo operations
|
|
999
|
-
pub fn store_undo(self: *Self, meta: []const u8) !void {
|
|
1000
|
-
const undo_node = try self.create_undo_node(self.root, meta);
|
|
1001
|
-
self.push_undo(undo_node);
|
|
1002
|
-
self.curr_history = null;
|
|
1003
|
-
try self.push_redo_branch();
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
fn create_undo_node(self: *const Self, root: *const Node, meta_: []const u8) !*UndoNode {
|
|
1007
|
-
const undo_node = try self.allocator.create(UndoNode);
|
|
1008
|
-
const meta = try self.allocator.dupe(u8, meta_);
|
|
1009
|
-
undo_node.* = UndoNode{
|
|
1010
|
-
.root = root,
|
|
1011
|
-
.meta = meta,
|
|
1012
|
-
};
|
|
1013
|
-
return undo_node;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
fn push_undo(self: *Self, undo_node: *UndoNode) void {
|
|
1017
|
-
const next = self.undo_history;
|
|
1018
|
-
self.undo_history = undo_node;
|
|
1019
|
-
undo_node.next = next;
|
|
1020
|
-
self.undo_depth += 1;
|
|
1021
|
-
|
|
1022
|
-
// Trim history if we exceed max_undo_depth
|
|
1023
|
-
if (self.config.max_undo_depth) |max_depth| {
|
|
1024
|
-
if (self.undo_depth > max_depth) {
|
|
1025
|
-
self.trimUndoHistory(max_depth);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
fn trimUndoHistory(self: *Self, max_depth: usize) void {
|
|
1031
|
-
var current = self.undo_history;
|
|
1032
|
-
var depth_count: usize = 0;
|
|
1033
|
-
var prev: ?*UndoNode = null;
|
|
1034
|
-
|
|
1035
|
-
while (current) |node| {
|
|
1036
|
-
depth_count += 1;
|
|
1037
|
-
if (depth_count >= max_depth) {
|
|
1038
|
-
// Cut off the rest of the history
|
|
1039
|
-
if (prev) |p| {
|
|
1040
|
-
p.next = null;
|
|
1041
|
-
}
|
|
1042
|
-
self.undo_depth = max_depth;
|
|
1043
|
-
return;
|
|
1044
|
-
}
|
|
1045
|
-
prev = node;
|
|
1046
|
-
current = node.next;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
fn push_redo(self: *Self, undo_node: *UndoNode) void {
|
|
1051
|
-
const next = self.redo_history;
|
|
1052
|
-
self.redo_history = undo_node;
|
|
1053
|
-
undo_node.next = next;
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
fn push_redo_branch(self: *Self) !void {
|
|
1057
|
-
const r = self.redo_history orelse return;
|
|
1058
|
-
const u = self.undo_history orelse return;
|
|
1059
|
-
const next = u.branches;
|
|
1060
|
-
const b = try self.allocator.create(UndoBranch);
|
|
1061
|
-
b.* = .{
|
|
1062
|
-
.redo = r,
|
|
1063
|
-
.next = next,
|
|
1064
|
-
};
|
|
1065
|
-
u.branches = b;
|
|
1066
|
-
self.redo_history = null;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
pub fn undo(self: *Self, meta: []const u8) ![]const u8 {
|
|
1070
|
-
const r = self.curr_history orelse try self.create_undo_node(self.root, meta);
|
|
1071
|
-
const h = self.undo_history orelse return error.Stop;
|
|
1072
|
-
self.undo_history = h.next;
|
|
1073
|
-
self.curr_history = h;
|
|
1074
|
-
self.root = h.root;
|
|
1075
|
-
self.version += 1;
|
|
1076
|
-
self.push_redo(r);
|
|
1077
|
-
if (self.undo_depth > 0) self.undo_depth -= 1;
|
|
1078
|
-
return h.meta;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
pub fn redo(self: *Self) ![]const u8 {
|
|
1082
|
-
const u = self.curr_history orelse return error.Stop;
|
|
1083
|
-
const h = self.redo_history orelse return error.Stop;
|
|
1084
|
-
if (u.root != self.root) return error.Stop;
|
|
1085
|
-
self.redo_history = h.next;
|
|
1086
|
-
self.curr_history = h;
|
|
1087
|
-
self.root = h.root;
|
|
1088
|
-
self.version += 1;
|
|
1089
|
-
self.push_undo(u);
|
|
1090
|
-
return h.meta;
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
pub fn can_undo(self: *const Self) bool {
|
|
1094
|
-
return self.undo_history != null;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
pub fn can_redo(self: *const Self) bool {
|
|
1098
|
-
return self.redo_history != null and self.curr_history != null;
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
pub fn clear_history(self: *Self) void {
|
|
1102
|
-
self.undo_history = null;
|
|
1103
|
-
self.redo_history = null;
|
|
1104
|
-
self.curr_history = null;
|
|
1105
|
-
self.undo_depth = 0;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
pub fn clear(self: *Self) void {
|
|
1109
|
-
self.root = self.empty_leaf;
|
|
1110
|
-
self.version += 1;
|
|
1111
|
-
self.applyEndsInvariant() catch {};
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
/// Replace the rope content with new items, using same structure as from_slice
|
|
1115
|
-
/// This is useful for repeated setText operations without creating a new rope instance
|
|
1116
|
-
pub fn setSegments(self: *Self, items: []const T) !void {
|
|
1117
|
-
if (items.len == 0) {
|
|
1118
|
-
self.root = self.empty_leaf;
|
|
1119
|
-
self.version += 1;
|
|
1120
|
-
try self.applyEndsInvariant();
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
var leaves: std.ArrayListUnmanaged(*const Node) = .{};
|
|
1125
|
-
defer leaves.deinit(self.allocator);
|
|
1126
|
-
try leaves.ensureTotalCapacity(self.allocator, items.len);
|
|
1127
|
-
|
|
1128
|
-
for (items) |item| {
|
|
1129
|
-
const leaf = try Node.new_leaf(self.allocator, item);
|
|
1130
|
-
try leaves.append(self.allocator, leaf);
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
self.root = try Node.merge_leaves(leaves.items, self.allocator);
|
|
1134
|
-
self.version += 1;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
fn rebuildMarkerCache(self: *Self) !void {
|
|
1138
|
-
if (!marker_enabled) return;
|
|
1139
|
-
|
|
1140
|
-
self.marker_cache.clear();
|
|
1141
|
-
|
|
1142
|
-
const RebuildContext = struct {
|
|
1143
|
-
cache: *MarkerCache,
|
|
1144
|
-
current_leaf: u32 = 0,
|
|
1145
|
-
current_weight: u32 = 0,
|
|
1146
|
-
|
|
1147
|
-
fn walker(ctx: *anyopaque, data: *const T, idx: u32) Node.WalkerResult {
|
|
1148
|
-
_ = idx;
|
|
1149
|
-
const context = @as(*@This(), @ptrCast(@alignCast(ctx)));
|
|
1150
|
-
|
|
1151
|
-
const tag = std.meta.activeTag(data.*);
|
|
1152
|
-
|
|
1153
|
-
var is_marker = false;
|
|
1154
|
-
inline for (T.MarkerTypes) |mt| {
|
|
1155
|
-
if (tag == mt) {
|
|
1156
|
-
is_marker = true;
|
|
1157
|
-
break;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
const leaf_weight = if (@hasDecl(T, "Metrics")) blk: {
|
|
1162
|
-
if (@hasDecl(T, "measure")) {
|
|
1163
|
-
const metrics = data.measure();
|
|
1164
|
-
break :blk if (@hasDecl(T.Metrics, "weight")) metrics.weight() else 1;
|
|
1165
|
-
}
|
|
1166
|
-
break :blk 1;
|
|
1167
|
-
} else 1;
|
|
1168
|
-
|
|
1169
|
-
if (is_marker) {
|
|
1170
|
-
const gop = context.cache.positions.getOrPut(tag) catch |e| {
|
|
1171
|
-
return .{ .keep_walking = false, .err = e };
|
|
1172
|
-
};
|
|
1173
|
-
if (!gop.found_existing) {
|
|
1174
|
-
gop.value_ptr.* = .{};
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
gop.value_ptr.append(context.cache.allocator, .{
|
|
1178
|
-
.leaf_index = context.current_leaf,
|
|
1179
|
-
.global_weight = context.current_weight,
|
|
1180
|
-
}) catch |e| {
|
|
1181
|
-
return .{ .keep_walking = false, .err = e };
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
context.current_leaf += 1;
|
|
1186
|
-
context.current_weight += leaf_weight;
|
|
1187
|
-
return .{};
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
|
|
1191
|
-
var ctx = RebuildContext{ .cache = &self.marker_cache };
|
|
1192
|
-
try self.walk(&ctx, RebuildContext.walker);
|
|
1193
|
-
|
|
1194
|
-
self.marker_cache.version = self.version;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
pub fn markerCount(self: *Self, tag: std.meta.Tag(T)) u32 {
|
|
1198
|
-
if (!marker_enabled) return 0;
|
|
1199
|
-
|
|
1200
|
-
if (self.marker_cache.version != self.version) {
|
|
1201
|
-
self.rebuildMarkerCache() catch return 0;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
const list = self.marker_cache.positions.get(tag) orelse return 0;
|
|
1205
|
-
return @intCast(list.items.len);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
pub fn getMarker(self: *Self, tag: std.meta.Tag(T), occurrence: u32) ?MarkerPosition {
|
|
1209
|
-
if (!marker_enabled) return null;
|
|
1210
|
-
|
|
1211
|
-
if (self.marker_cache.version != self.version) {
|
|
1212
|
-
self.rebuildMarkerCache() catch return null;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
const list = self.marker_cache.positions.get(tag) orelse return null;
|
|
1216
|
-
if (occurrence >= list.items.len) return null;
|
|
1217
|
-
return list.items[occurrence];
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
}
|