This commit is contained in:
subcrip 2024-06-05 01:04:44 +08:00
parent 9813d63059
commit 67200d7402
Signed by: subcrip
SSH Key Fingerprint: SHA256:dFPFi68d8C87YkFkEBU4TkcrYRySWpekRR1hbnDWUCw
3 changed files with 92 additions and 130 deletions

View File

@ -312,7 +312,6 @@ local plugins = {
-- refer to the configuration section below -- refer to the configuration section below
}, },
}, },
{ 'Civitasv/cmake-tools.nvim' },
{ "arielherself/melange-nvim" }, { "arielherself/melange-nvim" },
{ 'hrsh7th/vim-vsnip' }, { 'hrsh7th/vim-vsnip' },
{ {
@ -561,6 +560,7 @@ lspconfig.lua_ls.setup {
capabilities = capabilities capabilities = capabilities
} }
lspconfig.marksman.setup {} lspconfig.marksman.setup {}
lspconfig.cmake.setup {}
local lspconfutil = require 'lspconfig/util' local lspconfutil = require 'lspconfig/util'
local root_pattern = lspconfutil.root_pattern("veridian.yml", ".git") local root_pattern = lspconfutil.root_pattern("veridian.yml", ".git")
@ -954,135 +954,6 @@ require('neo-tree').setup {
} }
} }
require("cmake-tools").setup {
cmake_command = "cmake", -- this is used to specify cmake command path
ctest_command = "ctest", -- this is used to specify ctest command path
cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`
cmake_build_options = {}, -- this will be passed when invoke `CMakeBuild`
-- support macro expansion:
-- ${kit}
-- ${kitGenerator}
-- ${variant:xx}
cmake_build_directory = "out/${variant:buildType}", -- this is used to specify generate directory for cmake, allows macro expansion, relative to vim.loop.cwd()
cmake_soft_link_compile_commands = true, -- this will automatically make a soft link from compile commands file to project root dir
cmake_compile_commands_from_lsp = false, -- this will automatically set compile commands file location using lsp, to use it, please set `cmake_soft_link_compile_commands` to false
cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage
cmake_variants_message = {
short = { show = true }, -- whether to show short message
long = { show = true, max_length = 40 }, -- whether to show long message
},
cmake_dap_configuration = { -- debug settings for cmake
name = "cpp",
type = "codelldb",
request = "launch",
stopOnEntry = false,
runInTerminal = true,
console = "integratedTerminal",
},
cmake_executor = { -- executor to use
name = "quickfix", -- name of the executor
opts = {}, -- the options the executor will get, possible values depend on the executor type. See `default_opts` for possible values.
default_opts = { -- a list of default and possible values for executors
quickfix = {
show = "always", -- "always", "only_on_error"
position = "belowright", -- "vertical", "horizontal", "leftabove", "aboveleft", "rightbelow", "belowright", "topleft", "botright", use `:h vertical` for example to see help on them
size = 10,
encoding = "utf-8", -- if encoding is not "utf-8", it will be converted to "utf-8" using `vim.fn.iconv`
auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful.
},
toggleterm = {
direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float'
close_on_exit = false, -- whether close the terminal when exit
auto_scroll = true, -- whether auto scroll to the bottom
},
overseer = {
new_task_opts = {
strategy = {
"toggleterm",
direction = "horizontal",
autos_croll = true,
quit_on_exit = "success"
}
}, -- options to pass into the `overseer.new_task` command
on_new_task = function(task)
require("overseer").open(
{ enter = false, direction = "right" }
)
end, -- a function that gets overseer.Task when it is created, before calling `task:start`
},
terminal = {
name = "Main Terminal",
prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
split_direction = "horizontal", -- "horizontal", "vertical"
split_size = 11,
-- Window handling
single_terminal_per_instance = true, -- Single viewport, multiple windows
single_terminal_per_tab = true, -- Single viewport per tab
keep_terminal_static_location = true, -- Static location of the viewport if avialable
-- Running Tasks
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
focus = false, -- Focus on terminal when cmake task is launched.
do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter.
}, -- terminal executor uses the values in cmake_terminal
},
},
cmake_runner = { -- runner to use
name = "terminal", -- name of the runner
opts = {}, -- the options the runner will get, possible values depend on the runner type. See `default_opts` for possible values.
default_opts = { -- a list of default and possible values for runners
quickfix = {
show = "always", -- "always", "only_on_error"
position = "belowright", -- "bottom", "top"
size = 10,
encoding = "utf-8",
auto_close_when_success = true, -- typically, you can use it with the "always" option; it will auto-close the quickfix buffer if the execution is successful.
},
toggleterm = {
direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float'
close_on_exit = false, -- whether close the terminal when exit
auto_scroll = true, -- whether auto scroll to the bottom
},
overseer = {
new_task_opts = {
strategy = {
"toggleterm",
direction = "horizontal",
autos_croll = true,
quit_on_exit = "success"
}
}, -- options to pass into the `overseer.new_task` command
on_new_task = function(task)
end, -- a function that gets overseer.Task when it is created, before calling `task:start`
},
terminal = {
name = "Main Terminal",
prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
split_direction = "horizontal", -- "horizontal", "vertical"
split_size = 11,
-- Window handling
single_terminal_per_instance = true, -- Single viewport, multiple windows
single_terminal_per_tab = true, -- Single viewport per tab
keep_terminal_static_location = true, -- Static location of the viewport if avialable
-- Running Tasks
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
focus = false, -- Focus on terminal when cmake task is launched.
do_not_add_newline = false, -- Do not hit enter on the command inserted when using :CMakeRun, allowing a chance to review or modify the command before hitting enter.
},
},
},
cmake_notifications = {
runner = { enabled = true },
executor = { enabled = true },
spinner = { "", "", "", "", "", "", "", "", "", "" }, -- icons used for progress display
refresh_rate_ms = 100, -- how often to iterate icons
},
}
require('telescope').load_extension('git_file_history') require('telescope').load_extension('git_file_history')
require('telescope').load_extension('undo') require('telescope').load_extension('undo')

View File

@ -0,0 +1,78 @@
return [=[
template <int N, typename DataT = int>
struct binary_trie {
vector<tuple<array<int, 2>, DataT, array<int, 2>>> tr;
binary_trie() : tr(1) {}
void emplace(ll x, const DataT& data = {}) {
int ptr = 0;
for (int i = N - 1; ~i; --i) {
int bit = x >> i & 1;
if (not std::get<0>(tr[ptr])[bit]) {
std::get<0>(tr[ptr])[bit] = tr.size();
tr.emplace_back();
}
std::get<2>(tr[ptr])[bit] += 1;
ptr = std::get<0>(tr[ptr])[bit];
}
std::get<1>(tr[ptr]) = data;
}
/// WARN: Don't try to erase a non-existent element!
void erase(ll x) {
int ptr = 0;
vector<pii> st;
for (int i = N - 1; ~i; --i) {
int bit = x >> i & 1;
st.emplace_back(ptr, bit);
ptr = std::get<0>(tr[ptr])[bit];
}
while (st.size() and std::get<2>(tr[st.back().first])[st.back().second] == 1) {
std::get<0>(tr[st.back().first])[st.back().second] = 0;
std::get<2>(tr[st.back().first])[st.back().second] = 0;
st.pop_back();
}
tr[ptr] = {};
}
optional<DataT> get(ll x) {
int ptr = 0;
for (int i = N - 1; ~i; --i) {
int bit = x >> i & 1;
if (not std::get<0>(tr[ptr])[bit]) return {};
ptr = std::get<0>(tr[ptr])[bit];
}
return { std::get<1>(tr[ptr]) };
}
int count_prefix(ll x, int bits = N) {
int ptr = 0;
int res = 0;
for (int i = N - 1; i > max(-1, N - 1 - bits); --i) {
int bit = x >> 1 & 1;
if (not std::get<0>(tr[ptr])[bit]) return 0;
ptr = std::get<0>(tr[ptr])[bit];
res = std::get<2>(tr[ptr])[bit];
}
return res;
}
optional<pair<ll, DataT&>> get_max_xor(ll x) {
int ptr = 0;
ll res = 0;
for (int i = N - 1; ~i; --i) {
int bit = x >> i & 1;
if (std::get<0>(tr[ptr])[1 ^ bit]) {
ptr = std::get<0>(tr[ptr])[1 ^ bit];
res |= (1 ^ bit) << i;
} else if (std::get<0>(tr[ptr])[bit]) {
ptr = std::get<0>(tr[ptr])[bit];
res |= bit << i;
} else {
return {};
}
}
return {{ res, std::get<1>(tr[ptr]) }};
}
};
]=]

View File

@ -275,3 +275,16 @@ ls.add_snippets(nil, {
} }
}) })
local binary_trie = require('snippets.binary-trie')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'binary_trie',
namr = 'binary_trie',
dscr = '01-Trie',
},{
text(lines(binary_trie))
})
}
})