From fb8296c1a91df0ae56fb9ccf05eed76dc1ea7afe Mon Sep 17 00:00:00 2001
From: Meow Honk <21010072+catgoose@users.noreply.github.com>
Date: Sun, 12 Jan 2025 21:11:23 -0600
Subject: [PATCH] Perf: Trie implementation is space efficient (#131)
* ref(utils): renames byte_is_valid_colorchar to byte_is_valid_color_char
* test: adds test cases for nonalphanumeric custom_names including spaces
* fix(util): do not add spaces as an additional color character for checking valid color chars
* chore: adds error message if trie returns length but not rgb_hex
* doc: updates readme and ldoc
* ref(trie): dynamically build char_lookup based on inserted words, removes need for adding additional characters manually
* ref(tailwind_names): tailwind names uses same trie as names
* fix: removes reference to tailwind_names module
* feat: Trie dynamically allocates memory for each node and resizes capacity when needed.
Starts with an initial capacity of 8
* chore: removes old ldoc html file
* doc: let ldoc decide which markdown parser to use
* test: creates start_minimal-trie.sh script to run trie tests
* test: creates makefile for executing testing targets
* chore: creates trie benchmarks for different initial capacity settings
---
Makefile | 35 ++
README.md | 135 ++++++--
doc/colorizer.txt | 87 ++---
doc/index.html | 11 +-
doc/modules/colorizer.buffer.html | 3 +-
doc/modules/colorizer.color.html | 3 +-
doc/modules/colorizer.config.html | 11 +-
doc/modules/colorizer.constants.html | 3 +-
doc/modules/colorizer.html | 3 +-
doc/modules/colorizer.matcher.html | 3 +-
doc/modules/colorizer.parser.hsl.html | 3 +-
doc/modules/colorizer.parser.names.html | 30 +-
doc/modules/colorizer.parser.rgb.html | 3 +-
doc/modules/colorizer.parser.rgb_hex.html | 3 +-
doc/modules/colorizer.parser.rgba_hex.html | 3 +-
.../colorizer.parser.tailwind_names.html | 2 +-
doc/modules/colorizer.sass.html | 3 +-
doc/modules/colorizer.tailwind.html | 17 +-
doc/modules/colorizer.trie.html | 11 +-
doc/modules/colorizer.usercmds.html | 3 +-
doc/modules/colorizer.utils.html | 19 +-
doc/modules/trie.html | 34 +-
doc/modules/utils.html | 326 ------------------
lua/colorizer.lua | 1 -
lua/colorizer/buffer.lua | 26 +-
lua/colorizer/config.lua | 6 +-
lua/colorizer/matcher.lua | 24 +-
lua/colorizer/parser/names.lua | 95 +++--
lua/colorizer/parser/tailwind_names.lua | 91 -----
lua/colorizer/tailwind.lua | 6 +-
lua/colorizer/trie.lua | 288 +++++++++-------
lua/colorizer/utils.lua | 36 +-
scripts/gen_docs.sh | 2 +-
scripts/minimal-colorizer.sh | 4 +
scripts/start_minimal.sh | 4 -
scripts/trie-benchmark.sh | 10 +
scripts/trie-test.sh | 11 +
test/.gitignore | 1 +
test/expect.lua | 43 ++-
test/{minimal.lua => minimal-colorizer.lua} | 5 +-
test/print-trie.lua | 59 ----
test/trie/benchmark.lua | 146 ++++++++
test/trie/minimal.lua | 65 ++++
test/trie/test.lua | 61 ++++
test/trie/trie-benchmark.txt | 43 +++
test/trie/trie-test.txt | 34 ++
46 files changed, 945 insertions(+), 867 deletions(-)
create mode 100644 Makefile
delete mode 100644 doc/modules/utils.html
delete mode 100644 lua/colorizer/parser/tailwind_names.lua
create mode 100755 scripts/minimal-colorizer.sh
delete mode 100755 scripts/start_minimal.sh
create mode 100755 scripts/trie-benchmark.sh
create mode 100755 scripts/trie-test.sh
rename test/{minimal.lua => minimal-colorizer.lua} (95%)
delete mode 100644 test/print-trie.lua
create mode 100644 test/trie/benchmark.lua
create mode 100644 test/trie/minimal.lua
create mode 100644 test/trie/test.lua
create mode 100644 test/trie/trie-benchmark.txt
create mode 100644 test/trie/trie-test.txt
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0da0129
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,35 @@
+# Define variables for script paths
+SCRIPTS_DIR=scripts
+TRIE_TEST_SCRIPT=$(SCRIPTS_DIR)/trie-test.sh
+TRIE_BENCHMARK_SCRIPT=$(SCRIPTS_DIR)/trie-benchmark.sh
+MINIMAL_SCRIPT=$(SCRIPTS_DIR)/minimal-colorizer.sh
+
+help:
+ @echo "Available targets:"
+ @echo " make trie - Run trie test and benchmark"
+ @echo " make trie-test - Run trie test"
+ @echo " make trie-benchmark - Run trie benchmark"
+ @echo " make minimal - Run the minimal script"
+ @echo " make clean - Remove test/colorizer_*"
+
+trie: trie-test trie-benchmark
+
+trie-test:
+ @echo "Running trie test..."
+ @bash $(TRIE_TEST_SCRIPT)
+
+trie-benchmark:
+ @echo "Running trie benchmark..."
+ @bash $(TRIE_BENCHMARK_SCRIPT)
+
+minimal:
+ @echo "Running minimal config..."
+ @bash $(MINIMAL_SCRIPT)
+
+clean:
+ @echo "Removing test/colorizer_repro"
+ @rm -rf test/colorizer_repro
+ @echo "Removing test/trie/colorizer_trie"
+ @rm -rf test/trie/colorizer_trie
+
+.PHONY: help trie trie-test trie-benchmark minimal clean
diff --git a/README.md b/README.md
index d856d91..e77e1bb 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,11 @@
- [Lazyload Colorizer with Lazy.nvim](#lazyload-colorizer-with-lazynvim)
- [Tailwind](#tailwind)
- [Testing](#testing)
+ - [Minimal Colorizer](#minimal-colorizer)
+ - [Trie](#trie)
+ - [Test](#test)
+ - [Benchmark](#benchmark)
+ - [Results](#results)
- [Extras](#extras)
- [TODO](#todo)
@@ -114,10 +119,8 @@ library to do custom highlighting themselves.
```lua
require("colorizer").setup({
- -- Filetype options. Accepts table like `user_default_options`
- filetypes = { "*" },
- -- Buftype options. Accepts table like `user_default_options`
- buftypes = {},
+ filetypes = { "*" }, -- Filetype options. Accepts table like `user_default_options`
+ buftypes = {}, -- Buftype options. Accepts table like `user_default_options`
-- Boolean | List of usercommands to enable. See User commands section.
user_commands = true, -- Enable all or some usercommands
lazy_load = false, -- Lazily schedule buffer highlighting setup function
@@ -144,19 +147,18 @@ library to do custom highlighting themselves.
css = false, -- Enable all CSS *features*:
-- names, RGB, RGBA, RRGGBB, RRGGBBAA, AARRGGBB, rgb_fn, hsl_fn
css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn
- -- Highlighting mode. 'background'|'foreground'|'virtualtext'
- mode = "background", -- Set the display mode
- -- Tailwind colors. boolean|'normal'|'lsp'|'both'. True is same as normal
+ -- Tailwind colors. boolean|'normal'|'lsp'|'both'. True sets to 'normal'
tailwind = false, -- Enable tailwind colors
tailwind_opts = { -- Options for highlighting tailwind names
- update_names = false, -- When using tailwind = 'both', update tailwind
- -- names from LSP results. See tailwind section
+ update_names = false, -- When using tailwind = 'both', update tailwind names from LSP results. See tailwind section
},
-- parsers can contain values used in `user_default_options`
sass = { enable = false, parsers = { "css" } }, -- Enable sass colors
+ -- Highlighting mode. 'background'|'foreground'|'virtualtext'
+ mode = "background", -- Set the display mode
-- Virtualtext character to use
virtualtext = "■",
- -- Display virtualtext inline with color
+ -- Display virtualtext inline with color. boolean|'before'|'after'. True sets to 'after'
virtualtext_inline = false,
-- Virtualtext highlight mode: 'background'|'foreground'
virtualtext_mode = "foreground",
@@ -167,14 +169,6 @@ library to do custom highlighting themselves.
})
```
-Highlighting modes:
-
-- `background`: sets the background text color.
-- `foreground`: sets the foreground text color.
-- `virtualtext`: indicate the color behind the virtualtext.
-
-Virtualtext symbol can be displayed at end of line, or
-
Setup examples:
```lua
@@ -379,13 +373,21 @@ are cached and returned on `WinScrolled` event.
## Testing
-For troubleshooting use `test/minimal.lua`.
-Startup neovim with `nvim --clean -u minimal.lua` in the `test` directory.
+### Minimal Colorizer
-Alternatively, use the following script from root directory:
+For troubleshooting use `test/minimal-colorizer.lua`.
+Startup neovim with `nvim --clean -u minimal-colorizer.lua` in the `test` directory.
+
+Alternatively,
```bash
-scripts/start_minimal.sh
+make minimal
+```
+
+or
+
+```bash
+scripts/minimal-colorizer.sh
```
To test colorization with your config, edit `test/expect.lua` to see expected
@@ -393,6 +395,94 @@ highlights.
The returned table of `user_default_options` from `text/expect.lua` will be used
to conveniently reattach Colorizer to `test/expect.lua` on save.
+### Trie
+
+Colorizer uses a space efficient LuaJIT Trie implementation, which starts with
+an initial node capacity of 8 bytes and expands capacity per node when needed.
+
+The trie can be tested and benchmarked using `test/trie/test.lua` and
+`test/trie/benchmark.lua` respectively.
+
+#### Test
+
+```bash
+# runs both trie-test and trie-benchmark targets
+make trie
+```
+
+```bash
+# runs trie test which inserts words and checks longest prefix
+make trie-test
+```
+
+#### Benchmark
+
+```bash
+scripts/trie-test.sh
+```
+
+```bash
+# runs benchmark for different node initial capacity allocation
+make trie-benchmark
+```
+
+```bash
+scripts/trie-benchmark.sh
+```
+
+##### Results
+
+Inserting 7245 words: using uppercase, lowercase, camelcase from `vim.api.nvim_get_color_map()` and Tailwind colors
+
+| Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
+| ---------------- | ------------ | ---------------- | ---------------- |
+| 1 | 3652 | 25 | 16 |
+| 2 | 2056 | 11 | 8 |
+| 4 | 1174 | 6 | 5 |
+| 8 | 576 | 7 | 5 |
+| 16 | 23 | 7 | 5 |
+| 32 | 1 | 8 | 6 |
+| 64 | 0 | 10 | 7 |
+
+Inserting 1000 randomized words
+
+| Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
+| ---------------- | ------------ | ---------------- | ---------------- |
+| 1 | 434 | 1 | 0 |
+| 2 | 234 | 1 | 1 |
+| 4 | 129 | 1 | 0 |
+| 8 | 51 | 1 | 0 |
+| 16 | 17 | 1 | 1 |
+| 32 | 3 | 1 | 2 |
+| 64 | 1 | 2 | 1 |
+| 128 | 0 | 4 | 1 |
+
+Inserting 10,000 randomized words
+
+| Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
+| ---------------- | ------------ | ---------------- | ---------------- |
+| 1 | 4614 | 9 | 7 |
+| 2 | 2106 | 8 | 8 |
+| 4 | 842 | 9 | 7 |
+| 8 | 362 | 9 | 8 |
+| 16 | 208 | 11 | 9 |
+| 32 | 113 | 14 | 11 |
+| 64 | 24 | 21 | 14 |
+| 128 | 0 | 34 | 25 |
+
+Inserting 100,000 randomized words
+
+| Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
+| ---------------- | ------------ | ---------------- | ---------------- |
+| 1 | 40656 | 160 | 117 |
+| 2 | 21367 | 116 | 111 |
+| 4 | 11604 | 122 | 109 |
+| 8 | 5549 | 133 | 113 |
+| 16 | 1954 | 141 | 138 |
+| 32 | 499 | 173 | 158 |
+| 64 | 100 | 233 | 173 |
+| 128 | 0 | 343 | 198 |
+
## Extras
Documentation is generated using ldoc. See
@@ -402,6 +492,5 @@ Documentation is generated using ldoc. See
- [ ] Add more color types ( var, advanced css functions )
- [ ] Add more display modes. E.g - sign column
-- [ ] Use a more space efficient trie implementation.
- [ ] Support custom parsers
- [ ] Options support providing function to enable/disable instead of just boolean
diff --git a/doc/colorizer.txt b/doc/colorizer.txt
index ff8c283..6c414f0 100644
--- a/doc/colorizer.txt
+++ b/doc/colorizer.txt
@@ -553,11 +553,11 @@ user_default_options *colorizer.config.user_default_options*
{css} - boolean: Enables all CSS features (`rgb_fn`, `hsl_fn`, `names`,
`RGB`, `RRGGBB`).
{css_fn} - boolean: Enables all CSS functions (`rgb_fn`, `hsl_fn`).
- {mode} - 'background'|'foreground'|'virtualtext': Display mode
{tailwind} - boolean|string: Enables Tailwind CSS colors (e.g.,
`"normal"`, `"lsp"`, `"both"`).
{tailwind_opts} - table: Tailwind options for updating names cache, etc
{sass} - table: Sass color configuration (`enable` flag and `parsers`).
+ {mode} - 'background'|'foreground'|'virtualtext': Display mode
{virtualtext} - string: Character used for virtual text display.
{virtualtext_inline} - boolean|'before'|'after': Shows virtual text
inline with color.
@@ -611,8 +611,6 @@ opts *colorizer.config.opts*
`RRGGBB`, `hsl_fn`, `rgb_fn`).
- `css_fn` (boolean): Enables all CSS function-related features (e.g.,
`rgb_fn`, `hsl_fn`).
- - `mode` (string): Determines the display mode for highlights. Options are
- `"background"`, `"foreground"`, and `"virtualtext"`.
- `tailwind` (boolean|string): Enables Tailwind CSS colors. Accepts `true`,
`"normal"`, `"lsp"`, or `"both"`.
- `tailwind_opts` (table): Tailwind options for updating names cache, etc
@@ -623,6 +621,8 @@ opts *colorizer.config.opts*
- `sass` (table): Configures Sass color support.
- `enable` (boolean): Enables Sass color parsing.
- `parsers` (table): A list of parsers to use, typically includes `"css"`.
+ - `mode` (string): Determines the display mode for highlights. Options are
+ `"background"`, `"foreground"`, and `"virtualtext"`.
- `virtualtext` (string): Character used for virtual text display of colors
(default is `"■"`).
- `virtualtext_inline` (boolean|'before'|'after'): Shows the virtual text
@@ -825,6 +825,8 @@ LUA API *colorizer.parser.names-lua-api*
Functions: ~
|reset_cache| - Reset the color names cache.
+ |update_color| - Updates the color value for a given color name.
+
|parser| - Parses a line to identify color names.
@@ -836,6 +838,15 @@ reset_cache() *colorizer.parser.names.reset_cache*
+update_color({name}, {hex}) *colorizer.parser.names.update_color*
+ Updates the color value for a given color name.
+
+ Parameters: ~
+ {name} - string: The color name.
+ {hex} - string: The color value in hex format.
+
+
+
parser({line}, {i}, {opts}) *colorizer.parser.names.parser*
Parses a line to identify color names.
@@ -981,44 +992,6 @@ parser({line}, {i}, {opts}) *colorizer.parser.rgb.parser*
-==============================================================================
-TAILWIND_NAMES *colorizer.parser.tailwind_names-introduction*
-
-This module provides a parser that identifies named colors from a given line of
-text.
-
- The module uses a Trie structure for efficient matching of color names to
- #rrggbb values
-
-==============================================================================
-LUA API *colorizer.parser.tailwind_names-lua-api*
-
-Functions: ~
- |reset_cache| - Reset the color names cache.
-
- |parser| - Parses a line to identify color names.
-
-
-reset_cache() *colorizer.parser.tailwind_names.reset_cache*
- Reset the color names cache.
-
- Called from colorizer.setup
-
-
-
-
-parser({line}, {i}) *colorizer.parser.tailwind_names.parser*
- Parses a line to identify color names.
-
- Parameters: ~
- {line} - string: The text line to parse.
- {i} - number: The index to start parsing from.
-
- returns:~
- number or nil, string or nil: Length of match and hex value if found.
-
-
-
==============================================================================
SASS *colorizer.sass-introduction*
@@ -1118,34 +1091,23 @@ cleanup({bufnr}) *colorizer.tailwind.cleanup*
*colorizer.tailwind.lsp_highlight*
lsp_highlight({bufnr}, {ud_opts}, {buf_local_opts}, {add_highlight},
-{on_detach})
+{on_detach}, {line_start}, {line_end})
Highlight buffer using values returned by tailwindcss
Parameters: ~
{bufnr} - number: Buffer number (0 for current)
{ud_opts} - table: `user_default_options`
{buf_local_opts} - table: Buffer local options
- {add_highlight} - function
- {on_detach} - function
+ {add_highlight} - function: Function to add highlights
+ {on_detach} - function: Function to call when LSP is detached
+ {line_start} - number: Start line
+ {line_end} - number: End line
returns:~
boolean or nil
-==============================================================================
-TRIE *colorizer.trie-introduction*
-
-Trie implementation in luajit.
-
- This module provides a Trie data structure implemented in LuaJIT with efficient
- memory handling.
- It supports operations such as inserting, searching, finding the longest
- prefix, and converting the Trie into a table format.
- The implementation uses LuaJIT's Foreign Function Interface (FFI) for optimized
- memory allocation.
-
-
==============================================================================
USERCMDS *colorizer.usercmds-introduction*
@@ -1206,7 +1168,7 @@ Functions: ~
|add_additional_color_chars| - Adds additional characters to the list of
valid color characters.
- |byte_is_valid_colorchar| - Checks if a byte is valid as a color character
+ |byte_is_valid_color_char| - Checks if a byte is valid as a color character
(alphanumeric, dynamically added chars, or hardcoded characters).
|count| - Count the number of character in a string
@@ -1265,13 +1227,10 @@ get_non_alphanum_keys({tbl}) *colorizer.utils.get_non_alphanum_keys*
-
- *colorizer.utils.add_additional_color_chars*
-add_additional_color_chars({key}, {chars})
+add_additional_color_chars({chars}) *colorizer.utils.add_additional_color_chars*
Adds additional characters to the list of valid color characters.
Parameters: ~
- {key} - string: The key to associate with the additional characters.
{chars} - string: The additional characters to add.
returns:~
@@ -1279,14 +1238,12 @@ add_additional_color_chars({key}, {chars})
-byte_is_valid_colorchar({byte}, {key}) *colorizer.utils.byte_is_valid_colorchar*
+byte_is_valid_color_char({byte}) *colorizer.utils.byte_is_valid_color_char*
Checks if a byte is valid as a color character (alphanumeric, dynamically
added chars, or hardcoded characters).
Parameters: ~
{byte} - number: The byte to check.
- {key} - string|nil: The key for additional characters to validate
- against.
returns:~
boolean: `true` if the byte is valid, otherwise `false`.
diff --git a/doc/index.html b/doc/index.html
index 7692df0..4b5e2a8 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -43,10 +43,9 @@
Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
@@ -103,10 +102,6 @@ Modules
colorizer.parser.rgba_hex |
This module provides a parser for identifying and converting `#RRGGBBAA` hexadecimal color values to RGB hexadecimal format. |
-
- colorizer.parser.tailwind_names |
- This module provides a parser that identifies named colors from a given line of text. |
-
colorizer.sass |
Manages Sass variable parsing and color detection for buffers. |
@@ -116,8 +111,8 @@ Modules
Handles Tailwind CSS color highlighting within buffers. |
- colorizer.trie |
- Trie implementation in luajit. |
+ trie |
+ Trie implementation in LuaJIT. |
colorizer.usercmds |
diff --git a/doc/modules/colorizer.buffer.html b/doc/modules/colorizer.buffer.html
index 0ffb1e7..3939a1f 100644
--- a/doc/modules/colorizer.buffer.html
+++ b/doc/modules/colorizer.buffer.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.color.html b/doc/modules/colorizer.color.html
index 097894c..8d29323 100644
--- a/doc/modules/colorizer.color.html
+++ b/doc/modules/colorizer.color.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.config.html b/doc/modules/colorizer.config.html
index 45bb535..5a60eb5 100644
--- a/doc/modules/colorizer.config.html
+++ b/doc/modules/colorizer.config.html
@@ -51,10 +51,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
@@ -325,9 +324,6 @@ Fields:
css_fn
boolean: Enables all CSS functions (`rgb_fn`, `hsl_fn`).
- mode
- 'background'|'foreground'|'virtualtext': Display mode
-
tailwind
boolean|string: Enables Tailwind CSS colors (e.g., `"normal"`, `"lsp"`, `"both"`).
@@ -337,6 +333,9 @@ Fields:
sass
table: Sass color configuration (`enable` flag and `parsers`).
+ mode
+ 'background'|'foreground'|'virtualtext': Display mode
+
virtualtext
string: Character used for virtual text display.
@@ -425,13 +424,13 @@ Fields:
- `hsl_fn` (boolean): Enables CSS `hsl()` and `hsla()` functions.
- `css` (boolean): Enables all CSS-related features (e.g., `names`, `RGB`, `RRGGBB`, `hsl_fn`, `rgb_fn`).
- `css_fn` (boolean): Enables all CSS function-related features (e.g., `rgb_fn`, `hsl_fn`).
- - `mode` (string): Determines the display mode for highlights. Options are `"background"`, `"foreground"`, and `"virtualtext"`.
- `tailwind` (boolean|string): Enables Tailwind CSS colors. Accepts `true`, `"normal"`, `"lsp"`, or `"both"`.
- `tailwind_opts` (table): Tailwind options for updating names cache, etc
- `update_names` (boolean): Updates Tailwind "normal" names cache from LSP results. This provides a smoother highlighting experience when tailwind = "both" is used. Highlighting on non-tailwind lsp buffers (like cmp) becomes more consistent.
- `sass` (table): Configures Sass color support.
- `enable` (boolean): Enables Sass color parsing.
- `parsers` (table): A list of parsers to use, typically includes `"css"`.
+ - `mode` (string): Determines the display mode for highlights. Options are `"background"`, `"foreground"`, and `"virtualtext"`.
- `virtualtext` (string): Character used for virtual text display of colors (default is `"■"`).
- `virtualtext_inline` (boolean|'before'|'after'): Shows the virtual text inline with the color. True defaults to 'before'. False or nil disables.
- `virtualtext_mode` ('background'|'foreground'): Determines the display mode for virtual text.
diff --git a/doc/modules/colorizer.constants.html b/doc/modules/colorizer.constants.html
index 994f54a..445c711 100644
--- a/doc/modules/colorizer.constants.html
+++ b/doc/modules/colorizer.constants.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.html b/doc/modules/colorizer.html
index fd74b8f..2ed9bc5 100644
--- a/doc/modules/colorizer.html
+++ b/doc/modules/colorizer.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.matcher.html b/doc/modules/colorizer.matcher.html
index 7482d8d..56c34ef 100644
--- a/doc/modules/colorizer.matcher.html
+++ b/doc/modules/colorizer.matcher.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.parser.hsl.html b/doc/modules/colorizer.parser.hsl.html
index 2eefac9..472e0cd 100644
--- a/doc/modules/colorizer.parser.hsl.html
+++ b/doc/modules/colorizer.parser.hsl.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.parser.names.html b/doc/modules/colorizer.parser.names.html
index f005c18..f02bf9b 100644
--- a/doc/modules/colorizer.parser.names.html
+++ b/doc/modules/colorizer.parser.names.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
@@ -75,6 +74,10 @@
Reset the color names cache. |
+ update_color (name, hex) |
+ Updates the color value for a given color name. |
+
+
parser (line, i, opts) |
Parses a line to identify color names. |
@@ -101,6 +104,29 @@
+
+
+
+ update_color (name, hex)
+
+
+ Updates the color value for a given color name.
+
+
+ Parameters:
+
+ - name
+ string: The color name.
+
+ - hex
+ string: The color value in hex format.
+
+
+
+
+
+
+
diff --git a/doc/modules/colorizer.parser.rgb.html b/doc/modules/colorizer.parser.rgb.html
index 3ab2e5d..caf4f6f 100644
--- a/doc/modules/colorizer.parser.rgb.html
+++ b/doc/modules/colorizer.parser.rgb.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.parser.rgb_hex.html b/doc/modules/colorizer.parser.rgb_hex.html
index 5b964ef..f363d21 100644
--- a/doc/modules/colorizer.parser.rgb_hex.html
+++ b/doc/modules/colorizer.parser.rgb_hex.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.parser.rgba_hex.html b/doc/modules/colorizer.parser.rgba_hex.html
index b802d39..7340910 100644
--- a/doc/modules/colorizer.parser.rgba_hex.html
+++ b/doc/modules/colorizer.parser.rgba_hex.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.parser.tailwind_names.html b/doc/modules/colorizer.parser.tailwind_names.html
index 39a6e49..ff49476 100644
--- a/doc/modules/colorizer.parser.tailwind_names.html
+++ b/doc/modules/colorizer.parser.tailwind_names.html
@@ -53,7 +53,7 @@ Modules
parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.sass.html b/doc/modules/colorizer.sass.html
index cd32f0f..b900abc 100644
--- a/doc/modules/colorizer.sass.html
+++ b/doc/modules/colorizer.sass.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.tailwind.html b/doc/modules/colorizer.tailwind.html
index f8a25ea..c2962ff 100644
--- a/doc/modules/colorizer.tailwind.html
+++ b/doc/modules/colorizer.tailwind.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
@@ -77,7 +76,7 @@
Cleanup tailwind variables and autocmd |
- lsp_highlight (bufnr, ud_opts, buf_local_opts, add_highlight, on_detach) |
+ lsp_highlight (bufnr, ud_opts, buf_local_opts, add_highlight, on_detach, line_start, line_end) |
Highlight buffer using values returned by tailwindcss |
@@ -111,7 +110,7 @@ Parameters:
- lsp_highlight (bufnr, ud_opts, buf_local_opts, add_highlight, on_detach)
+ lsp_highlight (bufnr, ud_opts, buf_local_opts, add_highlight, on_detach, line_start, line_end)
Highlight buffer using values returned by tailwindcss
@@ -129,10 +128,16 @@ Parameters:
table: Buffer local options
add_highlight
- function
+ function: Function to add highlights
on_detach
- function
+ function: Function to call when LSP is detached
+
+ line_start
+ number: Start line
+
+ line_end
+ number: End line
diff --git a/doc/modules/colorizer.trie.html b/doc/modules/colorizer.trie.html
index 7fd896f..1302763 100644
--- a/doc/modules/colorizer.trie.html
+++ b/doc/modules/colorizer.trie.html
@@ -63,7 +63,16 @@ Module colorizer.trie
This module provides a Trie data structure implemented in LuaJIT with efficient memory handling.
It supports operations such as inserting, searching, finding the longest prefix, and converting the Trie into a table format.
- The implementation uses LuaJIT's Foreign Function Interface (FFI) for optimized memory allocation.
+ The implementation uses LuaJIT's Foreign Function Interface (FFI) for optimized memory allocation.
+ Dynamic Allocation:
+ - The `character` array in each Trie node is dynamically allocated using a double pointer (`struct Trie**`).
+ - Each Trie node contains:
+ - A `bool is_leaf` field to indicate whether the node represents the end of a string.
+ - A `struct Trie** character` pointer that references the dynamically allocated array.
+ - Memory for the `character` array is allocated only when the node is created.
+ - The `character` array can support up to 256 child nodes, corresponding to ASCII values.
+ - Each slot in the array is initialized to `NULL` and represents a potential child node.
+ - Memory for each node and its `character` array is allocated using `ffi.C.malloc` and freed recursively using `ffi.C.free`.
diff --git a/doc/modules/colorizer.usercmds.html b/doc/modules/colorizer.usercmds.html
index 5953cc8..72de190 100644
--- a/doc/modules/colorizer.usercmds.html
+++ b/doc/modules/colorizer.usercmds.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
diff --git a/doc/modules/colorizer.utils.html b/doc/modules/colorizer.utils.html
index 5c56a18..b45d8b8 100644
--- a/doc/modules/colorizer.utils.html
+++ b/doc/modules/colorizer.utils.html
@@ -50,10 +50,9 @@ Modules
parser.names
parser.rgb
parser.rgba_hex
- parser.tailwind_names
sass
tailwind
- trie
+ trie
usercmds
utils
@@ -88,11 +87,11 @@
Extract non-alphanumeric characters to add as a valid index in the Trie |
- add_additional_color_chars (key, chars) |
+ add_additional_color_chars (chars) |
Adds additional characters to the list of valid color characters. |
- byte_is_valid_colorchar (byte, key) |
+ byte_is_valid_color_char (byte) |
Checks if a byte is valid as a color character (alphanumeric, dynamically added chars, or hardcoded characters). |
@@ -231,7 +230,7 @@ Returns:
- add_additional_color_chars (key, chars)
+ add_additional_color_chars (chars)
Adds additional characters to the list of valid color characters.
@@ -239,9 +238,6 @@ Returns:
Parameters:
- - key
- string: The key to associate with the additional characters.
-
- chars
string: The additional characters to add.
@@ -258,8 +254,8 @@ Returns:
-
- byte_is_valid_colorchar (byte, key)
+
+ byte_is_valid_color_char (byte)
Checks if a byte is valid as a color character (alphanumeric, dynamically added chars, or hardcoded characters).
@@ -270,9 +266,6 @@ Parameters:
byte
number: The byte to check.
- key
- string|nil: The key for additional characters to validate against.
-
Returns:
diff --git a/doc/modules/trie.html b/doc/modules/trie.html
index f092c4d..152360e 100644
--- a/doc/modules/trie.html
+++ b/doc/modules/trie.html
@@ -39,8 +39,9 @@ Modules
buffer
color
config
+ constants
matcher
- parser.argb_hex
+ parser.rgb_hex
parser.hsl
parser.names
parser.rgb
@@ -57,8 +58,33 @@ Modules
Module trie
-
-
+
Trie implementation in LuaJIT.
+
+ This module provides an optimized Trie data structure using LuaJIT's Foreign Function Interface (FFI).
+ It supports operations like insertion, search, finding the longest prefix, and converting the Trie into a table format.
+
Dynamic Allocation:
+ The implementation uses dynamic memory allocation for efficient storage and manipulation of nodes:
+ - Each Trie node dynamically allocates memory for its `children` and `keys` arrays using `ffi.C.malloc` and `ffi.C.realloc`.
+ - Arrays are initially allocated with a small capacity and are resized as needed to accommodate more child nodes.
+
Node Structure:
+ Each Trie node contains the following fields:
+ - **`is_leaf`** (boolean): Indicates whether the node represents the end of a string.
+ - **`capacity`** (number): The current maximum number of children the node can hold.
+ - Starts at a small initial value (e.g., 8) and doubles as needed.
+ - **`size`** (number): The current number of children the node has.
+ - Always ≤ `capacity`.
+ - **`children`** (array): A dynamically allocated array of pointers to child nodes.
+ - **`keys`** (array): A dynamically allocated array of ASCII values corresponding to the `children` nodes.
+
Dynamic Resizing:
+ - If a node's `size` exceeds its `capacity` during insertion, the `capacity` is doubled.
+ - The `children` and `keys` arrays are reallocated to match the new capacity using `ffi.C.realloc`.
+ - Resizing ensures efficient use of memory while avoiding frequent allocations.
+
Memory Management:
+ - Memory is manually managed:
+ - **Allocation**: Done using `ffi.C.malloc` for new nodes and `ffi.C.realloc` for resizing arrays.
+ - **Deallocation**: Performed recursively for all child nodes using `ffi.C.free`.
+ - The implementation includes safeguards to handle allocation failures and ensure proper cleanup.
+
@@ -72,7 +98,7 @@
Module trie
generated by LDoc 1.5.0
-
Last updated - November
+
Last updated - January
-
-
-
-
-
-
-
-
-
-
-
-
-
-
colorizer
-
-
-
-
Contents
-
-
-
-
Modules
-
-
-
-
-
-
-
Module utils
-
Helper utils
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- byte_is_alphanumeric (byte)
-
- -
- Obvious.
-
-
-
Parameters:
-
-
- Returns:
-
-
- boolean
-
-
-
-
-
-
- -
-
- byte_is_hex (byte)
-
- -
- Obvious.
-
-
-
Parameters:
-
-
- Returns:
-
-
- boolean
-
-
-
-
-
-
- -
-
- byte_is_valid_colorchar (byte)
-
- -
- Obvious.
-
-
-
Parameters:
-
-
- Returns:
-
-
- boolean
-
-
-
-
-
-
- -
-
- get_last_modified (path)
-
- -
- Get last modified time of a file
-
-
-
Parameters:
-
- - path
- string: file path
-
-
-
- Returns:
-
-
- number|nil: modified time
-
-
-
-
-
-
- -
-
- merge (...)
-
- -
- Merge two tables.
-
-
todo: Remove this and use vim.tbl_deep_extend
-
-
-
Parameters:
-
-
- Returns:
-
-
- table
-
-
-
-
-
-
- -
-
- parse_hex (byte)
-
- -
- Obvious.
-
-
-
Parameters:
-
-
- Returns:
-
-
- number
-
-
-
-
-
-
- -
-
- percent_or_hex (v)
-
- -
- Obvious.
-
-
-
Parameters:
-
-
- Returns:
-
-
- number|nil
-
-
-
-
-
-
- -
-
- watch_file (path, callback, ...)
-
- -
- Watch a file for changes and execute callback
-
-
-
Parameters:
-
- - path
- string: File path
-
- - callback
- function: Callback to execute
-
- - ...
- array: params for callback
-
-
-
- Returns:
-
-
- function|nil
-
-
-
-
-
-
-
-
-
-
-
-
-
generated by LDoc 1.4.6
-
Last updated - September
-
-
-
diff --git a/doc/modules/utils.html b/doc/modules/utils.html
deleted file mode 100644
index af8d2ff..0000000
--- a/doc/modules/utils.html
+++ /dev/null
@@ -1,326 +0,0 @@
-
-
-
-