data-structure-typed 2.3.0 → 2.4.0
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/CHANGELOG.md +1 -1
- package/CMakeLists.txt +52 -0
- package/README.md +4 -4
- package/README_CN.md +5 -5
- package/benchmark/report.html +141 -12
- package/benchmark/report.json +1969 -38
- package/build/CMakeCache.txt +603 -0
- package/build/CMakeFiles/4.0.3/CMakeCXXCompiler.cmake +104 -0
- package/build/CMakeFiles/4.0.3/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/build/CMakeFiles/4.0.3/CMakeSystem.cmake +15 -0
- package/build/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
- package/build/CMakeFiles/4.0.3/CompilerIdCXX/a.out +0 -0
- package/build/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
- package/build/CMakeFiles/CMakeConfigureLog.yaml +2146 -0
- package/build/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- package/build/CMakeFiles/InstallScripts.json +9 -0
- package/build/CMakeFiles/Makefile.cmake +100 -0
- package/build/CMakeFiles/Makefile2 +720 -0
- package/build/CMakeFiles/TargetDirectories.txt +23 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/test/performance/data-structures/binary-tree/avl-rb-range-search.test.cpp.o +0 -0
- package/build/CMakeFiles/avl-rb-range-search-benchmark.dir/test/performance/data-structures/binary-tree/avl-rb-range-search.test.cpp.o.d +835 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/test/performance/data-structures/binary-tree/avl-tree.test.cpp.o +0 -0
- package/build/CMakeFiles/avl-tree-benchmark.dir/test/performance/data-structures/binary-tree/avl-tree.test.cpp.o.d +835 -0
- package/build/CMakeFiles/cmake.check_cache +1 -0
- package/build/CMakeFiles/deque-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/deque-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/deque-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/deque-benchmark.dir/compiler_depend.internal +791 -0
- package/build/CMakeFiles/deque-benchmark.dir/compiler_depend.make +2362 -0
- package/build/CMakeFiles/deque-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/deque-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/deque-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/deque-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/deque-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/deque-benchmark.dir/test/performance/data-structures/queue/deque.test.cpp.o +0 -0
- package/build/CMakeFiles/deque-benchmark.dir/test/performance/data-structures/queue/deque.test.cpp.o.d +787 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/compiler_depend.internal +790 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/compiler_depend.make +2359 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/test/performance/data-structures/linked-list/doubly-linked-list.test.cpp.o +0 -0
- package/build/CMakeFiles/doubly-linked-list-benchmark.dir/test/performance/data-structures/linked-list/doubly-linked-list.test.cpp.o.d +786 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/compiler_depend.internal +790 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/compiler_depend.make +2359 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/test/performance/data-structures/hash/hash-map.test.cpp.o +0 -0
- package/build/CMakeFiles/hash-map-benchmark.dir/test/performance/data-structures/hash/hash-map.test.cpp.o.d +786 -0
- package/build/CMakeFiles/heap-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/heap-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/heap-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/heap-benchmark.dir/compiler_depend.internal +843 -0
- package/build/CMakeFiles/heap-benchmark.dir/compiler_depend.make +2518 -0
- package/build/CMakeFiles/heap-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/heap-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/heap-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/heap-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/heap-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/heap-benchmark.dir/test/performance/data-structures/heap/heap.test.cpp.o +0 -0
- package/build/CMakeFiles/heap-benchmark.dir/test/performance/data-structures/heap/heap.test.cpp.o.d +839 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/compiler_depend.internal +793 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/compiler_depend.make +2368 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/test/performance/data-structures/priority-queue/priority-queue.test.cpp.o +0 -0
- package/build/CMakeFiles/priority-queue-benchmark.dir/test/performance/data-structures/priority-queue/priority-queue.test.cpp.o.d +789 -0
- package/build/CMakeFiles/progress.marks +1 -0
- package/build/CMakeFiles/queue-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/queue-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/queue-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/queue-benchmark.dir/compiler_depend.internal +793 -0
- package/build/CMakeFiles/queue-benchmark.dir/compiler_depend.make +2368 -0
- package/build/CMakeFiles/queue-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/queue-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/queue-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/queue-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/queue-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/queue-benchmark.dir/test/performance/data-structures/queue/queue.test.cpp.o +0 -0
- package/build/CMakeFiles/queue-benchmark.dir/test/performance/data-structures/queue/queue.test.cpp.o.d +789 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/test/performance/data-structures/binary-tree/red-black-tree.test.cpp.o +0 -0
- package/build/CMakeFiles/red-black-tree-benchmark.dir/test/performance/data-structures/binary-tree/red-black-tree.test.cpp.o.d +835 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/compiler_depend.internal +790 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/compiler_depend.make +2359 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/test/performance/data-structures/linked-list/singly-linked-list.test.cpp.o +0 -0
- package/build/CMakeFiles/singly-linked-list-benchmark.dir/test/performance/data-structures/linked-list/singly-linked-list.test.cpp.o.d +786 -0
- package/build/CMakeFiles/stack-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/stack-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/stack-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/stack-benchmark.dir/compiler_depend.internal +793 -0
- package/build/CMakeFiles/stack-benchmark.dir/compiler_depend.make +2368 -0
- package/build/CMakeFiles/stack-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/stack-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/stack-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/stack-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/stack-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/stack-benchmark.dir/test/performance/data-structures/stack/stack.test.cpp.o +0 -0
- package/build/CMakeFiles/stack-benchmark.dir/test/performance/data-structures/stack/stack.test.cpp.o.d +789 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/test/performance/data-structures/binary-tree/tree-map.test.cpp.o +0 -0
- package/build/CMakeFiles/tree-map-benchmark.dir/test/performance/data-structures/binary-tree/tree-map.test.cpp.o.d +835 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/test/performance/data-structures/binary-tree/tree-multi-map.test.cpp.o +0 -0
- package/build/CMakeFiles/tree-multi-map-benchmark.dir/test/performance/data-structures/binary-tree/tree-multi-map.test.cpp.o.d +835 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/test/performance/data-structures/binary-tree/tree-multi-set.test.cpp.o +0 -0
- package/build/CMakeFiles/tree-multi-set-benchmark.dir/test/performance/data-structures/binary-tree/tree-multi-set.test.cpp.o.d +835 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/DependInfo.cmake +23 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/build.make +114 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/cmake_clean.cmake +11 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/compiler_depend.internal +839 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/compiler_depend.make +2506 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/compiler_depend.ts +2 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/depend.make +2 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/flags.make +10 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/link.txt +1 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/progress.make +3 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/test/performance/data-structures/binary-tree/tree-set.test.cpp.o +0 -0
- package/build/CMakeFiles/tree-set-benchmark.dir/test/performance/data-structures/binary-tree/tree-set.test.cpp.o.d +835 -0
- package/build/Makefile +783 -0
- package/build/_deps/benchmark-build/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- package/build/_deps/benchmark-build/CMakeFiles/progress.marks +1 -0
- package/build/_deps/benchmark-build/Makefile +140 -0
- package/build/_deps/benchmark-build/benchmark.pc +12 -0
- package/build/_deps/benchmark-build/benchmarkConfig.cmake +14 -0
- package/build/_deps/benchmark-build/benchmarkConfigVersion.cmake +65 -0
- package/build/_deps/benchmark-build/benchmarkTargets.cmake +84 -0
- package/build/_deps/benchmark-build/cmake_install.cmake +50 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/DependInfo.cmake +41 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark.cc.o.d +875 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_api_internal.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_api_internal.cc.o.d +802 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_name.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_name.cc.o.d +772 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_register.cc.o.d +841 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_runner.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/benchmark_runner.cc.o.d +833 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/build.make +402 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/check.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/check.cc.o.d +784 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/cmake_clean.cmake +47 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/cmake_clean_target.cmake +3 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/colorprint.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/colorprint.cc.o.d +791 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/commandlineflags.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/commandlineflags.cc.o.d +795 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/compiler_depend.internal +15519 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/compiler_depend.make +17500 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/compiler_depend.ts +2 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/complexity.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/complexity.cc.o.d +793 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/console_reporter.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/console_reporter.cc.o.d +802 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/counter.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/counter.cc.o.d +773 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/csv_reporter.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/csv_reporter.cc.o.d +799 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/depend.make +2 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/flags.make +10 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/json_reporter.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/json_reporter.cc.o.d +800 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/link.txt +2 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/perf_counters.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/perf_counters.cc.o.d +807 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/progress.make +21 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/reporter.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/reporter.cc.o.d +798 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/statistics.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/statistics.cc.o.d +800 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/string_util.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/string_util.cc.o.d +795 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/sysinfo.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/sysinfo.cc.o.d +933 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/timers.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark.dir/timers.cc.o.d +904 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/DependInfo.cmake +23 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/benchmark_main.cc.o +0 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/benchmark_main.cc.o.d +772 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/build.make +114 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/cmake_clean.cmake +11 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/cmake_clean_target.cmake +3 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/compiler_depend.internal +776 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/compiler_depend.make +2317 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/compiler_depend.ts +2 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/depend.make +2 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/flags.make +10 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/link.txt +2 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/benchmark_main.dir/progress.make +3 -0
- package/build/_deps/benchmark-build/src/CMakeFiles/progress.marks +1 -0
- package/build/_deps/benchmark-build/src/Makefile +710 -0
- package/build/_deps/benchmark-build/src/cmake_install.cmake +45 -0
- package/build/_deps/benchmark-build/src/libbenchmark.a +0 -0
- package/build/_deps/benchmark-build/src/libbenchmark_main.a +0 -0
- package/build/_deps/benchmark-src/.clang-format +5 -0
- package/build/_deps/benchmark-src/.clang-tidy +7 -0
- package/build/_deps/benchmark-src/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
- package/build/_deps/benchmark-src/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/build/_deps/benchmark-src/.github/install_bazel.sh +13 -0
- package/build/_deps/benchmark-src/.github/libcxx-setup.sh +26 -0
- package/build/_deps/benchmark-src/.github/workflows/bazel.yml +35 -0
- package/build/_deps/benchmark-src/.github/workflows/build-and-test-min-cmake.yml +46 -0
- package/build/_deps/benchmark-src/.github/workflows/build-and-test-perfcounters.yml +51 -0
- package/build/_deps/benchmark-src/.github/workflows/build-and-test.yml +114 -0
- package/build/_deps/benchmark-src/.github/workflows/clang-format-lint.yml +17 -0
- package/build/_deps/benchmark-src/.github/workflows/clang-tidy.yml +38 -0
- package/build/_deps/benchmark-src/.github/workflows/doxygen.yml +28 -0
- package/build/_deps/benchmark-src/.github/workflows/pylint.yml +28 -0
- package/build/_deps/benchmark-src/.github/workflows/sanitizer.yml +96 -0
- package/build/_deps/benchmark-src/.github/workflows/test_bindings.yml +29 -0
- package/build/_deps/benchmark-src/.github/workflows/wheels.yml +79 -0
- package/build/_deps/benchmark-src/.travis.yml +208 -0
- package/build/_deps/benchmark-src/.ycm_extra_conf.py +115 -0
- package/build/_deps/benchmark-src/AUTHORS +71 -0
- package/build/_deps/benchmark-src/BUILD.bazel +87 -0
- package/build/_deps/benchmark-src/CMakeLists.txt +340 -0
- package/build/_deps/benchmark-src/CONTRIBUTING.md +58 -0
- package/build/_deps/benchmark-src/CONTRIBUTORS +95 -0
- package/build/_deps/benchmark-src/LICENSE +202 -0
- package/build/_deps/benchmark-src/MODULE.bazel +24 -0
- package/build/_deps/benchmark-src/README.md +223 -0
- package/build/_deps/benchmark-src/WORKSPACE +22 -0
- package/build/_deps/benchmark-src/WORKSPACE.bzlmod +2 -0
- package/build/_deps/benchmark-src/_config.yml +2 -0
- package/build/_deps/benchmark-src/appveyor.yml +50 -0
- package/build/_deps/benchmark-src/bazel/benchmark_deps.bzl +65 -0
- package/build/_deps/benchmark-src/bindings/python/BUILD +3 -0
- package/build/_deps/benchmark-src/bindings/python/build_defs.bzl +25 -0
- package/build/_deps/benchmark-src/bindings/python/google_benchmark/BUILD +40 -0
- package/build/_deps/benchmark-src/bindings/python/google_benchmark/__init__.py +162 -0
- package/build/_deps/benchmark-src/bindings/python/google_benchmark/benchmark.cc +184 -0
- package/build/_deps/benchmark-src/bindings/python/google_benchmark/example.py +136 -0
- package/build/_deps/benchmark-src/bindings/python/nanobind.BUILD +17 -0
- package/build/_deps/benchmark-src/bindings/python/python_headers.BUILD +6 -0
- package/build/_deps/benchmark-src/cmake/AddCXXCompilerFlag.cmake +78 -0
- package/build/_deps/benchmark-src/cmake/CXXFeatureCheck.cmake +82 -0
- package/build/_deps/benchmark-src/cmake/Config.cmake.in +7 -0
- package/build/_deps/benchmark-src/cmake/GetGitVersion.cmake +58 -0
- package/build/_deps/benchmark-src/cmake/GoogleTest.cmake +58 -0
- package/build/_deps/benchmark-src/cmake/GoogleTest.cmake.in +59 -0
- package/build/_deps/benchmark-src/cmake/benchmark.pc.in +12 -0
- package/build/_deps/benchmark-src/cmake/gnu_posix_regex.cpp +12 -0
- package/build/_deps/benchmark-src/cmake/llvm-toolchain.cmake +8 -0
- package/build/_deps/benchmark-src/cmake/posix_regex.cpp +14 -0
- package/build/_deps/benchmark-src/cmake/pthread_affinity.cpp +16 -0
- package/build/_deps/benchmark-src/cmake/split_list.cmake +3 -0
- package/build/_deps/benchmark-src/cmake/std_regex.cpp +10 -0
- package/build/_deps/benchmark-src/cmake/steady_clock.cpp +7 -0
- package/build/_deps/benchmark-src/cmake/thread_safety_attributes.cpp +4 -0
- package/build/_deps/benchmark-src/docs/AssemblyTests.md +149 -0
- package/build/_deps/benchmark-src/docs/_config.yml +3 -0
- package/build/_deps/benchmark-src/docs/assets/images/icon.png +0 -0
- package/build/_deps/benchmark-src/docs/assets/images/icon.xcf +0 -0
- package/build/_deps/benchmark-src/docs/assets/images/icon_black.png +0 -0
- package/build/_deps/benchmark-src/docs/assets/images/icon_black.xcf +0 -0
- package/build/_deps/benchmark-src/docs/dependencies.md +13 -0
- package/build/_deps/benchmark-src/docs/index.md +12 -0
- package/build/_deps/benchmark-src/docs/perf_counters.md +35 -0
- package/build/_deps/benchmark-src/docs/platform_specific_build_instructions.md +48 -0
- package/build/_deps/benchmark-src/docs/python_bindings.md +34 -0
- package/build/_deps/benchmark-src/docs/random_interleaving.md +13 -0
- package/build/_deps/benchmark-src/docs/reducing_variance.md +100 -0
- package/build/_deps/benchmark-src/docs/releasing.md +41 -0
- package/build/_deps/benchmark-src/docs/tools.md +343 -0
- package/build/_deps/benchmark-src/docs/user_guide.md +1266 -0
- package/build/_deps/benchmark-src/include/benchmark/benchmark.h +1991 -0
- package/build/_deps/benchmark-src/include/benchmark/export.h +47 -0
- package/build/_deps/benchmark-src/pyproject.toml +50 -0
- package/build/_deps/benchmark-src/setup.py +113 -0
- package/build/_deps/benchmark-src/src/CMakeLists.txt +170 -0
- package/build/_deps/benchmark-src/src/arraysize.h +33 -0
- package/build/_deps/benchmark-src/src/benchmark.cc +779 -0
- package/build/_deps/benchmark-src/src/benchmark_api_internal.cc +118 -0
- package/build/_deps/benchmark-src/src/benchmark_api_internal.h +87 -0
- package/build/_deps/benchmark-src/src/benchmark_main.cc +18 -0
- package/build/_deps/benchmark-src/src/benchmark_name.cc +59 -0
- package/build/_deps/benchmark-src/src/benchmark_register.cc +520 -0
- package/build/_deps/benchmark-src/src/benchmark_register.h +109 -0
- package/build/_deps/benchmark-src/src/benchmark_runner.cc +497 -0
- package/build/_deps/benchmark-src/src/benchmark_runner.h +131 -0
- package/build/_deps/benchmark-src/src/check.cc +11 -0
- package/build/_deps/benchmark-src/src/check.h +106 -0
- package/build/_deps/benchmark-src/src/colorprint.cc +200 -0
- package/build/_deps/benchmark-src/src/colorprint.h +33 -0
- package/build/_deps/benchmark-src/src/commandlineflags.cc +298 -0
- package/build/_deps/benchmark-src/src/commandlineflags.h +133 -0
- package/build/_deps/benchmark-src/src/complexity.cc +244 -0
- package/build/_deps/benchmark-src/src/complexity.h +55 -0
- package/build/_deps/benchmark-src/src/console_reporter.cc +206 -0
- package/build/_deps/benchmark-src/src/counter.cc +80 -0
- package/build/_deps/benchmark-src/src/counter.h +32 -0
- package/build/_deps/benchmark-src/src/csv_reporter.cc +161 -0
- package/build/_deps/benchmark-src/src/cycleclock.h +230 -0
- package/build/_deps/benchmark-src/src/internal_macros.h +115 -0
- package/build/_deps/benchmark-src/src/json_reporter.cc +320 -0
- package/build/_deps/benchmark-src/src/log.h +88 -0
- package/build/_deps/benchmark-src/src/mutex.h +155 -0
- package/build/_deps/benchmark-src/src/perf_counters.cc +282 -0
- package/build/_deps/benchmark-src/src/perf_counters.h +200 -0
- package/build/_deps/benchmark-src/src/re.h +158 -0
- package/build/_deps/benchmark-src/src/reporter.cc +118 -0
- package/build/_deps/benchmark-src/src/statistics.cc +209 -0
- package/build/_deps/benchmark-src/src/statistics.h +44 -0
- package/build/_deps/benchmark-src/src/string_util.cc +254 -0
- package/build/_deps/benchmark-src/src/string_util.h +70 -0
- package/build/_deps/benchmark-src/src/sysinfo.cc +855 -0
- package/build/_deps/benchmark-src/src/thread_manager.h +63 -0
- package/build/_deps/benchmark-src/src/thread_timer.h +86 -0
- package/build/_deps/benchmark-src/src/timers.cc +272 -0
- package/build/_deps/benchmark-src/src/timers.h +48 -0
- package/build/_deps/benchmark-src/test/AssemblyTests.cmake +67 -0
- package/build/_deps/benchmark-src/test/BUILD +127 -0
- package/build/_deps/benchmark-src/test/CMakeLists.txt +309 -0
- package/build/_deps/benchmark-src/test/args_product_test.cc +77 -0
- package/build/_deps/benchmark-src/test/basic_test.cc +180 -0
- package/build/_deps/benchmark-src/test/benchmark_gtest.cc +169 -0
- package/build/_deps/benchmark-src/test/benchmark_min_time_flag_iters_test.cc +66 -0
- package/build/_deps/benchmark-src/test/benchmark_min_time_flag_time_test.cc +90 -0
- package/build/_deps/benchmark-src/test/benchmark_name_gtest.cc +82 -0
- package/build/_deps/benchmark-src/test/benchmark_random_interleaving_gtest.cc +126 -0
- package/build/_deps/benchmark-src/test/benchmark_setup_teardown_test.cc +157 -0
- package/build/_deps/benchmark-src/test/benchmark_test.cc +274 -0
- package/build/_deps/benchmark-src/test/clobber_memory_assembly_test.cc +64 -0
- package/build/_deps/benchmark-src/test/commandlineflags_gtest.cc +228 -0
- package/build/_deps/benchmark-src/test/complexity_test.cc +228 -0
- package/build/_deps/benchmark-src/test/cxx03_test.cc +62 -0
- package/build/_deps/benchmark-src/test/diagnostics_test.cc +91 -0
- package/build/_deps/benchmark-src/test/display_aggregates_only_test.cc +45 -0
- package/build/_deps/benchmark-src/test/donotoptimize_assembly_test.cc +201 -0
- package/build/_deps/benchmark-src/test/donotoptimize_test.cc +69 -0
- package/build/_deps/benchmark-src/test/filter_test.cc +117 -0
- package/build/_deps/benchmark-src/test/fixture_test.cc +51 -0
- package/build/_deps/benchmark-src/test/internal_threading_test.cc +185 -0
- package/build/_deps/benchmark-src/test/link_main_test.cc +9 -0
- package/build/_deps/benchmark-src/test/map_test.cc +59 -0
- package/build/_deps/benchmark-src/test/memory_manager_test.cc +47 -0
- package/build/_deps/benchmark-src/test/min_time_parse_gtest.cc +30 -0
- package/build/_deps/benchmark-src/test/multiple_ranges_test.cc +96 -0
- package/build/_deps/benchmark-src/test/options_test.cc +77 -0
- package/build/_deps/benchmark-src/test/output_test.h +211 -0
- package/build/_deps/benchmark-src/test/output_test_helper.cc +519 -0
- package/build/_deps/benchmark-src/test/perf_counters_gtest.cc +307 -0
- package/build/_deps/benchmark-src/test/perf_counters_test.cc +92 -0
- package/build/_deps/benchmark-src/test/register_benchmark_test.cc +196 -0
- package/build/_deps/benchmark-src/test/repetitions_test.cc +214 -0
- package/build/_deps/benchmark-src/test/report_aggregates_only_test.cc +41 -0
- package/build/_deps/benchmark-src/test/reporter_output_test.cc +1130 -0
- package/build/_deps/benchmark-src/test/skip_with_error_test.cc +199 -0
- package/build/_deps/benchmark-src/test/spec_arg_test.cc +105 -0
- package/build/_deps/benchmark-src/test/spec_arg_verbosity_test.cc +43 -0
- package/build/_deps/benchmark-src/test/state_assembly_test.cc +68 -0
- package/build/_deps/benchmark-src/test/statistics_gtest.cc +35 -0
- package/build/_deps/benchmark-src/test/string_util_gtest.cc +199 -0
- package/build/_deps/benchmark-src/test/templated_fixture_test.cc +28 -0
- package/build/_deps/benchmark-src/test/time_unit_gtest.cc +37 -0
- package/build/_deps/benchmark-src/test/user_counters_tabular_test.cc +558 -0
- package/build/_deps/benchmark-src/test/user_counters_test.cc +561 -0
- package/build/_deps/benchmark-src/test/user_counters_thousands_test.cc +186 -0
- package/build/_deps/benchmark-src/tools/BUILD.bazel +19 -0
- package/build/_deps/benchmark-src/tools/compare.py +432 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test1_run1.json +127 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test1_run2.json +127 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test2_run.json +81 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test3_run0.json +65 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test3_run1.json +65 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test4_run.json +96 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test4_run0.json +21 -0
- package/build/_deps/benchmark-src/tools/gbench/Inputs/test4_run1.json +21 -0
- package/build/_deps/benchmark-src/tools/gbench/__init__.py +8 -0
- package/build/_deps/benchmark-src/tools/gbench/report.py +1201 -0
- package/build/_deps/benchmark-src/tools/gbench/util.py +203 -0
- package/build/_deps/benchmark-src/tools/libpfm.BUILD.bazel +22 -0
- package/build/_deps/benchmark-src/tools/requirements.txt +2 -0
- package/build/_deps/benchmark-src/tools/strip_asm.py +151 -0
- package/build/_deps/benchmark-subbuild/CMakeCache.txt +133 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/4.0.3/CMakeSystem.cmake +15 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/CMakeConfigureLog.yaml +11 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/CMakeRuleHashes.txt +11 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/InstallScripts.json +7 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/Makefile.cmake +52 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/Makefile2 +122 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/TargetDirectories.txt +3 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/DependInfo.cmake +22 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/Labels.json +46 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/Labels.txt +14 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/build.make +162 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/cmake_clean.cmake +17 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/compiler_depend.make +2 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/compiler_depend.ts +2 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate.dir/progress.make +10 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/cmake.check_cache +1 -0
- package/build/_deps/benchmark-subbuild/CMakeFiles/progress.marks +1 -0
- package/build/_deps/benchmark-subbuild/CMakeLists.txt +42 -0
- package/build/_deps/benchmark-subbuild/Makefile +162 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-gitclone-lastrun.txt +15 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-gitinfo.txt +15 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-patch-info.txt +6 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-update-info.txt +7 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/tmp/benchmark-populate-cfgcmd.txt +1 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/tmp/benchmark-populate-gitclone.cmake +87 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/tmp/benchmark-populate-gitupdate.cmake +317 -0
- package/build/_deps/benchmark-subbuild/benchmark-populate-prefix/tmp/benchmark-populate-mkdirs.cmake +27 -0
- package/build/_deps/benchmark-subbuild/cmake_install.cmake +56 -0
- package/build/bin/avl-rb-range-search-benchmark +0 -0
- package/build/bin/avl-tree-benchmark +0 -0
- package/build/bin/deque-benchmark +0 -0
- package/build/bin/doubly-linked-list-benchmark +0 -0
- package/build/bin/hash-map-benchmark +0 -0
- package/build/bin/heap-benchmark +0 -0
- package/build/bin/priority-queue-benchmark +0 -0
- package/build/bin/queue-benchmark +0 -0
- package/build/bin/red-black-tree-benchmark +0 -0
- package/build/bin/singly-linked-list-benchmark +0 -0
- package/build/bin/stack-benchmark +0 -0
- package/build/bin/tree-map-benchmark +0 -0
- package/build/bin/tree-multi-map-benchmark +0 -0
- package/build/bin/tree-multi-set-benchmark +0 -0
- package/build/bin/tree-set-benchmark +0 -0
- package/build/cmake_install.cmake +66 -0
- package/dist/cjs/index.cjs +1270 -1201
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1309 -1210
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1268 -1196
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1307 -1205
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +177 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +230 -147
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +263 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +170 -0
- package/dist/types/interfaces/binary-tree.d.ts +1 -1
- package/dist/types/types/data-structures/binary-tree/index.d.ts +3 -3
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +28 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +11 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +28 -0
- package/dist/umd/data-structure-typed.js +1303 -1194
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +10 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/eslint.config.mjs +5 -1
- package/package.json +4 -3
- package/src/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +40 -16
- package/src/data-structures/binary-tree/bst.ts +6 -6
- package/src/data-structures/binary-tree/index.ts +3 -3
- package/src/data-structures/binary-tree/red-black-tree.ts +34 -52
- package/src/data-structures/binary-tree/tree-map.ts +417 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +467 -325
- package/src/data-structures/binary-tree/tree-multi-set.ts +491 -0
- package/src/data-structures/binary-tree/tree-set.ts +394 -0
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/index.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-map.ts +39 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +13 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +33 -0
- package/test/config.ts +2 -2
- package/test/performance/benchmark-runner-enhanced.mjs +818 -0
- package/test/performance/cmake-benchmark-runner.mjs +234 -0
- package/test/performance/data-structures/binary-tree/avl-rb-range-search.test.cpp +112 -0
- package/test/performance/data-structures/binary-tree/avl-rb-range-search.test.mjs +51 -0
- package/test/performance/data-structures/binary-tree/avl-tree.test.cpp +181 -0
- package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +138 -0
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.mjs +85 -0
- package/test/performance/data-structures/binary-tree/binary-tree.test.mjs +100 -0
- package/test/performance/data-structures/binary-tree/bst.test.mjs +61 -0
- package/test/performance/data-structures/binary-tree/red-black-tree-cjs.test.mjs +259 -0
- package/test/performance/data-structures/binary-tree/red-black-tree.test.cpp +213 -0
- package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +275 -0
- package/test/performance/data-structures/binary-tree/tree-map.test.cpp +129 -0
- package/test/performance/data-structures/binary-tree/tree-map.test.mjs +171 -0
- package/test/performance/data-structures/binary-tree/tree-multi-map.test.cpp +205 -0
- package/test/performance/data-structures/binary-tree/tree-multi-map.test.mjs +106 -0
- package/test/performance/data-structures/binary-tree/tree-multi-set.test.cpp +217 -0
- package/test/performance/data-structures/binary-tree/tree-multi-set.test.mjs +91 -0
- package/test/performance/data-structures/binary-tree/tree-set.test.cpp +127 -0
- package/test/performance/data-structures/binary-tree/tree-set.test.mjs +174 -0
- package/test/performance/data-structures/comparison/{comparison.test.ts → comparison.test.mjs} +17 -17
- package/test/performance/data-structures/graph/{directed-graph.test.ts → directed-graph.test.mjs} +4 -4
- package/test/performance/data-structures/hash/hash-map.test.cpp +183 -0
- package/test/performance/data-structures/hash/hash-map.test.mjs +187 -0
- package/test/performance/data-structures/heap/heap.test.cpp +61 -0
- package/test/performance/data-structures/heap/heap.test.mjs +31 -0
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.cpp +84 -0
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.mjs +125 -0
- package/test/performance/data-structures/linked-list/singly-linked-list.test.cpp +77 -0
- package/test/performance/data-structures/linked-list/singly-linked-list.test.mjs +84 -0
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.mjs +40 -0
- package/test/performance/data-structures/priority-queue/priority-queue.test.cpp +59 -0
- package/test/performance/data-structures/priority-queue/priority-queue.test.mjs +64 -0
- package/test/performance/data-structures/queue/deque.test.cpp +119 -0
- package/test/performance/data-structures/queue/deque.test.mjs +144 -0
- package/test/performance/data-structures/queue/queue.test.cpp +59 -0
- package/test/performance/data-structures/queue/queue.test.mjs +77 -0
- package/test/performance/data-structures/stack/stack.test.cpp +40 -0
- package/test/performance/data-structures/stack/stack.test.mjs +69 -0
- package/test/performance/data-structures/trie/trie.test.mjs +43 -0
- package/test/performance/reportor-enhanced.mjs +871 -0
- package/test/performance/runner-config.json +33 -21
- package/test/unit/data-structures/base/iterable-element-base.more-branches.coverage.test.ts +6 -6
- package/test/unit/data-structures/base/linear-base.array.coverage.test.ts +5 -5
- package/test/unit/data-structures/base/linear-base.concat-else.coverage.test.ts +10 -10
- package/test/unit/data-structures/base/linear-base.more-branches.coverage.test.ts +7 -10
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +5 -5
- package/test/unit/data-structures/binary-tree/binary-tree.remaining-branches.coverage.test.ts +7 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +7 -7
- package/test/unit/data-structures/binary-tree/bst.more-branches-3.coverage.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/overall.test.ts +18 -31
- package/test/unit/data-structures/binary-tree/red-black-tree.boundary-max-update.coverage.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/red-black-tree.cache-stale-insert.coverage.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-mapmode-defined.coverage.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-mapmode-undefined.coverage.test.ts +5 -5
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-more.coverage.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/red-black-tree.remaining-branches.coverage.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.set-inputs.coverage.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/red-black-tree.setkvnode-parent-cache.coverage.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/red-black-tree.setkvnode-remaining.coverage.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/red-black-tree.setkvnode-uncovered.coverage.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.update-branches.coverage.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/tree-map.test.ts +270 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.coverage.test.ts +144 -3
- package/test/unit/data-structures/binary-tree/{tree-multi-map.test.ts → tree-multi-map.legacy.test.ts.skip} +16 -16
- package/test/unit/data-structures/binary-tree/tree-multi-map.rfc.test.ts +99 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.simplified.test.ts +482 -0
- package/test/unit/data-structures/binary-tree/tree-multi-set.test.ts +545 -0
- package/test/unit/data-structures/binary-tree/tree-set.test.ts +187 -0
- package/test/unit/unrestricted-interconversion.test.ts +12 -10
- package/test/utils/patch.ts +3 -3
- package/test/utils/perf.mjs +34 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -236
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -197
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +0 -243
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +0 -539
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +0 -438
- package/src/data-structures/binary-tree/tree-counter.ts +0 -587
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +0 -3
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +0 -3
- package/src/types/data-structures/binary-tree/tree-counter.ts +0 -3
- package/test/performance/benchmark-runner.ts +0 -531
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +0 -40
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +0 -37
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +0 -40
- package/test/performance/data-structures/binary-tree/bst.test.ts +0 -28
- package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +0 -60
- package/test/performance/data-structures/hash/hash-map.test.ts +0 -99
- package/test/performance/data-structures/heap/heap.test.ts +0 -26
- package/test/performance/data-structures/heap/min-heap.test.ts +0 -0
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -59
- package/test/performance/data-structures/linked-list/linked-list.test.ts +0 -0
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -35
- package/test/performance/data-structures/linked-list/skip-linked-list.test.ts +0 -0
- package/test/performance/data-structures/linked-list/skip-list.test.ts +0 -0
- package/test/performance/data-structures/matrix/matrix.test.ts +0 -0
- package/test/performance/data-structures/matrix/navigator.test.ts +0 -0
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +0 -17
- package/test/performance/data-structures/priority-queue/min-priority-queue.test.ts +0 -0
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +0 -34
- package/test/performance/data-structures/queue/deque.test.ts +0 -59
- package/test/performance/data-structures/queue/queue.test.ts +0 -35
- package/test/performance/data-structures/stack/stack.test.ts +0 -37
- package/test/performance/data-structures/trie/trie.test.ts +0 -18
- package/test/performance/reportor.ts +0 -279
- package/test/performance/single-suite-runner.ts +0 -72
- package/test/performance/types/index.ts +0 -1
- package/test/performance/types/reportor.ts +0 -7
- package/test/unit/data-structures/binary-tree/avl-tree-counter.more-branches-3.coverage.test.ts +0 -146
- package/test/unit/data-structures/binary-tree/avl-tree-counter.more-branches.coverage.test.ts +0 -93
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +0 -878
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.coverage.test.ts +0 -108
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.more-branches-2.coverage.test.ts +0 -85
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +0 -740
- package/test/unit/data-structures/binary-tree/tree-counter.coverage.test.ts +0 -115
- package/test/unit/data-structures/binary-tree/tree-counter.more-branches.coverage.test.ts +0 -244
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +0 -979
- /package/{test/performance/data-structures/binary-tree/binary-index-tree.test.ts → build/_deps/benchmark-subbuild/CMakeFiles/benchmark-populate-complete} +0 -0
- /package/{test/performance/data-structures/binary-tree/segment-tree.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-build} +0 -0
- /package/{test/performance/data-structures/binary-tree/tree-multimap.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-configure} +0 -0
- /package/{test/performance/data-structures/graph/abstract-graph.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-done} +0 -0
- /package/{test/performance/data-structures/graph/map-graph.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-download} +0 -0
- /package/{test/performance/data-structures/graph/overall.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-install} +0 -0
- /package/{test/performance/data-structures/graph/undirected-graph.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-mkdir} +0 -0
- /package/{test/performance/data-structures/hash/hash-table.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-patch} +0 -0
- /package/{test/performance/data-structures/heap/max-heap.test.ts → build/_deps/benchmark-subbuild/benchmark-populate-prefix/src/benchmark-populate-stamp/benchmark-populate-test} +0 -0
- /package/test/unit/data-structures/binary-tree/{tree-multi-map.more-branches-2.coverage.test.ts → tree-multi-map.more-branches-2.coverage.test.ts.skip} +0 -0
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __typeError = (msg) => {
|
|
5
|
+
throw TypeError(msg);
|
|
6
|
+
};
|
|
4
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
9
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
11
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
12
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
7
14
|
|
|
8
15
|
// src/data-structures/base/iterable-entry-base.ts
|
|
9
16
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
@@ -6995,6 +7002,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
6995
7002
|
__publicField(this, "iterationType", "ITERATIVE");
|
|
6996
7003
|
__publicField(this, "_isMapMode", true);
|
|
6997
7004
|
__publicField(this, "_isDuplicate", false);
|
|
7005
|
+
// Map mode acceleration store:
|
|
7006
|
+
// - isMapMode=false: unused
|
|
7007
|
+
// - isMapMode=true: key -> node reference (O(1) has/getNode + fast get)
|
|
6998
7008
|
__publicField(this, "_store", /* @__PURE__ */ new Map());
|
|
6999
7009
|
__publicField(this, "_root");
|
|
7000
7010
|
__publicField(this, "_size", 0);
|
|
@@ -7090,7 +7100,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7090
7100
|
* @returns The newly created node.
|
|
7091
7101
|
*/
|
|
7092
7102
|
createNode(key, value) {
|
|
7093
|
-
return new BinaryTreeNode(key,
|
|
7103
|
+
return new BinaryTreeNode(key, value);
|
|
7094
7104
|
}
|
|
7095
7105
|
/**
|
|
7096
7106
|
* Creates a new, empty tree of the same type and configuration.
|
|
@@ -7237,11 +7247,11 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7237
7247
|
* @returns True if the addition was successful, false otherwise.
|
|
7238
7248
|
*/
|
|
7239
7249
|
set(keyNodeOrEntry, value) {
|
|
7240
|
-
const [newNode
|
|
7250
|
+
const [newNode] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
7241
7251
|
if (newNode === void 0) return false;
|
|
7242
7252
|
if (!this._root) {
|
|
7243
7253
|
this._setRoot(newNode);
|
|
7244
|
-
if (this._isMapMode
|
|
7254
|
+
if (this._isMapMode && newNode !== null && newNode !== void 0) this._store.set(newNode.key, newNode);
|
|
7245
7255
|
this._size = 1;
|
|
7246
7256
|
return true;
|
|
7247
7257
|
}
|
|
@@ -7253,7 +7263,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7253
7263
|
if (!this._isDuplicate) {
|
|
7254
7264
|
if (newNode !== null && cur.key === newNode.key) {
|
|
7255
7265
|
this._replaceNode(cur, newNode);
|
|
7256
|
-
if (this._isMapMode) this.
|
|
7266
|
+
if (this._isMapMode && newNode !== null) this._store.set(cur.key, newNode);
|
|
7257
7267
|
return true;
|
|
7258
7268
|
}
|
|
7259
7269
|
}
|
|
@@ -7273,7 +7283,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7273
7283
|
} else if (potentialParent.right === void 0) {
|
|
7274
7284
|
potentialParent.right = newNode;
|
|
7275
7285
|
}
|
|
7276
|
-
if (this._isMapMode
|
|
7286
|
+
if (this._isMapMode && newNode !== null && newNode !== void 0) this._store.set(newNode.key, newNode);
|
|
7277
7287
|
this._size++;
|
|
7278
7288
|
return true;
|
|
7279
7289
|
}
|
|
@@ -7358,6 +7368,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7358
7368
|
if (leftSubTreeRightMost) {
|
|
7359
7369
|
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
7360
7370
|
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
7371
|
+
if (this._isMapMode) {
|
|
7372
|
+
this._store.set(curr.key, curr);
|
|
7373
|
+
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
7374
|
+
}
|
|
7361
7375
|
if (parentOfLeftSubTreeMax) {
|
|
7362
7376
|
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
7363
7377
|
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
@@ -7441,6 +7455,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7441
7455
|
* @returns The first matching node, or undefined if not found.
|
|
7442
7456
|
*/
|
|
7443
7457
|
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7458
|
+
if (this._isMapMode && keyNodeEntryOrPredicate !== null && keyNodeEntryOrPredicate !== void 0) {
|
|
7459
|
+
if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
7460
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7461
|
+
if (key === null || key === void 0) return;
|
|
7462
|
+
return this._store.get(key);
|
|
7463
|
+
}
|
|
7464
|
+
}
|
|
7444
7465
|
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType)[0];
|
|
7445
7466
|
}
|
|
7446
7467
|
/**
|
|
@@ -7453,15 +7474,22 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7453
7474
|
* @returns The associated value, or undefined.
|
|
7454
7475
|
*/
|
|
7455
7476
|
get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7456
|
-
var _a;
|
|
7477
|
+
var _a, _b;
|
|
7457
7478
|
if (this._isMapMode) {
|
|
7458
7479
|
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7459
7480
|
if (key === null || key === void 0) return;
|
|
7460
|
-
return this._store.get(key);
|
|
7481
|
+
return (_a = this._store.get(key)) == null ? void 0 : _a.value;
|
|
7461
7482
|
}
|
|
7462
|
-
return (
|
|
7483
|
+
return (_b = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _b.value;
|
|
7463
7484
|
}
|
|
7464
7485
|
has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7486
|
+
if (this._isMapMode && keyNodeEntryOrPredicate !== void 0 && keyNodeEntryOrPredicate !== null) {
|
|
7487
|
+
if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
7488
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7489
|
+
if (key === null || key === void 0) return false;
|
|
7490
|
+
return this._store.has(key);
|
|
7491
|
+
}
|
|
7492
|
+
}
|
|
7465
7493
|
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
|
|
7466
7494
|
}
|
|
7467
7495
|
/**
|
|
@@ -8206,8 +8234,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8206
8234
|
}
|
|
8207
8235
|
current = stack.pop();
|
|
8208
8236
|
if (this.isRealNode(current)) {
|
|
8209
|
-
|
|
8210
|
-
else yield [current.key, current.value];
|
|
8237
|
+
yield [current.key, current.value];
|
|
8211
8238
|
current = current.right;
|
|
8212
8239
|
}
|
|
8213
8240
|
}
|
|
@@ -8215,8 +8242,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8215
8242
|
if (node.left && this.isRealNode(node)) {
|
|
8216
8243
|
yield* this[Symbol.iterator](node.left);
|
|
8217
8244
|
}
|
|
8218
|
-
|
|
8219
|
-
else yield [node.key, node.value];
|
|
8245
|
+
yield [node.key, node.value];
|
|
8220
8246
|
if (node.right && this.isRealNode(node)) {
|
|
8221
8247
|
yield* this[Symbol.iterator](node.right);
|
|
8222
8248
|
}
|
|
@@ -8294,8 +8320,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8294
8320
|
(node) => {
|
|
8295
8321
|
if (node === null) cloned.set(null);
|
|
8296
8322
|
else {
|
|
8297
|
-
|
|
8298
|
-
else cloned.set([node.key, node.value]);
|
|
8323
|
+
cloned.set([node.key, node.value]);
|
|
8299
8324
|
}
|
|
8300
8325
|
},
|
|
8301
8326
|
this._root,
|
|
@@ -8303,7 +8328,6 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8303
8328
|
true
|
|
8304
8329
|
// Include nulls
|
|
8305
8330
|
);
|
|
8306
|
-
if (this._isMapMode) cloned._store = this._store;
|
|
8307
8331
|
}
|
|
8308
8332
|
/**
|
|
8309
8333
|
* (Protected) Recursive helper for `toVisual`.
|
|
@@ -8466,8 +8490,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8466
8490
|
*/
|
|
8467
8491
|
_setValue(key, value) {
|
|
8468
8492
|
if (key === null || key === void 0) return false;
|
|
8469
|
-
|
|
8470
|
-
|
|
8493
|
+
const node = this._store.get(key);
|
|
8494
|
+
if (!node) return false;
|
|
8495
|
+
node.value = value;
|
|
8496
|
+
return true;
|
|
8471
8497
|
}
|
|
8472
8498
|
/**
|
|
8473
8499
|
* (Protected) Clears all nodes from the tree.
|
|
@@ -8676,7 +8702,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8676
8702
|
* @returns The newly created BSTNode.
|
|
8677
8703
|
*/
|
|
8678
8704
|
createNode(key, value) {
|
|
8679
|
-
return new BSTNode(key,
|
|
8705
|
+
return new BSTNode(key, value);
|
|
8680
8706
|
}
|
|
8681
8707
|
/**
|
|
8682
8708
|
* Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
@@ -8917,11 +8943,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8917
8943
|
* @returns True if the addition was successful, false otherwise.
|
|
8918
8944
|
*/
|
|
8919
8945
|
set(keyNodeOrEntry, value) {
|
|
8920
|
-
const [newNode
|
|
8946
|
+
const [newNode] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
8921
8947
|
if (newNode === void 0) return false;
|
|
8922
8948
|
if (this._root === void 0) {
|
|
8923
8949
|
this._setRoot(newNode);
|
|
8924
|
-
if (this._isMapMode
|
|
8950
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
8925
8951
|
this._size++;
|
|
8926
8952
|
return true;
|
|
8927
8953
|
}
|
|
@@ -8929,12 +8955,12 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8929
8955
|
while (current !== void 0) {
|
|
8930
8956
|
if (this._compare(current.key, newNode.key) === 0) {
|
|
8931
8957
|
this._replaceNode(current, newNode);
|
|
8932
|
-
if (this._isMapMode) this.
|
|
8958
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(current.key, newNode);
|
|
8933
8959
|
return true;
|
|
8934
8960
|
} else if (this._compare(current.key, newNode.key) > 0) {
|
|
8935
8961
|
if (current.left === void 0) {
|
|
8936
8962
|
current.left = newNode;
|
|
8937
|
-
if (this._isMapMode
|
|
8963
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
8938
8964
|
this._size++;
|
|
8939
8965
|
return true;
|
|
8940
8966
|
}
|
|
@@ -8942,7 +8968,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8942
8968
|
} else {
|
|
8943
8969
|
if (current.right === void 0) {
|
|
8944
8970
|
current.right = newNode;
|
|
8945
|
-
if (this._isMapMode
|
|
8971
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
8946
8972
|
this._size++;
|
|
8947
8973
|
return true;
|
|
8948
8974
|
}
|
|
@@ -10497,7 +10523,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10497
10523
|
* @returns The newly created AVLTreeNode.
|
|
10498
10524
|
*/
|
|
10499
10525
|
createNode(key, value) {
|
|
10500
|
-
return new AVLTreeNode(key,
|
|
10526
|
+
return new AVLTreeNode(key, value);
|
|
10501
10527
|
}
|
|
10502
10528
|
/**
|
|
10503
10529
|
* Checks if the given item is an `AVLTreeNode` instance.
|
|
@@ -11051,7 +11077,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11051
11077
|
* @returns A new RedBlackTreeNode instance.
|
|
11052
11078
|
*/
|
|
11053
11079
|
createNode(key, value, color = "BLACK") {
|
|
11054
|
-
return new RedBlackTreeNode(key,
|
|
11080
|
+
return new RedBlackTreeNode(key, value, color);
|
|
11055
11081
|
}
|
|
11056
11082
|
/**
|
|
11057
11083
|
* Type guard: check whether the input is a RedBlackTreeNode.
|
|
@@ -11202,20 +11228,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11202
11228
|
if (minN !== NIL) {
|
|
11203
11229
|
const cMin = comparator(key, minN.key);
|
|
11204
11230
|
if (cMin === 0) {
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
else this._setValue(key, nextValue);
|
|
11208
|
-
} else minN.value = nextValue;
|
|
11231
|
+
minN.value = nextValue;
|
|
11232
|
+
if (this._isMapMode) this._store.set(key, minN);
|
|
11209
11233
|
return { node: minN, created: false };
|
|
11210
11234
|
}
|
|
11211
11235
|
const minL = minN.left;
|
|
11212
11236
|
if (cMin < 0 && (minL === NIL || minL === null || minL === void 0)) {
|
|
11213
11237
|
const newNode2 = this.createNode(key, nextValue);
|
|
11214
11238
|
this._attachNewNode(minN, "left", newNode2);
|
|
11215
|
-
if (this._isMapMode)
|
|
11216
|
-
if (nextValue !== void 0) this._store.set(newNode2.key, nextValue);
|
|
11217
|
-
else this._setValue(newNode2.key, nextValue);
|
|
11218
|
-
}
|
|
11239
|
+
if (this._isMapMode) this._store.set(newNode2.key, newNode2);
|
|
11219
11240
|
this._size++;
|
|
11220
11241
|
this._setMinCache(newNode2);
|
|
11221
11242
|
if (header._right === NIL) this._setMaxCache(newNode2);
|
|
@@ -11225,20 +11246,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11225
11246
|
const maxN = (_b = header._right) != null ? _b : NIL;
|
|
11226
11247
|
const cMax = comparator(key, maxN.key);
|
|
11227
11248
|
if (cMax === 0) {
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
else this._setValue(key, nextValue);
|
|
11231
|
-
} else maxN.value = nextValue;
|
|
11249
|
+
maxN.value = nextValue;
|
|
11250
|
+
if (this._isMapMode) this._store.set(key, maxN);
|
|
11232
11251
|
return { node: maxN, created: false };
|
|
11233
11252
|
}
|
|
11234
11253
|
const maxR = maxN.right;
|
|
11235
11254
|
if (cMax > 0 && (maxR === NIL || maxR === null || maxR === void 0)) {
|
|
11236
11255
|
const newNode2 = this.createNode(key, nextValue);
|
|
11237
11256
|
this._attachNewNode(maxN, "right", newNode2);
|
|
11238
|
-
if (this._isMapMode)
|
|
11239
|
-
if (nextValue !== void 0) this._store.set(newNode2.key, nextValue);
|
|
11240
|
-
else this._setValue(newNode2.key, nextValue);
|
|
11241
|
-
}
|
|
11257
|
+
if (this._isMapMode) this._store.set(newNode2.key, newNode2);
|
|
11242
11258
|
this._size++;
|
|
11243
11259
|
this._setMaxCache(newNode2);
|
|
11244
11260
|
if (header._left === NIL) this._setMinCache(newNode2);
|
|
@@ -11258,12 +11274,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11258
11274
|
if (lastCompared < 0) current = (_d = current.left) != null ? _d : NIL;
|
|
11259
11275
|
else if (lastCompared > 0) current = (_e = current.right) != null ? _e : NIL;
|
|
11260
11276
|
else {
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
else this._setValue(key, nextValue);
|
|
11264
|
-
} else {
|
|
11265
|
-
current.value = nextValue;
|
|
11266
|
-
}
|
|
11277
|
+
current.value = nextValue;
|
|
11278
|
+
if (isMapMode) store.set(key, current);
|
|
11267
11279
|
return { node: current, created: false };
|
|
11268
11280
|
}
|
|
11269
11281
|
}
|
|
@@ -11282,10 +11294,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11282
11294
|
this._insertFixup(newNode);
|
|
11283
11295
|
if (this.isRealNode(this._root)) this._root.color = "BLACK";
|
|
11284
11296
|
else return void 0;
|
|
11285
|
-
if (isMapMode)
|
|
11286
|
-
if (nextValue !== void 0) store.set(newNode.key, nextValue);
|
|
11287
|
-
else this._setValue(newNode.key, nextValue);
|
|
11288
|
-
}
|
|
11297
|
+
if (isMapMode) store.set(newNode.key, newNode);
|
|
11289
11298
|
this._size++;
|
|
11290
11299
|
const hMin = (_f = this._header._left) != null ? _f : NIL;
|
|
11291
11300
|
const hMax = (_g = this._header._right) != null ? _g : NIL;
|
|
@@ -11313,10 +11322,11 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11313
11322
|
* @remarks Time O(log n) average, Space O(1)
|
|
11314
11323
|
*/
|
|
11315
11324
|
_setKV(key, nextValue) {
|
|
11316
|
-
if (this._isMapMode
|
|
11325
|
+
if (this._isMapMode) {
|
|
11317
11326
|
const store = this._store;
|
|
11318
|
-
|
|
11319
|
-
|
|
11327
|
+
const node = store.get(key);
|
|
11328
|
+
if (node) {
|
|
11329
|
+
node.value = nextValue;
|
|
11320
11330
|
return true;
|
|
11321
11331
|
}
|
|
11322
11332
|
}
|
|
@@ -11341,10 +11351,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11341
11351
|
const cmp = this._compare.bind(this);
|
|
11342
11352
|
const c0 = cmp(key, hint.key);
|
|
11343
11353
|
if (c0 === 0) {
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
else this._setValue(key, value);
|
|
11347
|
-
} else hint.value = value;
|
|
11354
|
+
hint.value = value;
|
|
11355
|
+
if (this._isMapMode) this._store.set(key, hint);
|
|
11348
11356
|
return hint;
|
|
11349
11357
|
}
|
|
11350
11358
|
if (c0 < 0) {
|
|
@@ -11352,10 +11360,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11352
11360
|
const newNode = this.createNode(key, value);
|
|
11353
11361
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11354
11362
|
this._attachNewNode(hint, "left", newNode);
|
|
11355
|
-
if (this._isMapMode)
|
|
11356
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11357
|
-
else this._setValue(key, value);
|
|
11358
|
-
}
|
|
11363
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11359
11364
|
this._size++;
|
|
11360
11365
|
const NIL = this.NIL;
|
|
11361
11366
|
const hMin = (_b = this._header._left) != null ? _b : NIL;
|
|
@@ -11372,10 +11377,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11372
11377
|
const newNode = this.createNode(key, value);
|
|
11373
11378
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11374
11379
|
this._attachNewNode(pred, "right", newNode);
|
|
11375
|
-
if (this._isMapMode)
|
|
11376
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11377
|
-
else this._setValue(key, value);
|
|
11378
|
-
}
|
|
11380
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11379
11381
|
this._size++;
|
|
11380
11382
|
const NIL = this.NIL;
|
|
11381
11383
|
const hMin = (_e = this._header._left) != null ? _e : NIL;
|
|
@@ -11390,10 +11392,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11390
11392
|
const newNode = this.createNode(key, value);
|
|
11391
11393
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11392
11394
|
this._attachNewNode(hint, "right", newNode);
|
|
11393
|
-
if (this._isMapMode)
|
|
11394
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11395
|
-
else this._setValue(key, value);
|
|
11396
|
-
}
|
|
11395
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11397
11396
|
this._size++;
|
|
11398
11397
|
const NIL = this.NIL;
|
|
11399
11398
|
const hMin = (_h = this._header._left) != null ? _h : NIL;
|
|
@@ -11410,10 +11409,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11410
11409
|
const newNode = this.createNode(key, value);
|
|
11411
11410
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11412
11411
|
this._attachNewNode(succ, "left", newNode);
|
|
11413
|
-
if (this._isMapMode)
|
|
11414
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11415
|
-
else this._setValue(key, value);
|
|
11416
|
-
}
|
|
11412
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11417
11413
|
this._size++;
|
|
11418
11414
|
const NIL = this.NIL;
|
|
11419
11415
|
const hMin = (_k = this._header._left) != null ? _k : NIL;
|
|
@@ -11460,12 +11456,24 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11460
11456
|
} else {
|
|
11461
11457
|
return false;
|
|
11462
11458
|
}
|
|
11463
|
-
if (this._isMapMode)
|
|
11459
|
+
if (this._isMapMode) {
|
|
11460
|
+
const n = this.getNode(newNode.key);
|
|
11461
|
+
if (this.isRealNode(n)) {
|
|
11462
|
+
n.value = newValue;
|
|
11463
|
+
this._store.set(n.key, n);
|
|
11464
|
+
}
|
|
11465
|
+
}
|
|
11464
11466
|
this._size++;
|
|
11465
11467
|
return true;
|
|
11466
11468
|
}
|
|
11467
11469
|
if (insertStatus === "UPDATED") {
|
|
11468
|
-
if (this._isMapMode)
|
|
11470
|
+
if (this._isMapMode) {
|
|
11471
|
+
const n = this.getNode(newNode.key);
|
|
11472
|
+
if (this.isRealNode(n)) {
|
|
11473
|
+
n.value = newValue;
|
|
11474
|
+
this._store.set(n.key, n);
|
|
11475
|
+
}
|
|
11476
|
+
}
|
|
11469
11477
|
return true;
|
|
11470
11478
|
}
|
|
11471
11479
|
return false;
|
|
@@ -11835,1456 +11843,1543 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11835
11843
|
__name(_RedBlackTree, "RedBlackTree");
|
|
11836
11844
|
var RedBlackTree = _RedBlackTree;
|
|
11837
11845
|
|
|
11838
|
-
// src/data-structures/binary-tree/
|
|
11839
|
-
var
|
|
11846
|
+
// src/data-structures/binary-tree/tree-set.ts
|
|
11847
|
+
var _core, _isDefaultComparator, _userComparator;
|
|
11848
|
+
var _TreeSet = class _TreeSet {
|
|
11840
11849
|
/**
|
|
11841
|
-
* Create
|
|
11842
|
-
*
|
|
11843
|
-
* @
|
|
11844
|
-
*
|
|
11845
|
-
* @returns New AVLTreeMultiMapNode instance.
|
|
11850
|
+
* Create a TreeSet from an iterable of keys.
|
|
11851
|
+
*
|
|
11852
|
+
* @throws {TypeError} When using the default comparator and encountering unsupported key types,
|
|
11853
|
+
* or invalid keys (e.g. `NaN`, invalid `Date`).
|
|
11846
11854
|
*/
|
|
11847
|
-
constructor(
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
|
|
11855
|
-
|
|
11856
|
-
this.
|
|
11857
|
-
this.value = value;
|
|
11855
|
+
constructor(elements = [], options = {}) {
|
|
11856
|
+
__privateAdd(this, _core);
|
|
11857
|
+
__privateAdd(this, _isDefaultComparator);
|
|
11858
|
+
__privateAdd(this, _userComparator);
|
|
11859
|
+
var _a;
|
|
11860
|
+
__privateSet(this, _userComparator, options.comparator);
|
|
11861
|
+
const comparator = (_a = options.comparator) != null ? _a : _TreeSet.createDefaultComparator();
|
|
11862
|
+
__privateSet(this, _isDefaultComparator, options.comparator === void 0);
|
|
11863
|
+
__privateSet(this, _core, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
11864
|
+
for (const k of elements) this.add(k);
|
|
11858
11865
|
}
|
|
11859
11866
|
/**
|
|
11860
|
-
*
|
|
11861
|
-
*
|
|
11862
|
-
*
|
|
11867
|
+
* Create the strict default comparator.
|
|
11868
|
+
*
|
|
11869
|
+
* Supports:
|
|
11870
|
+
* - `number` (rejects `NaN`; treats `-0` and `0` as equal)
|
|
11871
|
+
* - `string`
|
|
11872
|
+
* - `Date` (orders by `getTime()`, rejects invalid dates)
|
|
11873
|
+
*
|
|
11874
|
+
* For other key types, a custom comparator must be provided.
|
|
11863
11875
|
*/
|
|
11864
|
-
|
|
11865
|
-
return
|
|
11876
|
+
static createDefaultComparator() {
|
|
11877
|
+
return (a, b) => {
|
|
11878
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
11879
|
+
if (Number.isNaN(a) || Number.isNaN(b)) throw new TypeError("TreeSet: NaN is not a valid key");
|
|
11880
|
+
const aa = Object.is(a, -0) ? 0 : a;
|
|
11881
|
+
const bb = Object.is(b, -0) ? 0 : b;
|
|
11882
|
+
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
11883
|
+
}
|
|
11884
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
11885
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
11886
|
+
}
|
|
11887
|
+
if (a instanceof Date && b instanceof Date) {
|
|
11888
|
+
const ta = a.getTime();
|
|
11889
|
+
const tb = b.getTime();
|
|
11890
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) throw new TypeError("TreeSet: invalid Date key");
|
|
11891
|
+
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
11892
|
+
}
|
|
11893
|
+
throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys");
|
|
11894
|
+
};
|
|
11866
11895
|
}
|
|
11867
11896
|
/**
|
|
11868
|
-
*
|
|
11869
|
-
* @remarks Time O(1), Space O(1)
|
|
11870
|
-
* @param v - New left child node, or null/undefined.
|
|
11871
|
-
* @returns void
|
|
11897
|
+
* Number of elements in the set.
|
|
11872
11898
|
*/
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
11899
|
+
get size() {
|
|
11900
|
+
return __privateGet(this, _core).size;
|
|
11901
|
+
}
|
|
11902
|
+
/**
|
|
11903
|
+
* Whether the set is empty.
|
|
11904
|
+
*/
|
|
11905
|
+
isEmpty() {
|
|
11906
|
+
return this.size === 0;
|
|
11907
|
+
}
|
|
11908
|
+
_validateKey(key) {
|
|
11909
|
+
if (!__privateGet(this, _isDefaultComparator)) return;
|
|
11910
|
+
if (typeof key === "number") {
|
|
11911
|
+
if (Number.isNaN(key)) throw new TypeError("TreeSet: NaN is not a valid key");
|
|
11912
|
+
return;
|
|
11876
11913
|
}
|
|
11877
|
-
|
|
11914
|
+
if (typeof key === "string") return;
|
|
11915
|
+
if (key instanceof Date) {
|
|
11916
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeSet: invalid Date key");
|
|
11917
|
+
return;
|
|
11918
|
+
}
|
|
11919
|
+
throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys");
|
|
11878
11920
|
}
|
|
11879
11921
|
/**
|
|
11880
|
-
*
|
|
11881
|
-
* @remarks
|
|
11882
|
-
* @returns Right child node, or null/undefined.
|
|
11922
|
+
* Add a key to the set (no-op if already present).
|
|
11923
|
+
* @remarks Expected time O(log n)
|
|
11883
11924
|
*/
|
|
11884
|
-
|
|
11885
|
-
|
|
11925
|
+
add(key) {
|
|
11926
|
+
this._validateKey(key);
|
|
11927
|
+
__privateGet(this, _core).set(key, void 0);
|
|
11928
|
+
return this;
|
|
11886
11929
|
}
|
|
11887
11930
|
/**
|
|
11888
|
-
*
|
|
11889
|
-
* @remarks
|
|
11890
|
-
* @param v - New right child node, or null/undefined.
|
|
11891
|
-
* @returns void
|
|
11931
|
+
* Test whether a key exists.
|
|
11932
|
+
* @remarks Expected time O(log n)
|
|
11892
11933
|
*/
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
}
|
|
11897
|
-
this._right = v;
|
|
11934
|
+
has(key) {
|
|
11935
|
+
this._validateKey(key);
|
|
11936
|
+
return __privateGet(this, _core).has(key);
|
|
11898
11937
|
}
|
|
11899
11938
|
/**
|
|
11900
|
-
*
|
|
11901
|
-
* @
|
|
11902
|
-
*
|
|
11903
|
-
* @returns The height.
|
|
11939
|
+
* Delete a key.
|
|
11940
|
+
* @returns `true` if the key existed; otherwise `false`.
|
|
11941
|
+
* @remarks Expected time O(log n)
|
|
11904
11942
|
*/
|
|
11905
|
-
|
|
11906
|
-
|
|
11943
|
+
delete(key) {
|
|
11944
|
+
var _a;
|
|
11945
|
+
this._validateKey(key);
|
|
11946
|
+
const res = __privateGet(this, _core).delete(key);
|
|
11947
|
+
return Array.isArray(res) && res.length > 0 && !!((_a = res[0]) == null ? void 0 : _a.deleted);
|
|
11907
11948
|
}
|
|
11908
11949
|
/**
|
|
11909
|
-
*
|
|
11910
|
-
* @remarks Time O(1), Space O(1)
|
|
11911
|
-
*
|
|
11912
|
-
* @param value - The new height.
|
|
11950
|
+
* Remove all keys.
|
|
11913
11951
|
*/
|
|
11914
|
-
|
|
11915
|
-
this.
|
|
11952
|
+
clear() {
|
|
11953
|
+
__privateGet(this, _core).clear();
|
|
11916
11954
|
}
|
|
11917
11955
|
/**
|
|
11918
|
-
*
|
|
11919
|
-
* @remarks Time O(1), Space O(1)
|
|
11920
|
-
*
|
|
11921
|
-
* @returns The node's color.
|
|
11956
|
+
* Iterate over keys in ascending order.
|
|
11922
11957
|
*/
|
|
11923
|
-
|
|
11924
|
-
return this.
|
|
11958
|
+
keys() {
|
|
11959
|
+
return __privateGet(this, _core).keys();
|
|
11925
11960
|
}
|
|
11926
11961
|
/**
|
|
11927
|
-
*
|
|
11928
|
-
* @remarks Time O(1), Space O(1)
|
|
11962
|
+
* Iterate over values in ascending order.
|
|
11929
11963
|
*
|
|
11930
|
-
*
|
|
11964
|
+
* Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
11931
11965
|
*/
|
|
11932
|
-
|
|
11933
|
-
this.
|
|
11966
|
+
values() {
|
|
11967
|
+
return this.keys();
|
|
11934
11968
|
}
|
|
11935
11969
|
/**
|
|
11936
|
-
*
|
|
11937
|
-
* @remarks Time O(1), Space O(1)
|
|
11970
|
+
* Iterate over `[value, value]` pairs (native Set convention).
|
|
11938
11971
|
*
|
|
11939
|
-
*
|
|
11972
|
+
* Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
11940
11973
|
*/
|
|
11941
|
-
|
|
11942
|
-
|
|
11974
|
+
*entries() {
|
|
11975
|
+
for (const k of this.keys()) yield [k, k];
|
|
11976
|
+
}
|
|
11977
|
+
[Symbol.iterator]() {
|
|
11978
|
+
return this.keys();
|
|
11943
11979
|
}
|
|
11944
11980
|
/**
|
|
11945
|
-
*
|
|
11946
|
-
* @remarks Time O(1), Space O(1)
|
|
11981
|
+
* Visit each value in ascending order.
|
|
11947
11982
|
*
|
|
11948
|
-
*
|
|
11983
|
+
* Callback follows native Set convention: `(value, value2, set)`.
|
|
11949
11984
|
*/
|
|
11950
|
-
|
|
11951
|
-
this.
|
|
11985
|
+
forEach(cb, thisArg) {
|
|
11986
|
+
for (const k of this) cb.call(thisArg, k, k, this);
|
|
11952
11987
|
}
|
|
11953
11988
|
/**
|
|
11954
|
-
*
|
|
11955
|
-
* @remarks Time O(1), Space O(1)
|
|
11989
|
+
* Create a new TreeSet by mapping each value to a new key.
|
|
11956
11990
|
*
|
|
11957
|
-
*
|
|
11991
|
+
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
11992
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
11958
11993
|
*/
|
|
11959
|
-
|
|
11960
|
-
|
|
11961
|
-
|
|
11962
|
-
|
|
11963
|
-
|
|
11964
|
-
|
|
11965
|
-
} else if (this.parent.right === this) {
|
|
11966
|
-
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
11994
|
+
map(callbackfn, options = {}, thisArg) {
|
|
11995
|
+
const out = new _TreeSet([], options);
|
|
11996
|
+
let index = 0;
|
|
11997
|
+
for (const v of this) {
|
|
11998
|
+
const mk = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
11999
|
+
out.add(mk);
|
|
11967
12000
|
}
|
|
11968
|
-
return
|
|
12001
|
+
return out;
|
|
11969
12002
|
}
|
|
11970
|
-
};
|
|
11971
|
-
__name(_AVLTreeMultiMapNode, "AVLTreeMultiMapNode");
|
|
11972
|
-
var AVLTreeMultiMapNode = _AVLTreeMultiMapNode;
|
|
11973
|
-
var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
11974
12003
|
/**
|
|
11975
|
-
* Create
|
|
11976
|
-
* @remarks Time O(
|
|
11977
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
11978
|
-
* @param [options] - Options for AVLTreeMultiMap (comparator, reverse, map mode).
|
|
11979
|
-
* @returns New AVLTreeMultiMap instance.
|
|
12004
|
+
* Create a new TreeSet containing only values that satisfy the predicate.
|
|
12005
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
11980
12006
|
*/
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
12007
|
+
filter(callbackfn, thisArg) {
|
|
12008
|
+
const out = new _TreeSet([], { comparator: __privateGet(this, _userComparator) });
|
|
12009
|
+
let index = 0;
|
|
12010
|
+
for (const v of this) {
|
|
12011
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12012
|
+
if (ok) out.add(v);
|
|
11985
12013
|
}
|
|
11986
|
-
|
|
11987
|
-
createNode(key, value = []) {
|
|
11988
|
-
return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
12014
|
+
return out;
|
|
11989
12015
|
}
|
|
11990
12016
|
/**
|
|
11991
|
-
*
|
|
11992
|
-
* @remarks Time O(
|
|
11993
|
-
*
|
|
11994
|
-
* @param keyNodeOrEntry - The item to check.
|
|
11995
|
-
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
12017
|
+
* Reduce values into a single accumulator.
|
|
12018
|
+
* @remarks Time O(n), Space O(1)
|
|
11996
12019
|
*/
|
|
11997
|
-
|
|
11998
|
-
|
|
12020
|
+
reduce(callbackfn, initialValue) {
|
|
12021
|
+
let acc = initialValue;
|
|
12022
|
+
let index = 0;
|
|
12023
|
+
for (const v of this) acc = callbackfn(acc, v, index++, this);
|
|
12024
|
+
return acc;
|
|
11999
12025
|
}
|
|
12000
12026
|
/**
|
|
12001
|
-
*
|
|
12002
|
-
* @remarks Time O(
|
|
12003
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
12004
|
-
* @param [value] - Single value to set when a bare key is provided.
|
|
12005
|
-
* @returns True if inserted or appended; false if ignored.
|
|
12027
|
+
* Test whether all values satisfy a predicate.
|
|
12028
|
+
* @remarks Time O(n), Space O(1)
|
|
12006
12029
|
*/
|
|
12007
|
-
|
|
12008
|
-
|
|
12009
|
-
const
|
|
12010
|
-
|
|
12011
|
-
|
|
12012
|
-
const existingValues = this.get(key);
|
|
12013
|
-
if (existingValues !== void 0 && values !== void 0) {
|
|
12014
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12015
|
-
return true;
|
|
12016
|
-
}
|
|
12017
|
-
return false;
|
|
12018
|
-
}, "_setToValues");
|
|
12019
|
-
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
12020
|
-
const existingNode = this.getNode(key);
|
|
12021
|
-
if (this.isRealNode(existingNode)) {
|
|
12022
|
-
const existingValues = this.get(existingNode);
|
|
12023
|
-
if (existingValues === void 0) {
|
|
12024
|
-
super.set(key, values);
|
|
12025
|
-
return true;
|
|
12026
|
-
}
|
|
12027
|
-
if (values !== void 0) {
|
|
12028
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12029
|
-
return true;
|
|
12030
|
-
} else {
|
|
12031
|
-
return false;
|
|
12032
|
-
}
|
|
12033
|
-
} else {
|
|
12034
|
-
return super.set(key, values);
|
|
12035
|
-
}
|
|
12036
|
-
}, "_setByNode");
|
|
12037
|
-
if (this._isMapMode) {
|
|
12038
|
-
return _setByNode() || _setToValues();
|
|
12039
|
-
}
|
|
12040
|
-
return _setToValues() || _setByNode();
|
|
12041
|
-
}, "_commonAdd");
|
|
12042
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
12043
|
-
const [key, values] = keyNodeOrEntry;
|
|
12044
|
-
return _commonAdd(key, value !== void 0 ? [value] : values);
|
|
12030
|
+
every(callbackfn, thisArg) {
|
|
12031
|
+
let index = 0;
|
|
12032
|
+
for (const v of this) {
|
|
12033
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12034
|
+
if (!ok) return false;
|
|
12045
12035
|
}
|
|
12046
|
-
return
|
|
12036
|
+
return true;
|
|
12047
12037
|
}
|
|
12048
12038
|
/**
|
|
12049
|
-
*
|
|
12050
|
-
* @remarks Time O(
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
if (Array.isArray(values)) {
|
|
12058
|
-
const index = values.indexOf(value);
|
|
12059
|
-
if (index === -1) return false;
|
|
12060
|
-
values.splice(index, 1);
|
|
12061
|
-
if (values.length === 0) this.delete(keyNodeOrEntry);
|
|
12062
|
-
return true;
|
|
12039
|
+
* Test whether any value satisfies a predicate.
|
|
12040
|
+
* @remarks Time O(n), Space O(1)
|
|
12041
|
+
*/
|
|
12042
|
+
some(callbackfn, thisArg) {
|
|
12043
|
+
let index = 0;
|
|
12044
|
+
for (const v of this) {
|
|
12045
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12046
|
+
if (ok) return true;
|
|
12063
12047
|
}
|
|
12064
12048
|
return false;
|
|
12065
12049
|
}
|
|
12066
12050
|
/**
|
|
12067
|
-
*
|
|
12068
|
-
* @remarks Time O(
|
|
12069
|
-
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
12070
|
-
* @returns True if rebalancing succeeded (tree not empty).
|
|
12051
|
+
* Find the first value that satisfies a predicate.
|
|
12052
|
+
* @remarks Time O(n), Space O(1)
|
|
12071
12053
|
*/
|
|
12072
|
-
|
|
12073
|
-
|
|
12074
|
-
const
|
|
12075
|
-
|
|
12076
|
-
|
|
12077
|
-
|
|
12078
|
-
|
|
12079
|
-
const m = l + (r - l >> 1);
|
|
12080
|
-
const root = nodes[m];
|
|
12081
|
-
root.left = build(l, m - 1, root);
|
|
12082
|
-
root.right = build(m + 1, r, root);
|
|
12083
|
-
root.parent = parent;
|
|
12084
|
-
const lh = root.left ? root.left.height : -1;
|
|
12085
|
-
const rh = root.right ? root.right.height : -1;
|
|
12086
|
-
root.height = Math.max(lh, rh) + 1;
|
|
12087
|
-
return root;
|
|
12088
|
-
}, "build");
|
|
12089
|
-
const newRoot = build(0, n - 1, void 0);
|
|
12090
|
-
this._setRoot(newRoot);
|
|
12091
|
-
this._size = n;
|
|
12092
|
-
return true;
|
|
12054
|
+
find(callbackfn, thisArg) {
|
|
12055
|
+
let index = 0;
|
|
12056
|
+
for (const v of this) {
|
|
12057
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12058
|
+
if (ok) return v;
|
|
12059
|
+
}
|
|
12060
|
+
return void 0;
|
|
12093
12061
|
}
|
|
12094
12062
|
/**
|
|
12095
|
-
*
|
|
12096
|
-
* @remarks Time O(
|
|
12097
|
-
* @template MK
|
|
12098
|
-
* @template MV
|
|
12099
|
-
* @template MR
|
|
12100
|
-
* @param callback - Function mapping (key, values, index, tree) → [newKey, newValue].
|
|
12101
|
-
* @param [options] - Options for the output tree.
|
|
12102
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
12103
|
-
* @returns The mapped AVLTree or AVLTreeMultiMap depending on MV; see overloads.
|
|
12063
|
+
* Materialize the set into an array of keys.
|
|
12064
|
+
* @remarks Time O(n), Space O(n)
|
|
12104
12065
|
*/
|
|
12105
|
-
|
|
12106
|
-
|
|
12107
|
-
let i = 0;
|
|
12108
|
-
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
12109
|
-
return out;
|
|
12066
|
+
toArray() {
|
|
12067
|
+
return [...this];
|
|
12110
12068
|
}
|
|
12111
12069
|
/**
|
|
12112
|
-
*
|
|
12113
|
-
* @remarks Time O(
|
|
12114
|
-
* @template TK
|
|
12115
|
-
* @template TV
|
|
12116
|
-
* @template TR
|
|
12117
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
12118
|
-
* @returns An empty like-kind instance.
|
|
12070
|
+
* Print a human-friendly representation.
|
|
12071
|
+
* @remarks Time O(n), Space O(n)
|
|
12119
12072
|
*/
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
const Ctor = this.constructor;
|
|
12123
|
-
return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
12073
|
+
print() {
|
|
12074
|
+
__privateGet(this, _core).print();
|
|
12124
12075
|
}
|
|
12076
|
+
// Navigable operations
|
|
12125
12077
|
/**
|
|
12126
|
-
*
|
|
12127
|
-
* @remarks Time O(N log N), Space O(N)
|
|
12128
|
-
* @template TK
|
|
12129
|
-
* @template TV
|
|
12130
|
-
* @template TR
|
|
12131
|
-
* @param iter - Iterable used to seed the new tree.
|
|
12132
|
-
* @param [options] - Options merged with the current snapshot.
|
|
12133
|
-
* @returns A like-kind AVLTree built from the iterable.
|
|
12078
|
+
* Smallest key in the set.
|
|
12134
12079
|
*/
|
|
12135
|
-
|
|
12136
|
-
|
|
12137
|
-
const Ctor = this.constructor;
|
|
12138
|
-
return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
12080
|
+
first() {
|
|
12081
|
+
return __privateGet(this, _core).getLeftMost();
|
|
12139
12082
|
}
|
|
12140
|
-
};
|
|
12141
|
-
__name(_AVLTreeMultiMap, "AVLTreeMultiMap");
|
|
12142
|
-
var AVLTreeMultiMap = _AVLTreeMultiMap;
|
|
12143
|
-
|
|
12144
|
-
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
12145
|
-
var _TreeMultiMapNode = class _TreeMultiMapNode {
|
|
12146
12083
|
/**
|
|
12147
|
-
*
|
|
12148
|
-
* @remarks Time O(1), Space O(1)
|
|
12149
|
-
* @param key - Key of the node.
|
|
12150
|
-
* @param [value] - Initial array of values.
|
|
12151
|
-
* @returns New TreeMultiMapNode instance.
|
|
12084
|
+
* Largest key in the set.
|
|
12152
12085
|
*/
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
__publicField(this, "value");
|
|
12156
|
-
__publicField(this, "parent");
|
|
12157
|
-
__publicField(this, "_left");
|
|
12158
|
-
__publicField(this, "_right");
|
|
12159
|
-
__publicField(this, "_height", 0);
|
|
12160
|
-
__publicField(this, "_color", "BLACK");
|
|
12161
|
-
__publicField(this, "_count", 1);
|
|
12162
|
-
this.key = key;
|
|
12163
|
-
this.value = value;
|
|
12164
|
-
this.color = color;
|
|
12086
|
+
last() {
|
|
12087
|
+
return __privateGet(this, _core).getRightMost();
|
|
12165
12088
|
}
|
|
12166
12089
|
/**
|
|
12167
|
-
*
|
|
12168
|
-
* @remarks Time O(1), Space O(1)
|
|
12169
|
-
* @returns Left child node, or null/undefined.
|
|
12090
|
+
* Remove and return the smallest key.
|
|
12170
12091
|
*/
|
|
12171
|
-
|
|
12172
|
-
|
|
12092
|
+
pollFirst() {
|
|
12093
|
+
const k = this.first();
|
|
12094
|
+
if (k === void 0) return void 0;
|
|
12095
|
+
this.delete(k);
|
|
12096
|
+
return k;
|
|
12173
12097
|
}
|
|
12174
12098
|
/**
|
|
12175
|
-
*
|
|
12176
|
-
* @remarks Time O(1), Space O(1)
|
|
12177
|
-
* @param v - New left child node, or null/undefined.
|
|
12178
|
-
* @returns void
|
|
12099
|
+
* Remove and return the largest key.
|
|
12179
12100
|
*/
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12101
|
+
pollLast() {
|
|
12102
|
+
const k = this.last();
|
|
12103
|
+
if (k === void 0) return void 0;
|
|
12104
|
+
this.delete(k);
|
|
12105
|
+
return k;
|
|
12185
12106
|
}
|
|
12186
12107
|
/**
|
|
12187
|
-
*
|
|
12188
|
-
* @remarks Time O(1), Space O(1)
|
|
12189
|
-
* @returns Right child node, or null/undefined.
|
|
12108
|
+
* Smallest key that is >= the given key.
|
|
12190
12109
|
*/
|
|
12191
|
-
|
|
12192
|
-
|
|
12110
|
+
ceiling(key) {
|
|
12111
|
+
this._validateKey(key);
|
|
12112
|
+
return __privateGet(this, _core).ceiling(key);
|
|
12193
12113
|
}
|
|
12194
12114
|
/**
|
|
12195
|
-
*
|
|
12196
|
-
* @remarks Time O(1), Space O(1)
|
|
12197
|
-
* @param v - New right child node, or null/undefined.
|
|
12198
|
-
* @returns void
|
|
12115
|
+
* Largest key that is <= the given key.
|
|
12199
12116
|
*/
|
|
12200
|
-
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
}
|
|
12204
|
-
this._right = v;
|
|
12117
|
+
floor(key) {
|
|
12118
|
+
this._validateKey(key);
|
|
12119
|
+
return __privateGet(this, _core).floor(key);
|
|
12205
12120
|
}
|
|
12206
12121
|
/**
|
|
12207
|
-
*
|
|
12208
|
-
* @remarks Time O(1), Space O(1)
|
|
12209
|
-
*
|
|
12210
|
-
* @returns The height.
|
|
12122
|
+
* Smallest key that is > the given key.
|
|
12211
12123
|
*/
|
|
12212
|
-
|
|
12213
|
-
|
|
12124
|
+
higher(key) {
|
|
12125
|
+
this._validateKey(key);
|
|
12126
|
+
return __privateGet(this, _core).higher(key);
|
|
12214
12127
|
}
|
|
12215
12128
|
/**
|
|
12216
|
-
*
|
|
12217
|
-
* @remarks Time O(1), Space O(1)
|
|
12218
|
-
*
|
|
12219
|
-
* @param value - The new height.
|
|
12129
|
+
* Largest key that is < the given key.
|
|
12220
12130
|
*/
|
|
12221
|
-
|
|
12222
|
-
this.
|
|
12131
|
+
lower(key) {
|
|
12132
|
+
this._validateKey(key);
|
|
12133
|
+
return __privateGet(this, _core).lower(key);
|
|
12223
12134
|
}
|
|
12224
12135
|
/**
|
|
12225
|
-
*
|
|
12226
|
-
* @remarks Time O(1), Space O(1)
|
|
12136
|
+
* Return all keys in a given range.
|
|
12227
12137
|
*
|
|
12228
|
-
* @
|
|
12138
|
+
* @param range `[low, high]`
|
|
12139
|
+
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
12229
12140
|
*/
|
|
12230
|
-
|
|
12231
|
-
|
|
12141
|
+
rangeSearch(range, options = {}) {
|
|
12142
|
+
const { lowInclusive = true, highInclusive = true } = options;
|
|
12143
|
+
const [low, high] = range;
|
|
12144
|
+
this._validateKey(low);
|
|
12145
|
+
this._validateKey(high);
|
|
12146
|
+
const keys = __privateGet(this, _core).rangeSearch([low, high]);
|
|
12147
|
+
const out = [];
|
|
12148
|
+
const cmp = __privateGet(this, _core).comparator;
|
|
12149
|
+
for (const k of keys) {
|
|
12150
|
+
if (k === void 0) continue;
|
|
12151
|
+
if (!lowInclusive && cmp(k, low) === 0) continue;
|
|
12152
|
+
if (!highInclusive && cmp(k, high) === 0) continue;
|
|
12153
|
+
out.push(k);
|
|
12154
|
+
}
|
|
12155
|
+
return out;
|
|
12156
|
+
}
|
|
12157
|
+
};
|
|
12158
|
+
_core = new WeakMap();
|
|
12159
|
+
_isDefaultComparator = new WeakMap();
|
|
12160
|
+
_userComparator = new WeakMap();
|
|
12161
|
+
__name(_TreeSet, "TreeSet");
|
|
12162
|
+
var TreeSet = _TreeSet;
|
|
12163
|
+
|
|
12164
|
+
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
12165
|
+
var _TreeMultiMapNode = class _TreeMultiMapNode extends RedBlackTreeNode {
|
|
12166
|
+
constructor(key, value = []) {
|
|
12167
|
+
super(key, value);
|
|
12232
12168
|
}
|
|
12169
|
+
};
|
|
12170
|
+
__name(_TreeMultiMapNode, "TreeMultiMapNode");
|
|
12171
|
+
var TreeMultiMapNode = _TreeMultiMapNode;
|
|
12172
|
+
var _core2, _isDefaultComparator2;
|
|
12173
|
+
var _TreeMultiMap = class _TreeMultiMap {
|
|
12233
12174
|
/**
|
|
12234
|
-
*
|
|
12175
|
+
* Creates a new TreeMultiMap.
|
|
12176
|
+
* @param keysNodesEntriesOrRaws - Initial entries
|
|
12177
|
+
* @param options - Configuration options
|
|
12178
|
+
* @remarks Time O(m log m), Space O(m) where m is the number of initial entries
|
|
12179
|
+
*/
|
|
12180
|
+
constructor(keysNodesEntriesOrRaws = [], options = {}) {
|
|
12181
|
+
__privateAdd(this, _core2);
|
|
12182
|
+
__privateAdd(this, _isDefaultComparator2);
|
|
12183
|
+
var _a;
|
|
12184
|
+
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
12185
|
+
__privateSet(this, _isDefaultComparator2, options.comparator === void 0);
|
|
12186
|
+
__privateSet(this, _core2, new RedBlackTree([], { ...options, comparator, isMapMode: options.isMapMode }));
|
|
12187
|
+
for (const x of keysNodesEntriesOrRaws) {
|
|
12188
|
+
if (x === null || x === void 0) continue;
|
|
12189
|
+
if (Array.isArray(x)) {
|
|
12190
|
+
const [k, bucket] = x;
|
|
12191
|
+
if (k === null || k === void 0) continue;
|
|
12192
|
+
if (bucket !== void 0) {
|
|
12193
|
+
__privateGet(this, _core2).set(k, [...bucket]);
|
|
12194
|
+
} else {
|
|
12195
|
+
__privateGet(this, _core2).set(k, []);
|
|
12196
|
+
}
|
|
12197
|
+
continue;
|
|
12198
|
+
}
|
|
12199
|
+
__privateGet(this, _core2).set(x, []);
|
|
12200
|
+
}
|
|
12201
|
+
}
|
|
12202
|
+
/**
|
|
12203
|
+
* Validates the key against the default comparator rules.
|
|
12235
12204
|
* @remarks Time O(1), Space O(1)
|
|
12236
|
-
*
|
|
12237
|
-
* @param value - The new color.
|
|
12238
12205
|
*/
|
|
12239
|
-
|
|
12240
|
-
this
|
|
12206
|
+
_validateKey(key) {
|
|
12207
|
+
if (!__privateGet(this, _isDefaultComparator2)) return;
|
|
12208
|
+
if (typeof key === "number") {
|
|
12209
|
+
if (Number.isNaN(key)) throw new TypeError("TreeMultiMap: NaN is not a valid key");
|
|
12210
|
+
return;
|
|
12211
|
+
}
|
|
12212
|
+
if (typeof key === "string") return;
|
|
12213
|
+
if (key instanceof Date) {
|
|
12214
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeMultiMap: invalid Date key");
|
|
12215
|
+
return;
|
|
12216
|
+
}
|
|
12217
|
+
throw new TypeError("TreeMultiMap: comparator is required for non-number/non-string/non-Date keys");
|
|
12241
12218
|
}
|
|
12242
12219
|
/**
|
|
12243
|
-
*
|
|
12220
|
+
* Number of distinct keys.
|
|
12244
12221
|
* @remarks Time O(1), Space O(1)
|
|
12245
|
-
*
|
|
12246
|
-
* @returns The subtree node count.
|
|
12247
12222
|
*/
|
|
12248
|
-
get
|
|
12249
|
-
return this.
|
|
12223
|
+
get size() {
|
|
12224
|
+
return __privateGet(this, _core2).size;
|
|
12250
12225
|
}
|
|
12251
12226
|
/**
|
|
12252
|
-
*
|
|
12227
|
+
* Whether the map is empty.
|
|
12253
12228
|
* @remarks Time O(1), Space O(1)
|
|
12254
|
-
*
|
|
12255
|
-
* @param value - The new count.
|
|
12256
12229
|
*/
|
|
12257
|
-
|
|
12258
|
-
this.
|
|
12230
|
+
isEmpty() {
|
|
12231
|
+
return this.size === 0;
|
|
12259
12232
|
}
|
|
12260
12233
|
/**
|
|
12261
|
-
*
|
|
12234
|
+
* Removes all entries from the map.
|
|
12262
12235
|
* @remarks Time O(1), Space O(1)
|
|
12263
|
-
*
|
|
12264
|
-
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
12265
12236
|
*/
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
12269
|
-
}
|
|
12270
|
-
if (this.parent.left === this) {
|
|
12271
|
-
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
12272
|
-
} else if (this.parent.right === this) {
|
|
12273
|
-
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
12274
|
-
}
|
|
12275
|
-
return "MAL_NODE";
|
|
12237
|
+
clear() {
|
|
12238
|
+
__privateGet(this, _core2).clear();
|
|
12276
12239
|
}
|
|
12277
|
-
};
|
|
12278
|
-
__name(_TreeMultiMapNode, "TreeMultiMapNode");
|
|
12279
|
-
var TreeMultiMapNode = _TreeMultiMapNode;
|
|
12280
|
-
var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
12281
12240
|
/**
|
|
12282
|
-
*
|
|
12283
|
-
* @remarks Time O(
|
|
12284
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
12285
|
-
* @param [options] - Options for TreeMultiMap (comparator, reverse, map mode).
|
|
12286
|
-
* @returns New TreeMultiMap instance.
|
|
12241
|
+
* Bucket length for a key (missing => 0).
|
|
12242
|
+
* @remarks Time O(log n), Space O(1)
|
|
12287
12243
|
*/
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
this.setMany(keysNodesEntriesOrRaws);
|
|
12292
|
-
}
|
|
12244
|
+
count(key) {
|
|
12245
|
+
const b = this.get(key);
|
|
12246
|
+
return Array.isArray(b) ? b.length : 0;
|
|
12293
12247
|
}
|
|
12294
|
-
|
|
12295
|
-
|
|
12248
|
+
/**
|
|
12249
|
+
* Total number of values across all buckets (Σ bucket.length).
|
|
12250
|
+
* @remarks Time O(n), Space O(1)
|
|
12251
|
+
*/
|
|
12252
|
+
get totalSize() {
|
|
12253
|
+
let sum = 0;
|
|
12254
|
+
for (const [, bucket] of this) sum += bucket.length;
|
|
12255
|
+
return sum;
|
|
12296
12256
|
}
|
|
12297
12257
|
/**
|
|
12298
|
-
*
|
|
12299
|
-
* @remarks Time O(
|
|
12300
|
-
*
|
|
12301
|
-
* @param keyNodeOrEntry - The item to check.
|
|
12302
|
-
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
12258
|
+
* Whether the map contains the given key.
|
|
12259
|
+
* @remarks Time O(log n), Space O(1)
|
|
12303
12260
|
*/
|
|
12304
|
-
|
|
12305
|
-
|
|
12261
|
+
has(key) {
|
|
12262
|
+
this._validateKey(key);
|
|
12263
|
+
return __privateGet(this, _core2).has(key);
|
|
12306
12264
|
}
|
|
12307
12265
|
/**
|
|
12308
|
-
*
|
|
12309
|
-
* @remarks Time O(log
|
|
12310
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
12311
|
-
* @param [value] - Single value to set when a bare key is provided.
|
|
12312
|
-
* @returns True if inserted or appended; false if ignored.
|
|
12266
|
+
* Live bucket reference (do not auto-delete key if bucket becomes empty via mutation).
|
|
12267
|
+
* @remarks Time O(log n), Space O(1)
|
|
12313
12268
|
*/
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
|
|
12317
|
-
if (key === void 0 || key === null) return false;
|
|
12318
|
-
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
12319
|
-
const existingValues = this.get(key);
|
|
12320
|
-
if (existingValues !== void 0 && values !== void 0) {
|
|
12321
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12322
|
-
return true;
|
|
12323
|
-
}
|
|
12324
|
-
return false;
|
|
12325
|
-
}, "_setToValues");
|
|
12326
|
-
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
12327
|
-
const existingNode = this.getNode(key);
|
|
12328
|
-
if (this.isRealNode(existingNode)) {
|
|
12329
|
-
const existingValues = this.get(existingNode);
|
|
12330
|
-
if (existingValues === void 0) {
|
|
12331
|
-
super.set(key, values);
|
|
12332
|
-
return true;
|
|
12333
|
-
}
|
|
12334
|
-
if (values !== void 0) {
|
|
12335
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12336
|
-
return true;
|
|
12337
|
-
} else {
|
|
12338
|
-
return false;
|
|
12339
|
-
}
|
|
12340
|
-
} else {
|
|
12341
|
-
return super.set(key, values);
|
|
12342
|
-
}
|
|
12343
|
-
}, "_setByNode");
|
|
12344
|
-
if (this._isMapMode) {
|
|
12345
|
-
return _setByNode() || _setToValues();
|
|
12346
|
-
}
|
|
12347
|
-
return _setToValues() || _setByNode();
|
|
12348
|
-
}, "_commonAdd");
|
|
12349
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
12350
|
-
const [key, values] = keyNodeOrEntry;
|
|
12351
|
-
return _commonAdd(key, value !== void 0 ? [value] : values);
|
|
12352
|
-
}
|
|
12353
|
-
return _commonAdd(keyNodeOrEntry, value !== void 0 ? [value] : void 0);
|
|
12269
|
+
get(key) {
|
|
12270
|
+
this._validateKey(key);
|
|
12271
|
+
return __privateGet(this, _core2).get(key);
|
|
12354
12272
|
}
|
|
12355
12273
|
/**
|
|
12356
|
-
*
|
|
12357
|
-
* @remarks Time O(log
|
|
12358
|
-
|
|
12359
|
-
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
if (Array.isArray(values)) {
|
|
12365
|
-
const index = values.indexOf(value);
|
|
12366
|
-
if (index === -1) return false;
|
|
12367
|
-
values.splice(index, 1);
|
|
12368
|
-
if (values.length === 0) this.delete(keyNodeOrEntry);
|
|
12274
|
+
* Append a single value.
|
|
12275
|
+
* @remarks Time O(log n), Space O(1)
|
|
12276
|
+
*/
|
|
12277
|
+
add(key, value) {
|
|
12278
|
+
this._validateKey(key);
|
|
12279
|
+
const bucket = __privateGet(this, _core2).get(key);
|
|
12280
|
+
if (bucket) {
|
|
12281
|
+
bucket.push(value);
|
|
12369
12282
|
return true;
|
|
12370
12283
|
}
|
|
12371
|
-
return
|
|
12284
|
+
return __privateGet(this, _core2).set(key, [value]);
|
|
12285
|
+
}
|
|
12286
|
+
set(entry, value) {
|
|
12287
|
+
if (entry === null || entry === void 0) return false;
|
|
12288
|
+
if (Array.isArray(entry)) {
|
|
12289
|
+
const [k, bucket] = entry;
|
|
12290
|
+
if (k === null || k === void 0) return false;
|
|
12291
|
+
if (value !== void 0) return this.add(k, value);
|
|
12292
|
+
if (bucket === void 0) {
|
|
12293
|
+
return __privateGet(this, _core2).set(k, []);
|
|
12294
|
+
}
|
|
12295
|
+
const existing = __privateGet(this, _core2).get(k);
|
|
12296
|
+
if (existing) {
|
|
12297
|
+
existing.push(...bucket);
|
|
12298
|
+
return true;
|
|
12299
|
+
}
|
|
12300
|
+
return __privateGet(this, _core2).set(k, [...bucket]);
|
|
12301
|
+
}
|
|
12302
|
+
if (value !== void 0) return this.add(entry, value);
|
|
12303
|
+
return __privateGet(this, _core2).set(entry, []);
|
|
12372
12304
|
}
|
|
12373
12305
|
/**
|
|
12374
|
-
*
|
|
12375
|
-
* @remarks Time O(
|
|
12376
|
-
* @template MK
|
|
12377
|
-
* @template MV
|
|
12378
|
-
* @template MR
|
|
12379
|
-
* @param callback - Function mapping (key, values, index, tree) → [newKey, newValue].
|
|
12380
|
-
* @param [options] - Options for the output tree.
|
|
12381
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
12382
|
-
* @returns A new RedBlackTree (or TreeMultiMap when mapping to array values; see overloads).
|
|
12306
|
+
* Deletes a key and its entire bucket.
|
|
12307
|
+
* @remarks Time O(log n), Space O(1)
|
|
12383
12308
|
*/
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
12388
|
-
return out;
|
|
12309
|
+
delete(key) {
|
|
12310
|
+
this._validateKey(key);
|
|
12311
|
+
return __privateGet(this, _core2).delete(key).length > 0;
|
|
12389
12312
|
}
|
|
12390
12313
|
/**
|
|
12391
|
-
*
|
|
12392
|
-
* @remarks Time O(
|
|
12393
|
-
* @template TK
|
|
12394
|
-
* @template TV
|
|
12395
|
-
* @template TR
|
|
12396
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
12397
|
-
* @returns An empty like-kind instance.
|
|
12314
|
+
* Check if a specific value exists in a key's bucket.
|
|
12315
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12398
12316
|
*/
|
|
12399
|
-
|
|
12400
|
-
|
|
12401
|
-
|
|
12402
|
-
return
|
|
12317
|
+
hasEntry(key, value, eq = Object.is) {
|
|
12318
|
+
const bucket = this.get(key);
|
|
12319
|
+
if (!Array.isArray(bucket)) return false;
|
|
12320
|
+
return bucket.some((v) => eq(v, value));
|
|
12403
12321
|
}
|
|
12404
12322
|
/**
|
|
12405
|
-
*
|
|
12406
|
-
* @remarks Time O(
|
|
12407
|
-
* @template TK
|
|
12408
|
-
* @template TV
|
|
12409
|
-
* @template TR
|
|
12410
|
-
* @param iter - Iterable used to seed the new tree.
|
|
12411
|
-
* @param [options] - Options merged with the current snapshot.
|
|
12412
|
-
* @returns A like-kind RedBlackTree built from the iterable.
|
|
12323
|
+
* Delete a single occurrence of a value from a key's bucket.
|
|
12324
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12413
12325
|
*/
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12326
|
+
deleteValue(key, value, eq = Object.is) {
|
|
12327
|
+
const bucket = this.get(key);
|
|
12328
|
+
if (!Array.isArray(bucket)) return false;
|
|
12329
|
+
const idx = bucket.findIndex((v) => eq(v, value));
|
|
12330
|
+
if (idx === -1) return false;
|
|
12331
|
+
bucket.splice(idx, 1);
|
|
12332
|
+
if (bucket.length === 0) this.delete(key);
|
|
12333
|
+
return true;
|
|
12418
12334
|
}
|
|
12419
|
-
};
|
|
12420
|
-
__name(_TreeMultiMap, "TreeMultiMap");
|
|
12421
|
-
var TreeMultiMap = _TreeMultiMap;
|
|
12422
|
-
|
|
12423
|
-
// src/data-structures/binary-tree/tree-counter.ts
|
|
12424
|
-
var _TreeCounterNode = class _TreeCounterNode {
|
|
12425
12335
|
/**
|
|
12426
|
-
*
|
|
12427
|
-
* @remarks Time O(
|
|
12428
|
-
* @param key - Key of the node.
|
|
12429
|
-
* @param [value] - Value associated with the key (ignored in map mode).
|
|
12430
|
-
* @param [count] - Initial count for this node (default 1).
|
|
12431
|
-
* @param color - Initial color ('RED' or 'BLACK').
|
|
12432
|
-
* @returns New TreeCounterNode instance.
|
|
12336
|
+
* Delete all occurrences of a value from a key's bucket.
|
|
12337
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12433
12338
|
*/
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
this.count = count;
|
|
12339
|
+
deleteValues(key, value, eq = Object.is) {
|
|
12340
|
+
const bucket = this.get(key);
|
|
12341
|
+
if (!Array.isArray(bucket) || bucket.length === 0) return 0;
|
|
12342
|
+
let removed = 0;
|
|
12343
|
+
for (let i = bucket.length - 1; i >= 0; i--) {
|
|
12344
|
+
if (eq(bucket[i], value)) {
|
|
12345
|
+
bucket.splice(i, 1);
|
|
12346
|
+
removed++;
|
|
12347
|
+
}
|
|
12348
|
+
}
|
|
12349
|
+
if (bucket.length === 0 && removed > 0) this.delete(key);
|
|
12350
|
+
return removed;
|
|
12447
12351
|
}
|
|
12352
|
+
// ---- iteration (bucket view) ----
|
|
12448
12353
|
/**
|
|
12449
|
-
*
|
|
12450
|
-
* @remarks Time O(
|
|
12451
|
-
* @returns Left child node, or null/undefined.
|
|
12354
|
+
* Iterates over all entries as [key, bucket] pairs.
|
|
12355
|
+
* @remarks Time O(n), Space O(1)
|
|
12452
12356
|
*/
|
|
12453
|
-
|
|
12454
|
-
|
|
12357
|
+
*[Symbol.iterator]() {
|
|
12358
|
+
for (const [k, v] of __privateGet(this, _core2)) {
|
|
12359
|
+
yield [k, v != null ? v : []];
|
|
12360
|
+
}
|
|
12455
12361
|
}
|
|
12456
12362
|
/**
|
|
12457
|
-
*
|
|
12458
|
-
* @remarks Time O(
|
|
12459
|
-
* @param v - New left child node, or null/undefined.
|
|
12460
|
-
* @returns void
|
|
12363
|
+
* Iterates over all keys.
|
|
12364
|
+
* @remarks Time O(n), Space O(1)
|
|
12461
12365
|
*/
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
v.parent = this;
|
|
12465
|
-
}
|
|
12466
|
-
this._left = v;
|
|
12366
|
+
*keys() {
|
|
12367
|
+
yield* __privateGet(this, _core2).keys();
|
|
12467
12368
|
}
|
|
12468
12369
|
/**
|
|
12469
|
-
*
|
|
12470
|
-
* @remarks Time O(
|
|
12471
|
-
* @returns Right child node, or null/undefined.
|
|
12370
|
+
* Iterates over all buckets.
|
|
12371
|
+
* @remarks Time O(n), Space O(1)
|
|
12472
12372
|
*/
|
|
12473
|
-
|
|
12474
|
-
|
|
12373
|
+
*values() {
|
|
12374
|
+
for (const [, bucket] of this) yield bucket;
|
|
12475
12375
|
}
|
|
12376
|
+
// ---- entry-flat views ----
|
|
12476
12377
|
/**
|
|
12477
|
-
*
|
|
12478
|
-
* @remarks Time O(
|
|
12479
|
-
* @param v - New right child node, or null/undefined.
|
|
12480
|
-
* @returns void
|
|
12378
|
+
* Iterates over all entries for a specific key.
|
|
12379
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12481
12380
|
*/
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
this._right = v;
|
|
12381
|
+
*entriesOf(key) {
|
|
12382
|
+
const bucket = this.get(key);
|
|
12383
|
+
if (!Array.isArray(bucket)) return;
|
|
12384
|
+
for (const v of bucket) yield [key, v];
|
|
12487
12385
|
}
|
|
12488
12386
|
/**
|
|
12489
|
-
*
|
|
12490
|
-
* @remarks Time O(
|
|
12491
|
-
*
|
|
12492
|
-
* @returns The height.
|
|
12387
|
+
* Iterates over all values for a specific key.
|
|
12388
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12493
12389
|
*/
|
|
12494
|
-
|
|
12495
|
-
|
|
12390
|
+
*valuesOf(key) {
|
|
12391
|
+
const bucket = this.get(key);
|
|
12392
|
+
if (!Array.isArray(bucket)) return;
|
|
12393
|
+
yield* bucket;
|
|
12496
12394
|
}
|
|
12497
12395
|
/**
|
|
12498
|
-
*
|
|
12499
|
-
* @remarks Time O(
|
|
12500
|
-
*
|
|
12501
|
-
* @param value - The new height.
|
|
12396
|
+
* Iterates over all [key, value] pairs (flattened from buckets).
|
|
12397
|
+
* @remarks Time O(T), Space O(1) where T is totalSize
|
|
12502
12398
|
*/
|
|
12503
|
-
|
|
12504
|
-
this
|
|
12399
|
+
*flatEntries() {
|
|
12400
|
+
for (const [k, bucket] of this) {
|
|
12401
|
+
for (const v of bucket) yield [k, v];
|
|
12402
|
+
}
|
|
12505
12403
|
}
|
|
12404
|
+
// ━━━ Navigable methods (return [K, V[]] | undefined) ━━━
|
|
12506
12405
|
/**
|
|
12507
|
-
*
|
|
12508
|
-
* @remarks Time O(
|
|
12509
|
-
*
|
|
12510
|
-
*
|
|
12406
|
+
* Returns the entry with the smallest key.
|
|
12407
|
+
* @remarks Time O(log n), Space O(1)
|
|
12408
|
+
* @example
|
|
12409
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12410
|
+
* map.first(); // [1, ['a']]
|
|
12511
12411
|
*/
|
|
12512
|
-
|
|
12513
|
-
|
|
12412
|
+
first() {
|
|
12413
|
+
const k = __privateGet(this, _core2).getLeftMost();
|
|
12414
|
+
if (k === void 0) return void 0;
|
|
12415
|
+
const b = this.get(k);
|
|
12416
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12514
12417
|
}
|
|
12515
12418
|
/**
|
|
12516
|
-
*
|
|
12517
|
-
* @remarks Time O(
|
|
12518
|
-
*
|
|
12519
|
-
*
|
|
12419
|
+
* Returns the entry with the largest key.
|
|
12420
|
+
* @remarks Time O(log n), Space O(1)
|
|
12421
|
+
* @example
|
|
12422
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12423
|
+
* map.last(); // [2, ['b']]
|
|
12520
12424
|
*/
|
|
12521
|
-
|
|
12522
|
-
|
|
12425
|
+
last() {
|
|
12426
|
+
const k = __privateGet(this, _core2).getRightMost();
|
|
12427
|
+
if (k === void 0) return void 0;
|
|
12428
|
+
const b = this.get(k);
|
|
12429
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12523
12430
|
}
|
|
12524
12431
|
/**
|
|
12525
|
-
*
|
|
12526
|
-
* @remarks Time O(
|
|
12527
|
-
*
|
|
12528
|
-
*
|
|
12432
|
+
* Removes and returns the entry with the smallest key.
|
|
12433
|
+
* @remarks Time O(log n), Space O(1)
|
|
12434
|
+
* @example
|
|
12435
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12436
|
+
* map.pollFirst(); // [1, ['a']]
|
|
12437
|
+
* map.has(1); // false
|
|
12529
12438
|
*/
|
|
12530
|
-
|
|
12531
|
-
|
|
12439
|
+
pollFirst() {
|
|
12440
|
+
const e = this.first();
|
|
12441
|
+
if (!e) return void 0;
|
|
12442
|
+
this.delete(e[0]);
|
|
12443
|
+
return e;
|
|
12532
12444
|
}
|
|
12533
12445
|
/**
|
|
12534
|
-
*
|
|
12535
|
-
* @remarks Time O(
|
|
12536
|
-
*
|
|
12537
|
-
*
|
|
12446
|
+
* Removes and returns the entry with the largest key.
|
|
12447
|
+
* @remarks Time O(log n), Space O(1)
|
|
12448
|
+
* @example
|
|
12449
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12450
|
+
* map.pollLast(); // [2, ['b']]
|
|
12451
|
+
* map.has(2); // false
|
|
12538
12452
|
*/
|
|
12539
|
-
|
|
12540
|
-
|
|
12453
|
+
pollLast() {
|
|
12454
|
+
const e = this.last();
|
|
12455
|
+
if (!e) return void 0;
|
|
12456
|
+
this.delete(e[0]);
|
|
12457
|
+
return e;
|
|
12541
12458
|
}
|
|
12542
12459
|
/**
|
|
12543
|
-
*
|
|
12544
|
-
* @remarks Time O(
|
|
12545
|
-
*
|
|
12546
|
-
*
|
|
12460
|
+
* Returns the entry with the smallest key >= given key.
|
|
12461
|
+
* @remarks Time O(log n), Space O(1)
|
|
12462
|
+
* @example
|
|
12463
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12464
|
+
* map.ceiling(15); // [20, ['b']]
|
|
12465
|
+
* map.ceiling(20); // [20, ['b']]
|
|
12547
12466
|
*/
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
} else if (this.parent.right === this) {
|
|
12555
|
-
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
12556
|
-
}
|
|
12557
|
-
return "MAL_NODE";
|
|
12467
|
+
ceiling(key) {
|
|
12468
|
+
this._validateKey(key);
|
|
12469
|
+
const k = __privateGet(this, _core2).ceiling(key);
|
|
12470
|
+
if (k === void 0) return void 0;
|
|
12471
|
+
const b = this.get(k);
|
|
12472
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12558
12473
|
}
|
|
12559
|
-
};
|
|
12560
|
-
__name(_TreeCounterNode, "TreeCounterNode");
|
|
12561
|
-
var TreeCounterNode = _TreeCounterNode;
|
|
12562
|
-
var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
12563
12474
|
/**
|
|
12564
|
-
*
|
|
12565
|
-
* @remarks Time O(
|
|
12566
|
-
* @
|
|
12567
|
-
*
|
|
12568
|
-
*
|
|
12475
|
+
* Returns the entry with the largest key <= given key.
|
|
12476
|
+
* @remarks Time O(log n), Space O(1)
|
|
12477
|
+
* @example
|
|
12478
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12479
|
+
* map.floor(25); // [20, ['b']]
|
|
12480
|
+
* map.floor(20); // [20, ['b']]
|
|
12481
|
+
*/
|
|
12482
|
+
floor(key) {
|
|
12483
|
+
this._validateKey(key);
|
|
12484
|
+
const k = __privateGet(this, _core2).floor(key);
|
|
12485
|
+
if (k === void 0) return void 0;
|
|
12486
|
+
const b = this.get(k);
|
|
12487
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12488
|
+
}
|
|
12489
|
+
/**
|
|
12490
|
+
* Returns the entry with the smallest key > given key.
|
|
12491
|
+
* @remarks Time O(log n), Space O(1)
|
|
12492
|
+
* @example
|
|
12493
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12494
|
+
* map.higher(10); // [20, ['b']]
|
|
12495
|
+
* map.higher(15); // [20, ['b']]
|
|
12569
12496
|
*/
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
if (
|
|
12497
|
+
higher(key) {
|
|
12498
|
+
this._validateKey(key);
|
|
12499
|
+
const k = __privateGet(this, _core2).higher(key);
|
|
12500
|
+
if (k === void 0) return void 0;
|
|
12501
|
+
const b = this.get(k);
|
|
12502
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12574
12503
|
}
|
|
12575
12504
|
/**
|
|
12576
|
-
*
|
|
12577
|
-
* @remarks Time O(
|
|
12578
|
-
* @
|
|
12505
|
+
* Returns the entry with the largest key < given key.
|
|
12506
|
+
* @remarks Time O(log n), Space O(1)
|
|
12507
|
+
* @example
|
|
12508
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12509
|
+
* map.lower(20); // [10, ['a']]
|
|
12510
|
+
* map.lower(15); // [10, ['a']]
|
|
12579
12511
|
*/
|
|
12580
|
-
|
|
12581
|
-
|
|
12512
|
+
lower(key) {
|
|
12513
|
+
this._validateKey(key);
|
|
12514
|
+
const k = __privateGet(this, _core2).lower(key);
|
|
12515
|
+
if (k === void 0) return void 0;
|
|
12516
|
+
const b = this.get(k);
|
|
12517
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12582
12518
|
}
|
|
12519
|
+
// ━━━ Tree utilities ━━━
|
|
12583
12520
|
/**
|
|
12584
|
-
*
|
|
12585
|
-
* @remarks Time O(
|
|
12586
|
-
* @returns Total count recomputed from nodes.
|
|
12521
|
+
* Prints the internal tree structure (for debugging).
|
|
12522
|
+
* @remarks Time O(n), Space O(n)
|
|
12587
12523
|
*/
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
this.dfs((node) => sum += node ? node.count : 0);
|
|
12591
|
-
return sum;
|
|
12524
|
+
print(...args) {
|
|
12525
|
+
return __privateGet(this, _core2).print(...args);
|
|
12592
12526
|
}
|
|
12593
|
-
|
|
12594
|
-
|
|
12527
|
+
/**
|
|
12528
|
+
* Executes a callback for each entry.
|
|
12529
|
+
* @remarks Time O(n), Space O(1)
|
|
12530
|
+
*/
|
|
12531
|
+
forEach(callback) {
|
|
12532
|
+
for (const [k, v] of this) {
|
|
12533
|
+
callback(v, k, this);
|
|
12534
|
+
}
|
|
12595
12535
|
}
|
|
12596
12536
|
/**
|
|
12597
|
-
*
|
|
12598
|
-
* @remarks Time O(
|
|
12599
|
-
* @returns True if the value is a TreeCounterNode.
|
|
12537
|
+
* Creates a new map with entries that pass the predicate.
|
|
12538
|
+
* @remarks Time O(n), Space O(n)
|
|
12600
12539
|
*/
|
|
12601
|
-
|
|
12602
|
-
|
|
12540
|
+
filter(predicate) {
|
|
12541
|
+
const filtered = [];
|
|
12542
|
+
for (const [k, v] of this) {
|
|
12543
|
+
if (predicate(v, k, this)) filtered.push([k, v]);
|
|
12544
|
+
}
|
|
12545
|
+
return new _TreeMultiMap(filtered, { comparator: this.comparator });
|
|
12603
12546
|
}
|
|
12604
12547
|
/**
|
|
12605
|
-
*
|
|
12606
|
-
* @remarks Time O(log
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
set(keyNodeOrEntry, value, count = 1) {
|
|
12613
|
-
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12614
|
-
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12615
|
-
const isSuccessAdded = super.set(newNode, newValue);
|
|
12616
|
-
if (isSuccessAdded) {
|
|
12617
|
-
this._count += orgCount;
|
|
12618
|
-
return true;
|
|
12619
|
-
} else {
|
|
12620
|
-
return false;
|
|
12548
|
+
* Creates a new map by transforming each entry.
|
|
12549
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12550
|
+
*/
|
|
12551
|
+
map(mapper) {
|
|
12552
|
+
const mapped = [];
|
|
12553
|
+
for (const [k, v] of this) {
|
|
12554
|
+
mapped.push(mapper(v, k, this));
|
|
12621
12555
|
}
|
|
12556
|
+
return new _TreeMultiMap(mapped, { comparator: this.comparator });
|
|
12622
12557
|
}
|
|
12623
12558
|
/**
|
|
12624
|
-
*
|
|
12625
|
-
* @remarks Time O(
|
|
12626
|
-
* @param keyNodeEntryRawOrPredicate - Key, node, or [key, value] entry identifying the node.
|
|
12627
|
-
* @param [ignoreCount] - If true, remove the node regardless of its count.
|
|
12628
|
-
* @returns Array of deletion results including deleted node and a rebalance hint when present.
|
|
12559
|
+
* Reduces all entries to a single value.
|
|
12560
|
+
* @remarks Time O(n), Space O(1)
|
|
12629
12561
|
*/
|
|
12630
|
-
|
|
12631
|
-
|
|
12562
|
+
reduce(callback, initialValue) {
|
|
12563
|
+
let acc = initialValue;
|
|
12564
|
+
for (const [k, v] of this) {
|
|
12565
|
+
acc = callback(acc, v, k, this);
|
|
12566
|
+
}
|
|
12567
|
+
return acc;
|
|
12568
|
+
}
|
|
12569
|
+
/**
|
|
12570
|
+
* Sets multiple entries at once.
|
|
12571
|
+
* @remarks Time O(m log n), Space O(m) where m is input size
|
|
12572
|
+
*/
|
|
12573
|
+
setMany(keysNodesEntriesOrRaws) {
|
|
12632
12574
|
const results = [];
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
else nodeToDelete = this.isRealNode(keyNodeEntryRawOrPredicate) ? keyNodeEntryRawOrPredicate : this.getNode(keyNodeEntryRawOrPredicate);
|
|
12636
|
-
if (!nodeToDelete) {
|
|
12637
|
-
return results;
|
|
12575
|
+
for (const x of keysNodesEntriesOrRaws) {
|
|
12576
|
+
results.push(this.set(x, void 0));
|
|
12638
12577
|
}
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12642
|
-
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
|
|
12681
|
-
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
}
|
|
12690
|
-
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
12691
|
-
this._transplant(nodeToDelete, successor);
|
|
12692
|
-
this._count -= nodeToDelete.count;
|
|
12693
|
-
} else {
|
|
12694
|
-
nodeToDelete.count--;
|
|
12695
|
-
this._count--;
|
|
12696
|
-
results.push({ deleted: nodeToDelete, needBalanced: void 0 });
|
|
12697
|
-
return results;
|
|
12698
|
-
}
|
|
12699
|
-
successor.left = nodeToDelete.left;
|
|
12700
|
-
if (this.isRealNode(successor.left)) {
|
|
12701
|
-
successor.left.parent = successor;
|
|
12702
|
-
}
|
|
12703
|
-
successor.color = nodeToDelete.color;
|
|
12578
|
+
return results;
|
|
12579
|
+
}
|
|
12580
|
+
/**
|
|
12581
|
+
* Searches for entries within a key range.
|
|
12582
|
+
* @remarks Time O(log n + k), Space O(k) where k is result size
|
|
12583
|
+
*/
|
|
12584
|
+
rangeSearch(range, callback, isBalanced) {
|
|
12585
|
+
return __privateGet(this, _core2).rangeSearch(range, callback, isBalanced);
|
|
12586
|
+
}
|
|
12587
|
+
/**
|
|
12588
|
+
* Creates a shallow clone of this map.
|
|
12589
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12590
|
+
*/
|
|
12591
|
+
clone() {
|
|
12592
|
+
return new _TreeMultiMap(this, { comparator: this.comparator, isMapMode: __privateGet(this, _core2)._isMapMode });
|
|
12593
|
+
}
|
|
12594
|
+
/**
|
|
12595
|
+
* Expose comparator for advanced usage/testing (read-only).
|
|
12596
|
+
* @remarks Time O(1), Space O(1)
|
|
12597
|
+
*/
|
|
12598
|
+
get comparator() {
|
|
12599
|
+
return __privateGet(this, _core2)._comparator;
|
|
12600
|
+
}
|
|
12601
|
+
};
|
|
12602
|
+
_core2 = new WeakMap();
|
|
12603
|
+
_isDefaultComparator2 = new WeakMap();
|
|
12604
|
+
__name(_TreeMultiMap, "TreeMultiMap");
|
|
12605
|
+
var TreeMultiMap = _TreeMultiMap;
|
|
12606
|
+
|
|
12607
|
+
// src/data-structures/binary-tree/tree-map.ts
|
|
12608
|
+
var _core3, _isDefaultComparator3, _userComparator2;
|
|
12609
|
+
var _TreeMap = class _TreeMap {
|
|
12610
|
+
/**
|
|
12611
|
+
* Create a TreeMap from an iterable of `[key, value]` entries.
|
|
12612
|
+
*
|
|
12613
|
+
* @throws {TypeError} If any entry is not a 2-tuple-like value, or when using the default comparator
|
|
12614
|
+
* and encountering unsupported/invalid keys (e.g. `NaN`, invalid `Date`).
|
|
12615
|
+
*/
|
|
12616
|
+
constructor(entries = [], options = {}) {
|
|
12617
|
+
__privateAdd(this, _core3);
|
|
12618
|
+
__privateAdd(this, _isDefaultComparator3);
|
|
12619
|
+
__privateAdd(this, _userComparator2);
|
|
12620
|
+
var _a;
|
|
12621
|
+
__privateSet(this, _userComparator2, options.comparator);
|
|
12622
|
+
const comparator = (_a = options.comparator) != null ? _a : _TreeMap.createDefaultComparator();
|
|
12623
|
+
__privateSet(this, _isDefaultComparator3, options.comparator === void 0);
|
|
12624
|
+
__privateSet(this, _core3, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
12625
|
+
for (const item of entries) {
|
|
12626
|
+
if (!Array.isArray(item) || item.length < 2) {
|
|
12627
|
+
throw new TypeError("TreeMap: each entry must be a [key, value] tuple");
|
|
12704
12628
|
}
|
|
12629
|
+
const k = item[0];
|
|
12630
|
+
const v = item[1];
|
|
12631
|
+
this.set(k, v);
|
|
12705
12632
|
}
|
|
12706
|
-
|
|
12707
|
-
|
|
12708
|
-
|
|
12633
|
+
}
|
|
12634
|
+
/**
|
|
12635
|
+
* Create the strict default comparator.
|
|
12636
|
+
*
|
|
12637
|
+
* Supports:
|
|
12638
|
+
* - `number` (rejects `NaN`; treats `-0` and `0` as equal)
|
|
12639
|
+
* - `string`
|
|
12640
|
+
* - `Date` (orders by `getTime()`, rejects invalid dates)
|
|
12641
|
+
*
|
|
12642
|
+
* For other key types, a custom comparator must be provided.
|
|
12643
|
+
*/
|
|
12644
|
+
static createDefaultComparator() {
|
|
12645
|
+
return (a, b) => {
|
|
12646
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
12647
|
+
if (Number.isNaN(a) || Number.isNaN(b)) throw new TypeError("TreeMap: NaN is not a valid key");
|
|
12648
|
+
const aa = Object.is(a, -0) ? 0 : a;
|
|
12649
|
+
const bb = Object.is(b, -0) ? 0 : b;
|
|
12650
|
+
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
12651
|
+
}
|
|
12652
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
12653
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
12654
|
+
}
|
|
12655
|
+
if (a instanceof Date && b instanceof Date) {
|
|
12656
|
+
const ta = a.getTime();
|
|
12657
|
+
const tb = b.getTime();
|
|
12658
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) throw new TypeError("TreeMap: invalid Date key");
|
|
12659
|
+
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
12660
|
+
}
|
|
12661
|
+
throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys");
|
|
12662
|
+
};
|
|
12663
|
+
}
|
|
12664
|
+
_validateKey(key) {
|
|
12665
|
+
if (!__privateGet(this, _isDefaultComparator3)) return;
|
|
12666
|
+
if (typeof key === "number") {
|
|
12667
|
+
if (Number.isNaN(key)) throw new TypeError("TreeMap: NaN is not a valid key");
|
|
12668
|
+
return;
|
|
12709
12669
|
}
|
|
12710
|
-
|
|
12711
|
-
|
|
12670
|
+
if (typeof key === "string") return;
|
|
12671
|
+
if (key instanceof Date) {
|
|
12672
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeMap: invalid Date key");
|
|
12673
|
+
return;
|
|
12674
|
+
}
|
|
12675
|
+
throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys");
|
|
12712
12676
|
}
|
|
12713
12677
|
/**
|
|
12714
|
-
*
|
|
12715
|
-
|
|
12716
|
-
|
|
12678
|
+
* Number of entries in the map.
|
|
12679
|
+
*/
|
|
12680
|
+
get size() {
|
|
12681
|
+
return __privateGet(this, _core3).size;
|
|
12682
|
+
}
|
|
12683
|
+
/**
|
|
12684
|
+
* Whether the map is empty.
|
|
12685
|
+
*/
|
|
12686
|
+
isEmpty() {
|
|
12687
|
+
return this.size === 0;
|
|
12688
|
+
}
|
|
12689
|
+
/**
|
|
12690
|
+
* Set or overwrite a value for a key.
|
|
12691
|
+
* @remarks Expected time O(log n)
|
|
12692
|
+
*/
|
|
12693
|
+
set(key, value) {
|
|
12694
|
+
this._validateKey(key);
|
|
12695
|
+
__privateGet(this, _core3).set(key, value);
|
|
12696
|
+
return this;
|
|
12697
|
+
}
|
|
12698
|
+
/**
|
|
12699
|
+
* Get the value under a key.
|
|
12700
|
+
* @remarks Expected time O(log n)
|
|
12701
|
+
*/
|
|
12702
|
+
get(key) {
|
|
12703
|
+
this._validateKey(key);
|
|
12704
|
+
return __privateGet(this, _core3).get(key);
|
|
12705
|
+
}
|
|
12706
|
+
/**
|
|
12707
|
+
* Test whether a key exists.
|
|
12708
|
+
* @remarks Expected time O(log n)
|
|
12709
|
+
*/
|
|
12710
|
+
has(key) {
|
|
12711
|
+
this._validateKey(key);
|
|
12712
|
+
return __privateGet(this, _core3).has(key);
|
|
12713
|
+
}
|
|
12714
|
+
/**
|
|
12715
|
+
* Delete a key.
|
|
12716
|
+
* @returns `true` if the key existed; otherwise `false`.
|
|
12717
|
+
* @remarks Expected time O(log n)
|
|
12718
|
+
*/
|
|
12719
|
+
delete(key) {
|
|
12720
|
+
var _a;
|
|
12721
|
+
this._validateKey(key);
|
|
12722
|
+
const res = __privateGet(this, _core3).delete(key);
|
|
12723
|
+
return Array.isArray(res) && res.length > 0 && !!((_a = res[0]) == null ? void 0 : _a.deleted);
|
|
12724
|
+
}
|
|
12725
|
+
/**
|
|
12726
|
+
* Remove all entries.
|
|
12717
12727
|
*/
|
|
12718
12728
|
clear() {
|
|
12719
|
-
|
|
12720
|
-
this._count = 0;
|
|
12729
|
+
__privateGet(this, _core3).clear();
|
|
12721
12730
|
}
|
|
12722
12731
|
/**
|
|
12723
|
-
*
|
|
12724
|
-
* @remarks Time O(N), Space O(N)
|
|
12725
|
-
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
12726
|
-
* @returns True if rebalancing succeeded (tree not empty).
|
|
12732
|
+
* Iterate over keys in ascending order.
|
|
12727
12733
|
*/
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12733
|
-
for (const nd of nodes) total += nd ? nd.count : 0;
|
|
12734
|
-
this._clearNodes();
|
|
12735
|
-
const build = /* @__PURE__ */ __name((l, r, parent) => {
|
|
12736
|
-
if (l > r) return void 0;
|
|
12737
|
-
const m = l + (r - l >> 1);
|
|
12738
|
-
const root = nodes[m];
|
|
12739
|
-
const leftChild = build(l, m - 1, root);
|
|
12740
|
-
const rightChild = build(m + 1, r, root);
|
|
12741
|
-
root.left = leftChild;
|
|
12742
|
-
root.right = rightChild;
|
|
12743
|
-
root.parent = parent;
|
|
12744
|
-
return root;
|
|
12745
|
-
}, "build");
|
|
12746
|
-
const newRoot = build(0, n - 1, void 0);
|
|
12747
|
-
this._setRoot(newRoot);
|
|
12748
|
-
this._size = n;
|
|
12749
|
-
this._count = total;
|
|
12750
|
-
return true;
|
|
12734
|
+
keys() {
|
|
12735
|
+
return __privateGet(this, _core3).keys();
|
|
12736
|
+
}
|
|
12737
|
+
_entryFromKey(k) {
|
|
12738
|
+
return [k, __privateGet(this, _core3).get(k)];
|
|
12751
12739
|
}
|
|
12752
12740
|
/**
|
|
12753
|
-
*
|
|
12754
|
-
*
|
|
12755
|
-
*
|
|
12756
|
-
* @template MV
|
|
12757
|
-
* @template MR
|
|
12758
|
-
* @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
|
|
12759
|
-
* @param [options] - Options for the output tree.
|
|
12760
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
12761
|
-
* @returns A new TreeCounter with mapped entries.
|
|
12741
|
+
* Iterate over values in ascending key order.
|
|
12742
|
+
*
|
|
12743
|
+
* Note: values may be `undefined` (TreeMap allows storing `undefined`, like native `Map`).
|
|
12762
12744
|
*/
|
|
12763
|
-
|
|
12764
|
-
const
|
|
12745
|
+
*values() {
|
|
12746
|
+
for (const k of this.keys()) yield this._entryFromKey(k)[1];
|
|
12747
|
+
}
|
|
12748
|
+
/**
|
|
12749
|
+
* Iterate over `[key, value]` entries in ascending key order.
|
|
12750
|
+
*
|
|
12751
|
+
* Note: values may be `undefined`.
|
|
12752
|
+
*/
|
|
12753
|
+
*entries() {
|
|
12754
|
+
for (const k of this.keys()) yield this._entryFromKey(k);
|
|
12755
|
+
}
|
|
12756
|
+
[Symbol.iterator]() {
|
|
12757
|
+
return this.entries();
|
|
12758
|
+
}
|
|
12759
|
+
/**
|
|
12760
|
+
* Visit each entry in ascending key order.
|
|
12761
|
+
*
|
|
12762
|
+
* Note: callback value may be `undefined`.
|
|
12763
|
+
*/
|
|
12764
|
+
forEach(cb, thisArg) {
|
|
12765
|
+
for (const [k, v] of this) cb.call(thisArg, v, k, this);
|
|
12766
|
+
}
|
|
12767
|
+
/**
|
|
12768
|
+
* Create a new TreeMap by mapping each entry to a new `[key, value]` entry.
|
|
12769
|
+
*
|
|
12770
|
+
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
12771
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
12772
|
+
*/
|
|
12773
|
+
map(callbackfn, options = {}, thisArg) {
|
|
12774
|
+
const out = new _TreeMap([], options);
|
|
12765
12775
|
let index = 0;
|
|
12766
|
-
for (const [
|
|
12767
|
-
|
|
12776
|
+
for (const [k, v] of this) {
|
|
12777
|
+
const [mk, mv] = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12778
|
+
out.set(mk, mv);
|
|
12768
12779
|
}
|
|
12769
12780
|
return out;
|
|
12770
12781
|
}
|
|
12771
12782
|
/**
|
|
12772
|
-
*
|
|
12773
|
-
* @remarks Time O(
|
|
12774
|
-
* @returns A deep copy of this tree.
|
|
12783
|
+
* Create a new TreeMap containing only entries that satisfy the predicate.
|
|
12784
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
12775
12785
|
*/
|
|
12776
|
-
|
|
12777
|
-
const out = this
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
if (
|
|
12782
|
-
const outNode = out.getNode(node.key);
|
|
12783
|
-
if (outNode) outNode.count = node.count;
|
|
12786
|
+
filter(callbackfn, thisArg) {
|
|
12787
|
+
const out = new _TreeMap([], { comparator: __privateGet(this, _userComparator2) });
|
|
12788
|
+
let index = 0;
|
|
12789
|
+
for (const [k, v] of this) {
|
|
12790
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12791
|
+
if (ok) out.set(k, v);
|
|
12784
12792
|
}
|
|
12785
12793
|
return out;
|
|
12786
12794
|
}
|
|
12787
12795
|
/**
|
|
12788
|
-
*
|
|
12789
|
-
* @remarks Time O(
|
|
12790
|
-
* @template TK
|
|
12791
|
-
* @template TV
|
|
12792
|
-
* @template TR
|
|
12793
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
12794
|
-
* @returns An empty like-kind instance.
|
|
12796
|
+
* Reduce entries into a single accumulator.
|
|
12797
|
+
* @remarks Time O(n), Space O(1)
|
|
12795
12798
|
*/
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12799
|
+
reduce(callbackfn, initialValue) {
|
|
12800
|
+
let acc = initialValue;
|
|
12801
|
+
let index = 0;
|
|
12802
|
+
for (const [k, v] of this) acc = callbackfn(acc, v, k, index++, this);
|
|
12803
|
+
return acc;
|
|
12799
12804
|
}
|
|
12800
12805
|
/**
|
|
12801
|
-
*
|
|
12802
|
-
* @remarks Time O(
|
|
12803
|
-
* @template TK
|
|
12804
|
-
* @template TV
|
|
12805
|
-
* @template TR
|
|
12806
|
-
* @param iter - Iterable used to seed the new tree.
|
|
12807
|
-
* @param [options] - Options merged with the current snapshot.
|
|
12808
|
-
* @returns A like-kind TreeCounter built from the iterable.
|
|
12806
|
+
* Test whether all entries satisfy a predicate.
|
|
12807
|
+
* @remarks Time O(n), Space O(1)
|
|
12809
12808
|
*/
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
}
|
|
12809
|
+
every(callbackfn, thisArg) {
|
|
12810
|
+
let index = 0;
|
|
12811
|
+
for (const [k, v] of this) {
|
|
12812
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12813
|
+
if (!ok) return false;
|
|
12814
|
+
}
|
|
12815
|
+
return true;
|
|
12816
12816
|
}
|
|
12817
12817
|
/**
|
|
12818
|
-
*
|
|
12819
|
-
* @remarks Time O(
|
|
12820
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry.
|
|
12821
|
-
* @param [value] - Value used when a bare key is provided.
|
|
12822
|
-
* @param [count] - Count increment to apply (default 1).
|
|
12823
|
-
* @returns Tuple [node, value] where node may be undefined.
|
|
12818
|
+
* Test whether any entry satisfies a predicate.
|
|
12819
|
+
* @remarks Time O(n), Space O(1)
|
|
12824
12820
|
*/
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
if (key === void 0 || key === null) return [void 0, void 0];
|
|
12831
|
-
const finalValue = value != null ? value : entryValue;
|
|
12832
|
-
return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
12821
|
+
some(callbackfn, thisArg) {
|
|
12822
|
+
let index = 0;
|
|
12823
|
+
for (const [k, v] of this) {
|
|
12824
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12825
|
+
if (ok) return true;
|
|
12833
12826
|
}
|
|
12834
|
-
return
|
|
12827
|
+
return false;
|
|
12835
12828
|
}
|
|
12836
12829
|
/**
|
|
12837
|
-
*
|
|
12838
|
-
* @
|
|
12839
|
-
* @
|
|
12840
|
-
* @param destNode - Destination node (or key) to receive properties.
|
|
12841
|
-
* @returns Destination node after swap, or undefined.
|
|
12830
|
+
* Find the first entry that satisfies a predicate.
|
|
12831
|
+
* @returns The first matching `[key, value]` tuple, or `undefined`.
|
|
12832
|
+
* @remarks Time O(n), Space O(1)
|
|
12842
12833
|
*/
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
const tempNode = this.createNode(key, value, color, count);
|
|
12849
|
-
if (tempNode) {
|
|
12850
|
-
tempNode.color = color;
|
|
12851
|
-
destNode.key = srcNode.key;
|
|
12852
|
-
if (!this._isMapMode) destNode.value = srcNode.value;
|
|
12853
|
-
destNode.count = srcNode.count;
|
|
12854
|
-
destNode.color = srcNode.color;
|
|
12855
|
-
srcNode.key = tempNode.key;
|
|
12856
|
-
if (!this._isMapMode) srcNode.value = tempNode.value;
|
|
12857
|
-
srcNode.count = tempNode.count;
|
|
12858
|
-
srcNode.color = tempNode.color;
|
|
12859
|
-
}
|
|
12860
|
-
return destNode;
|
|
12834
|
+
find(callbackfn, thisArg) {
|
|
12835
|
+
let index = 0;
|
|
12836
|
+
for (const [k, v] of this) {
|
|
12837
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12838
|
+
if (ok) return [k, v];
|
|
12861
12839
|
}
|
|
12862
12840
|
return void 0;
|
|
12863
12841
|
}
|
|
12864
12842
|
/**
|
|
12865
|
-
*
|
|
12866
|
-
* @remarks Time O(
|
|
12867
|
-
* @param oldNode - Node being replaced.
|
|
12868
|
-
* @param newNode - Replacement node.
|
|
12869
|
-
* @returns The new node after replacement.
|
|
12843
|
+
* Materialize the map into an array of `[key, value]` tuples.
|
|
12844
|
+
* @remarks Time O(n), Space O(n)
|
|
12870
12845
|
*/
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12846
|
+
toArray() {
|
|
12847
|
+
return [...this];
|
|
12848
|
+
}
|
|
12849
|
+
/**
|
|
12850
|
+
* Print a human-friendly representation.
|
|
12851
|
+
* @remarks Time O(n), Space O(n)
|
|
12852
|
+
*/
|
|
12853
|
+
print() {
|
|
12854
|
+
__privateGet(this, _core3).print();
|
|
12855
|
+
}
|
|
12856
|
+
// Navigable operations (return entry tuples)
|
|
12857
|
+
// Note: returned tuple values may be `undefined`.
|
|
12858
|
+
/**
|
|
12859
|
+
* Smallest entry by key.
|
|
12860
|
+
*/
|
|
12861
|
+
first() {
|
|
12862
|
+
const k = __privateGet(this, _core3).getLeftMost();
|
|
12863
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12864
|
+
}
|
|
12865
|
+
/**
|
|
12866
|
+
* Largest entry by key.
|
|
12867
|
+
*/
|
|
12868
|
+
last() {
|
|
12869
|
+
const k = __privateGet(this, _core3).getRightMost();
|
|
12870
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12871
|
+
}
|
|
12872
|
+
/**
|
|
12873
|
+
* Remove and return the smallest entry.
|
|
12874
|
+
*/
|
|
12875
|
+
pollFirst() {
|
|
12876
|
+
const entry = this.first();
|
|
12877
|
+
if (!entry) return void 0;
|
|
12878
|
+
this.delete(entry[0]);
|
|
12879
|
+
return entry;
|
|
12880
|
+
}
|
|
12881
|
+
/**
|
|
12882
|
+
* Remove and return the largest entry.
|
|
12883
|
+
*/
|
|
12884
|
+
pollLast() {
|
|
12885
|
+
const entry = this.last();
|
|
12886
|
+
if (!entry) return void 0;
|
|
12887
|
+
this.delete(entry[0]);
|
|
12888
|
+
return entry;
|
|
12889
|
+
}
|
|
12890
|
+
/**
|
|
12891
|
+
* Smallest entry whose key is >= the given key.
|
|
12892
|
+
*/
|
|
12893
|
+
ceiling(key) {
|
|
12894
|
+
this._validateKey(key);
|
|
12895
|
+
const k = __privateGet(this, _core3).ceiling(key);
|
|
12896
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12897
|
+
}
|
|
12898
|
+
/**
|
|
12899
|
+
* Largest entry whose key is <= the given key.
|
|
12900
|
+
*/
|
|
12901
|
+
floor(key) {
|
|
12902
|
+
this._validateKey(key);
|
|
12903
|
+
const k = __privateGet(this, _core3).floor(key);
|
|
12904
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12905
|
+
}
|
|
12906
|
+
/**
|
|
12907
|
+
* Smallest entry whose key is > the given key.
|
|
12908
|
+
*/
|
|
12909
|
+
higher(key) {
|
|
12910
|
+
this._validateKey(key);
|
|
12911
|
+
const k = __privateGet(this, _core3).higher(key);
|
|
12912
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12913
|
+
}
|
|
12914
|
+
/**
|
|
12915
|
+
* Largest entry whose key is < the given key.
|
|
12916
|
+
*/
|
|
12917
|
+
lower(key) {
|
|
12918
|
+
this._validateKey(key);
|
|
12919
|
+
const k = __privateGet(this, _core3).lower(key);
|
|
12920
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12921
|
+
}
|
|
12922
|
+
/**
|
|
12923
|
+
* Return all entries in a given key range.
|
|
12924
|
+
*
|
|
12925
|
+
* @param range `[low, high]`
|
|
12926
|
+
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
12927
|
+
*/
|
|
12928
|
+
rangeSearch(range, options = {}) {
|
|
12929
|
+
const { lowInclusive = true, highInclusive = true } = options;
|
|
12930
|
+
const [low, high] = range;
|
|
12931
|
+
this._validateKey(low);
|
|
12932
|
+
this._validateKey(high);
|
|
12933
|
+
const keys = __privateGet(this, _core3).rangeSearch([low, high]);
|
|
12934
|
+
const out = [];
|
|
12935
|
+
const cmp = __privateGet(this, _core3).comparator;
|
|
12936
|
+
for (const k of keys) {
|
|
12937
|
+
if (k === void 0) continue;
|
|
12938
|
+
if (!lowInclusive && cmp(k, low) === 0) continue;
|
|
12939
|
+
if (!highInclusive && cmp(k, high) === 0) continue;
|
|
12940
|
+
out.push(this._entryFromKey(k));
|
|
12941
|
+
}
|
|
12942
|
+
return out;
|
|
12874
12943
|
}
|
|
12875
12944
|
};
|
|
12876
|
-
|
|
12877
|
-
|
|
12945
|
+
_core3 = new WeakMap();
|
|
12946
|
+
_isDefaultComparator3 = new WeakMap();
|
|
12947
|
+
_userComparator2 = new WeakMap();
|
|
12948
|
+
__name(_TreeMap, "TreeMap");
|
|
12949
|
+
var TreeMap = _TreeMap;
|
|
12878
12950
|
|
|
12879
|
-
// src/data-structures/binary-tree/
|
|
12880
|
-
var
|
|
12951
|
+
// src/data-structures/binary-tree/tree-multi-set.ts
|
|
12952
|
+
var _core4, _isDefaultComparator4;
|
|
12953
|
+
var _TreeMultiSet = class _TreeMultiSet {
|
|
12954
|
+
// total occurrences (sumCounts)
|
|
12955
|
+
/**
|
|
12956
|
+
* Creates a new TreeMultiSet.
|
|
12957
|
+
* @param elements - Initial elements to add
|
|
12958
|
+
* @param options - Configuration options
|
|
12959
|
+
* @remarks Time O(m log m), Space O(m) where m is the number of initial elements
|
|
12960
|
+
*/
|
|
12961
|
+
constructor(elements = [], options = {}) {
|
|
12962
|
+
__privateAdd(this, _core4);
|
|
12963
|
+
__privateAdd(this, _isDefaultComparator4);
|
|
12964
|
+
__publicField(this, "_size", 0);
|
|
12965
|
+
var _a;
|
|
12966
|
+
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
12967
|
+
__privateSet(this, _isDefaultComparator4, options.comparator === void 0);
|
|
12968
|
+
__privateSet(this, _core4, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
12969
|
+
for (const k of elements) this.add(k);
|
|
12970
|
+
}
|
|
12881
12971
|
/**
|
|
12882
|
-
*
|
|
12972
|
+
* Validates the key against the default comparator rules.
|
|
12883
12973
|
* @remarks Time O(1), Space O(1)
|
|
12884
|
-
* @param key - Key of the node.
|
|
12885
|
-
* @param [value] - Associated value (ignored in map mode).
|
|
12886
|
-
* @param [count] - Initial count for this node (default 1).
|
|
12887
|
-
* @returns New AVLTreeCounterNode instance.
|
|
12888
12974
|
*/
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12975
|
+
_validateKey(key) {
|
|
12976
|
+
if (!__privateGet(this, _isDefaultComparator4)) return;
|
|
12977
|
+
if (typeof key === "number") {
|
|
12978
|
+
if (Number.isNaN(key)) throw new TypeError("TreeMultiSet: NaN is not a valid key");
|
|
12979
|
+
return;
|
|
12980
|
+
}
|
|
12981
|
+
if (typeof key === "string") return;
|
|
12982
|
+
if (key instanceof Date) {
|
|
12983
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeMultiSet: invalid Date key");
|
|
12984
|
+
return;
|
|
12985
|
+
}
|
|
12986
|
+
throw new TypeError("TreeMultiSet: comparator is required for non-number/non-string/non-Date keys");
|
|
12987
|
+
}
|
|
12988
|
+
/**
|
|
12989
|
+
* Validates that count is a non-negative safe integer.
|
|
12990
|
+
* @remarks Time O(1), Space O(1)
|
|
12991
|
+
*/
|
|
12992
|
+
_validateCount(n) {
|
|
12993
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new RangeError("TreeMultiSet: count must be a safe integer >= 0");
|
|
12901
12994
|
}
|
|
12902
12995
|
/**
|
|
12903
|
-
*
|
|
12996
|
+
* Total occurrences (sumCounts).
|
|
12904
12997
|
* @remarks Time O(1), Space O(1)
|
|
12905
|
-
* @returns Left child node, or null/undefined.
|
|
12906
12998
|
*/
|
|
12907
|
-
get
|
|
12908
|
-
return this.
|
|
12999
|
+
get size() {
|
|
13000
|
+
return this._size;
|
|
12909
13001
|
}
|
|
12910
13002
|
/**
|
|
12911
|
-
*
|
|
13003
|
+
* Number of distinct keys.
|
|
12912
13004
|
* @remarks Time O(1), Space O(1)
|
|
12913
|
-
* @param v - New left child node, or null/undefined.
|
|
12914
|
-
* @returns void
|
|
12915
13005
|
*/
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
v.parent = this;
|
|
12919
|
-
}
|
|
12920
|
-
this._left = v;
|
|
13006
|
+
get distinctSize() {
|
|
13007
|
+
return __privateGet(this, _core4).size;
|
|
12921
13008
|
}
|
|
12922
13009
|
/**
|
|
12923
|
-
*
|
|
13010
|
+
* Whether the multiset is empty.
|
|
12924
13011
|
* @remarks Time O(1), Space O(1)
|
|
12925
|
-
* @returns Right child node, or null/undefined.
|
|
12926
13012
|
*/
|
|
12927
|
-
|
|
12928
|
-
return this.
|
|
13013
|
+
isEmpty() {
|
|
13014
|
+
return this.size === 0;
|
|
12929
13015
|
}
|
|
12930
13016
|
/**
|
|
12931
|
-
*
|
|
12932
|
-
* @remarks Time O(
|
|
12933
|
-
* @param v - New right child node, or null/undefined.
|
|
12934
|
-
* @returns void
|
|
13017
|
+
* Whether the multiset contains the given key.
|
|
13018
|
+
* @remarks Time O(log n), Space O(1)
|
|
12935
13019
|
*/
|
|
12936
|
-
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
}
|
|
12940
|
-
this._right = v;
|
|
13020
|
+
has(key) {
|
|
13021
|
+
this._validateKey(key);
|
|
13022
|
+
return this.count(key) > 0;
|
|
12941
13023
|
}
|
|
12942
13024
|
/**
|
|
12943
|
-
*
|
|
12944
|
-
* @remarks Time O(
|
|
12945
|
-
*
|
|
12946
|
-
* @returns The height.
|
|
13025
|
+
* Returns the count of occurrences for the given key.
|
|
13026
|
+
* @remarks Time O(log n), Space O(1)
|
|
12947
13027
|
*/
|
|
12948
|
-
|
|
12949
|
-
|
|
13028
|
+
count(key) {
|
|
13029
|
+
var _a;
|
|
13030
|
+
this._validateKey(key);
|
|
13031
|
+
return (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
12950
13032
|
}
|
|
12951
13033
|
/**
|
|
12952
|
-
*
|
|
12953
|
-
* @
|
|
12954
|
-
*
|
|
12955
|
-
* @param value - The new height.
|
|
13034
|
+
* Add `n` occurrences of `key`.
|
|
13035
|
+
* @returns True if the multiset changed.
|
|
13036
|
+
* @remarks Time O(log n), Space O(1)
|
|
12956
13037
|
*/
|
|
12957
|
-
|
|
12958
|
-
|
|
13038
|
+
add(key, n = 1) {
|
|
13039
|
+
var _a;
|
|
13040
|
+
this._validateKey(key);
|
|
13041
|
+
this._validateCount(n);
|
|
13042
|
+
if (n === 0) return false;
|
|
13043
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13044
|
+
const next = old + n;
|
|
13045
|
+
__privateGet(this, _core4).set(key, next);
|
|
13046
|
+
this._size += n;
|
|
13047
|
+
return true;
|
|
12959
13048
|
}
|
|
12960
13049
|
/**
|
|
12961
|
-
*
|
|
12962
|
-
* @
|
|
12963
|
-
*
|
|
12964
|
-
* @returns The node's color.
|
|
13050
|
+
* Set count for `key` to exactly `n`.
|
|
13051
|
+
* @returns True if changed.
|
|
13052
|
+
* @remarks Time O(log n), Space O(1)
|
|
12965
13053
|
*/
|
|
12966
|
-
|
|
12967
|
-
|
|
13054
|
+
setCount(key, n) {
|
|
13055
|
+
var _a;
|
|
13056
|
+
this._validateKey(key);
|
|
13057
|
+
this._validateCount(n);
|
|
13058
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13059
|
+
if (old === n) return false;
|
|
13060
|
+
if (n === 0) {
|
|
13061
|
+
if (old !== 0) __privateGet(this, _core4).delete(key);
|
|
13062
|
+
} else {
|
|
13063
|
+
__privateGet(this, _core4).set(key, n);
|
|
13064
|
+
}
|
|
13065
|
+
this._size += n - old;
|
|
13066
|
+
return true;
|
|
12968
13067
|
}
|
|
12969
13068
|
/**
|
|
12970
|
-
*
|
|
12971
|
-
* @
|
|
12972
|
-
*
|
|
12973
|
-
* @param value - The new color.
|
|
13069
|
+
* Delete `n` occurrences of `key` (default 1).
|
|
13070
|
+
* @returns True if any occurrence was removed.
|
|
13071
|
+
* @remarks Time O(log n), Space O(1)
|
|
12974
13072
|
*/
|
|
12975
|
-
|
|
12976
|
-
|
|
13073
|
+
delete(key, n = 1) {
|
|
13074
|
+
var _a;
|
|
13075
|
+
this._validateKey(key);
|
|
13076
|
+
this._validateCount(n);
|
|
13077
|
+
if (n === 0) return false;
|
|
13078
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13079
|
+
if (old === 0) return false;
|
|
13080
|
+
const removed = Math.min(old, n);
|
|
13081
|
+
const next = old - removed;
|
|
13082
|
+
if (next === 0) __privateGet(this, _core4).delete(key);
|
|
13083
|
+
else __privateGet(this, _core4).set(key, next);
|
|
13084
|
+
this._size -= removed;
|
|
13085
|
+
return true;
|
|
12977
13086
|
}
|
|
12978
13087
|
/**
|
|
12979
|
-
*
|
|
12980
|
-
* @
|
|
12981
|
-
*
|
|
12982
|
-
* @returns The subtree node count.
|
|
13088
|
+
* Delete all occurrences of the given key.
|
|
13089
|
+
* @returns True if any occurrence was removed.
|
|
13090
|
+
* @remarks Time O(log n), Space O(1)
|
|
12983
13091
|
*/
|
|
12984
|
-
|
|
12985
|
-
|
|
13092
|
+
deleteAll(key) {
|
|
13093
|
+
var _a;
|
|
13094
|
+
this._validateKey(key);
|
|
13095
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13096
|
+
if (old === 0) return false;
|
|
13097
|
+
__privateGet(this, _core4).delete(key);
|
|
13098
|
+
this._size -= old;
|
|
13099
|
+
return true;
|
|
12986
13100
|
}
|
|
12987
13101
|
/**
|
|
12988
|
-
*
|
|
12989
|
-
* @remarks Time O(
|
|
12990
|
-
*
|
|
12991
|
-
* @param value - The new count.
|
|
13102
|
+
* Iterates over distinct keys (each key yielded once).
|
|
13103
|
+
* @remarks Time O(n), Space O(1)
|
|
12992
13104
|
*/
|
|
12993
|
-
|
|
12994
|
-
this.
|
|
13105
|
+
*keysDistinct() {
|
|
13106
|
+
yield* __privateGet(this, _core4).keys();
|
|
12995
13107
|
}
|
|
12996
13108
|
/**
|
|
12997
|
-
*
|
|
12998
|
-
* @remarks Time O(
|
|
12999
|
-
*
|
|
13000
|
-
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
13109
|
+
* Iterates over entries as [key, count] pairs.
|
|
13110
|
+
* @remarks Time O(n), Space O(1)
|
|
13001
13111
|
*/
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
|
|
13112
|
+
*entries() {
|
|
13113
|
+
for (const [k, v] of __privateGet(this, _core4)) {
|
|
13114
|
+
yield [k, v != null ? v : 0];
|
|
13005
13115
|
}
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13116
|
+
}
|
|
13117
|
+
/**
|
|
13118
|
+
* Expanded iteration (default). Each key is yielded `count(key)` times.
|
|
13119
|
+
* @remarks Time O(size), Space O(1) where size is total occurrences
|
|
13120
|
+
*/
|
|
13121
|
+
*[Symbol.iterator]() {
|
|
13122
|
+
for (const [k, c] of this.entries()) {
|
|
13123
|
+
for (let i = 0; i < c; i++) yield k;
|
|
13010
13124
|
}
|
|
13011
|
-
return "MAL_NODE";
|
|
13012
13125
|
}
|
|
13013
|
-
};
|
|
13014
|
-
__name(_AVLTreeCounterNode, "AVLTreeCounterNode");
|
|
13015
|
-
var AVLTreeCounterNode = _AVLTreeCounterNode;
|
|
13016
|
-
var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
13017
13126
|
/**
|
|
13018
|
-
*
|
|
13019
|
-
* @remarks Time O(
|
|
13020
|
-
* @param keysNodesEntriesOrRaws
|
|
13021
|
-
* @param options
|
|
13022
|
-
* @returns New AVLTreeCounterNode instance.
|
|
13127
|
+
* Returns an array with all elements (expanded).
|
|
13128
|
+
* @remarks Time O(size), Space O(size)
|
|
13023
13129
|
*/
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
__publicField(this, "_count", 0);
|
|
13027
|
-
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
13130
|
+
toArray() {
|
|
13131
|
+
return [...this];
|
|
13028
13132
|
}
|
|
13029
|
-
|
|
13030
|
-
|
|
13133
|
+
/**
|
|
13134
|
+
* Returns an array with distinct keys only.
|
|
13135
|
+
* @remarks Time O(n), Space O(n)
|
|
13136
|
+
*/
|
|
13137
|
+
toDistinctArray() {
|
|
13138
|
+
return [...this.keysDistinct()];
|
|
13031
13139
|
}
|
|
13032
13140
|
/**
|
|
13033
|
-
*
|
|
13034
|
-
* @remarks Time O(
|
|
13035
|
-
* @returns Total count recomputed from nodes.
|
|
13141
|
+
* Returns an array of [key, count] entries.
|
|
13142
|
+
* @remarks Time O(n), Space O(n)
|
|
13036
13143
|
*/
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
this.dfs((node) => sum += node.count);
|
|
13040
|
-
return sum;
|
|
13144
|
+
toEntries() {
|
|
13145
|
+
return [...this.entries()];
|
|
13041
13146
|
}
|
|
13042
|
-
|
|
13043
|
-
|
|
13147
|
+
/**
|
|
13148
|
+
* Expose comparator for advanced usage/testing (read-only).
|
|
13149
|
+
* @remarks Time O(1), Space O(1)
|
|
13150
|
+
*/
|
|
13151
|
+
get comparator() {
|
|
13152
|
+
return __privateGet(this, _core4)._comparator;
|
|
13044
13153
|
}
|
|
13154
|
+
// ━━━ clear ━━━
|
|
13045
13155
|
/**
|
|
13046
|
-
*
|
|
13156
|
+
* Remove all elements from the multiset.
|
|
13047
13157
|
* @remarks Time O(1), Space O(1)
|
|
13048
|
-
* @
|
|
13158
|
+
* @example
|
|
13159
|
+
* const ms = new TreeMultiSet([1, 2, 2, 3]);
|
|
13160
|
+
* ms.clear();
|
|
13161
|
+
* ms.size; // 0
|
|
13049
13162
|
*/
|
|
13050
|
-
|
|
13051
|
-
|
|
13163
|
+
clear() {
|
|
13164
|
+
__privateGet(this, _core4).clear();
|
|
13165
|
+
this._size = 0;
|
|
13052
13166
|
}
|
|
13167
|
+
// ━━━ Navigable methods ━━━
|
|
13053
13168
|
/**
|
|
13054
|
-
*
|
|
13055
|
-
* @remarks Time O(log
|
|
13056
|
-
* @
|
|
13057
|
-
*
|
|
13058
|
-
*
|
|
13059
|
-
* @returns True if inserted/updated; false if ignored.
|
|
13169
|
+
* Returns the smallest key, or undefined if empty.
|
|
13170
|
+
* @remarks Time O(log n), Space O(1)
|
|
13171
|
+
* @example
|
|
13172
|
+
* const ms = new TreeMultiSet([3, 1, 4]);
|
|
13173
|
+
* ms.first(); // 1
|
|
13060
13174
|
*/
|
|
13061
|
-
|
|
13062
|
-
|
|
13063
|
-
if (newNode === void 0) return false;
|
|
13064
|
-
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
13065
|
-
const inserted = super.set(newNode, newValue);
|
|
13066
|
-
if (inserted) {
|
|
13067
|
-
this._count += orgNodeCount;
|
|
13068
|
-
}
|
|
13069
|
-
return true;
|
|
13175
|
+
first() {
|
|
13176
|
+
return __privateGet(this, _core4).getLeftMost();
|
|
13070
13177
|
}
|
|
13071
13178
|
/**
|
|
13072
|
-
*
|
|
13073
|
-
* @remarks Time O(log
|
|
13074
|
-
* @
|
|
13075
|
-
*
|
|
13076
|
-
*
|
|
13179
|
+
* Returns the largest key, or undefined if empty.
|
|
13180
|
+
* @remarks Time O(log n), Space O(1)
|
|
13181
|
+
* @example
|
|
13182
|
+
* const ms = new TreeMultiSet([3, 1, 4]);
|
|
13183
|
+
* ms.last(); // 4
|
|
13077
13184
|
*/
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
const deletedResult = [];
|
|
13081
|
-
if (!this.root) return deletedResult;
|
|
13082
|
-
const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
|
|
13083
|
-
if (!curr) return deletedResult;
|
|
13084
|
-
const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
|
|
13085
|
-
let needBalanced = void 0, orgCurrent = curr;
|
|
13086
|
-
if (curr.count > 1 && !ignoreCount) {
|
|
13087
|
-
curr.count--;
|
|
13088
|
-
this._count--;
|
|
13089
|
-
} else {
|
|
13090
|
-
if (!curr.left) {
|
|
13091
|
-
if (!parent) {
|
|
13092
|
-
if (curr.right !== void 0 && curr.right !== null) this._setRoot(curr.right);
|
|
13093
|
-
} else {
|
|
13094
|
-
const { familyPosition: fp } = curr;
|
|
13095
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
13096
|
-
parent.left = curr.right;
|
|
13097
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
13098
|
-
parent.right = curr.right;
|
|
13099
|
-
}
|
|
13100
|
-
needBalanced = parent;
|
|
13101
|
-
}
|
|
13102
|
-
} else {
|
|
13103
|
-
const leftSubTreeRightMost = curr.left ? this.getRightMost((node) => node, curr.left) : void 0;
|
|
13104
|
-
if (leftSubTreeRightMost) {
|
|
13105
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
13106
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
13107
|
-
if (parentOfLeftSubTreeMax) {
|
|
13108
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
|
|
13109
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
13110
|
-
} else {
|
|
13111
|
-
parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
13112
|
-
}
|
|
13113
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
13114
|
-
}
|
|
13115
|
-
}
|
|
13116
|
-
}
|
|
13117
|
-
this._size = this._size - 1;
|
|
13118
|
-
if (orgCurrent) this._count -= orgCurrent.count;
|
|
13119
|
-
}
|
|
13120
|
-
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
13121
|
-
if (needBalanced) {
|
|
13122
|
-
this._balancePath(needBalanced);
|
|
13123
|
-
}
|
|
13124
|
-
return deletedResult;
|
|
13185
|
+
last() {
|
|
13186
|
+
return __privateGet(this, _core4).getRightMost();
|
|
13125
13187
|
}
|
|
13126
13188
|
/**
|
|
13127
|
-
*
|
|
13128
|
-
* @remarks Time O(
|
|
13129
|
-
* @
|
|
13189
|
+
* Removes all occurrences of the smallest key and returns it.
|
|
13190
|
+
* @remarks Time O(log n), Space O(1)
|
|
13191
|
+
* @example
|
|
13192
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3]);
|
|
13193
|
+
* ms.pollFirst(); // 1
|
|
13194
|
+
* ms.has(1); // false
|
|
13130
13195
|
*/
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13196
|
+
pollFirst() {
|
|
13197
|
+
const key = this.first();
|
|
13198
|
+
if (key === void 0) return void 0;
|
|
13199
|
+
this.deleteAll(key);
|
|
13200
|
+
return key;
|
|
13134
13201
|
}
|
|
13135
13202
|
/**
|
|
13136
|
-
*
|
|
13137
|
-
* @remarks Time O(
|
|
13138
|
-
* @
|
|
13139
|
-
*
|
|
13203
|
+
* Removes all occurrences of the largest key and returns it.
|
|
13204
|
+
* @remarks Time O(log n), Space O(1)
|
|
13205
|
+
* @example
|
|
13206
|
+
* const ms = new TreeMultiSet([1, 2, 3, 3]);
|
|
13207
|
+
* ms.pollLast(); // 3
|
|
13208
|
+
* ms.has(3); // false
|
|
13140
13209
|
*/
|
|
13141
|
-
|
|
13142
|
-
const
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
for (const nd of nodes) total += nd ? nd.count : 0;
|
|
13147
|
-
this._clearNodes();
|
|
13148
|
-
const build = /* @__PURE__ */ __name((l, r, parent) => {
|
|
13149
|
-
if (l > r) return void 0;
|
|
13150
|
-
const m = l + (r - l >> 1);
|
|
13151
|
-
const root = nodes[m];
|
|
13152
|
-
root.left = build(l, m - 1, root);
|
|
13153
|
-
root.right = build(m + 1, r, root);
|
|
13154
|
-
root.parent = parent;
|
|
13155
|
-
const lh = root.left ? root.left.height : -1;
|
|
13156
|
-
const rh = root.right ? root.right.height : -1;
|
|
13157
|
-
root.height = Math.max(lh, rh) + 1;
|
|
13158
|
-
return root;
|
|
13159
|
-
}, "build");
|
|
13160
|
-
const newRoot = build(0, n - 1, void 0);
|
|
13161
|
-
this._setRoot(newRoot);
|
|
13162
|
-
this._size = n;
|
|
13163
|
-
this._count = total;
|
|
13164
|
-
return true;
|
|
13210
|
+
pollLast() {
|
|
13211
|
+
const key = this.last();
|
|
13212
|
+
if (key === void 0) return void 0;
|
|
13213
|
+
this.deleteAll(key);
|
|
13214
|
+
return key;
|
|
13165
13215
|
}
|
|
13166
13216
|
/**
|
|
13167
|
-
*
|
|
13168
|
-
* @remarks Time O(
|
|
13169
|
-
* @
|
|
13217
|
+
* Returns the smallest key >= given key, or undefined.
|
|
13218
|
+
* @remarks Time O(log n), Space O(1)
|
|
13219
|
+
* @example
|
|
13220
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13221
|
+
* ms.ceiling(15); // 20
|
|
13222
|
+
* ms.ceiling(20); // 20
|
|
13170
13223
|
*/
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
this.bfs((node) => out.set(node.key, void 0, node.count));
|
|
13175
|
-
} else {
|
|
13176
|
-
this.bfs((node) => out.set(node.key, node.value, node.count));
|
|
13177
|
-
}
|
|
13178
|
-
if (this._isMapMode) out._store = this._store;
|
|
13179
|
-
return out;
|
|
13224
|
+
ceiling(key) {
|
|
13225
|
+
this._validateKey(key);
|
|
13226
|
+
return __privateGet(this, _core4).ceiling(key);
|
|
13180
13227
|
}
|
|
13181
13228
|
/**
|
|
13182
|
-
*
|
|
13183
|
-
* @remarks Time O(
|
|
13184
|
-
* @
|
|
13185
|
-
*
|
|
13186
|
-
*
|
|
13187
|
-
*
|
|
13188
|
-
* @param [options] - Options for the output tree.
|
|
13189
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
13190
|
-
* @returns A new AVLTreeCounter with mapped entries.
|
|
13229
|
+
* Returns the largest key <= given key, or undefined.
|
|
13230
|
+
* @remarks Time O(log n), Space O(1)
|
|
13231
|
+
* @example
|
|
13232
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13233
|
+
* ms.floor(25); // 20
|
|
13234
|
+
* ms.floor(20); // 20
|
|
13191
13235
|
*/
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
|
|
13195
|
-
for (const [key, value] of this) {
|
|
13196
|
-
out.set(callback.call(thisArg, value, key, index++, this));
|
|
13197
|
-
}
|
|
13198
|
-
return out;
|
|
13236
|
+
floor(key) {
|
|
13237
|
+
this._validateKey(key);
|
|
13238
|
+
return __privateGet(this, _core4).floor(key);
|
|
13199
13239
|
}
|
|
13200
13240
|
/**
|
|
13201
|
-
*
|
|
13202
|
-
* @remarks Time O(
|
|
13203
|
-
* @
|
|
13204
|
-
*
|
|
13205
|
-
*
|
|
13206
|
-
*
|
|
13207
|
-
* @returns An empty like-kind instance.
|
|
13241
|
+
* Returns the smallest key > given key, or undefined.
|
|
13242
|
+
* @remarks Time O(log n), Space O(1)
|
|
13243
|
+
* @example
|
|
13244
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13245
|
+
* ms.higher(10); // 20
|
|
13246
|
+
* ms.higher(15); // 20
|
|
13208
13247
|
*/
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
return
|
|
13248
|
+
higher(key) {
|
|
13249
|
+
this._validateKey(key);
|
|
13250
|
+
return __privateGet(this, _core4).higher(key);
|
|
13212
13251
|
}
|
|
13213
13252
|
/**
|
|
13214
|
-
*
|
|
13215
|
-
* @remarks Time O(
|
|
13216
|
-
* @
|
|
13217
|
-
*
|
|
13218
|
-
*
|
|
13219
|
-
*
|
|
13220
|
-
* @param [options] - Options merged with the current snapshot.
|
|
13221
|
-
* @returns A like-kind AVLTreeCounter built from the iterable.
|
|
13253
|
+
* Returns the largest key < given key, or undefined.
|
|
13254
|
+
* @remarks Time O(log n), Space O(1)
|
|
13255
|
+
* @example
|
|
13256
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13257
|
+
* ms.lower(20); // 10
|
|
13258
|
+
* ms.lower(15); // 10
|
|
13222
13259
|
*/
|
|
13223
|
-
|
|
13224
|
-
|
|
13225
|
-
return
|
|
13260
|
+
lower(key) {
|
|
13261
|
+
this._validateKey(key);
|
|
13262
|
+
return __privateGet(this, _core4).lower(key);
|
|
13226
13263
|
}
|
|
13264
|
+
// ━━━ Functional methods ━━━
|
|
13227
13265
|
/**
|
|
13228
|
-
*
|
|
13229
|
-
* @remarks Time O(
|
|
13230
|
-
* @
|
|
13231
|
-
*
|
|
13232
|
-
*
|
|
13233
|
-
*
|
|
13266
|
+
* Iterates over distinct keys with their counts.
|
|
13267
|
+
* @remarks Time O(n), Space O(1)
|
|
13268
|
+
* @example
|
|
13269
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13270
|
+
* ms.forEach((key, count) => console.log(`${key}: ${count}`));
|
|
13271
|
+
* // 1: 2, 2: 1, 3: 3
|
|
13234
13272
|
*/
|
|
13235
|
-
|
|
13236
|
-
|
|
13237
|
-
|
|
13238
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
13239
|
-
const [key, entryValue] = keyNodeOrEntry;
|
|
13240
|
-
if (key === void 0 || key === null) return [void 0, void 0];
|
|
13241
|
-
const finalValue = value != null ? value : entryValue;
|
|
13242
|
-
return [this.createNode(key, finalValue, count), finalValue];
|
|
13273
|
+
forEach(callback) {
|
|
13274
|
+
for (const [k, c] of this.entries()) {
|
|
13275
|
+
callback(k, c);
|
|
13243
13276
|
}
|
|
13244
|
-
return [this.createNode(keyNodeOrEntry, value, count), value];
|
|
13245
13277
|
}
|
|
13246
13278
|
/**
|
|
13247
|
-
*
|
|
13248
|
-
* @remarks Time O(
|
|
13249
|
-
* @
|
|
13250
|
-
*
|
|
13251
|
-
*
|
|
13279
|
+
* Creates a new TreeMultiSet with entries that match the predicate.
|
|
13280
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13281
|
+
* @example
|
|
13282
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13283
|
+
* const filtered = ms.filter((key, count) => count >= 2);
|
|
13284
|
+
* // TreeMultiSet { 1: 2, 3: 3 }
|
|
13252
13285
|
*/
|
|
13253
|
-
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
|
|
13257
|
-
|
|
13258
|
-
|
|
13259
|
-
if (
|
|
13260
|
-
|
|
13261
|
-
destNode.key = srcNode.key;
|
|
13262
|
-
if (!this._isMapMode) destNode.value = srcNode.value;
|
|
13263
|
-
destNode.count = srcNode.count;
|
|
13264
|
-
destNode.height = srcNode.height;
|
|
13265
|
-
srcNode.key = tempNode.key;
|
|
13266
|
-
if (!this._isMapMode) srcNode.value = tempNode.value;
|
|
13267
|
-
srcNode.count = tempNode.count;
|
|
13268
|
-
srcNode.height = tempNode.height;
|
|
13286
|
+
filter(predicate) {
|
|
13287
|
+
const result = new _TreeMultiSet([], {
|
|
13288
|
+
comparator: __privateGet(this, _isDefaultComparator4) ? void 0 : this.comparator,
|
|
13289
|
+
isMapMode: __privateGet(this, _core4)._isMapMode
|
|
13290
|
+
});
|
|
13291
|
+
for (const [k, c] of this.entries()) {
|
|
13292
|
+
if (predicate(k, c)) {
|
|
13293
|
+
result.add(k, c);
|
|
13269
13294
|
}
|
|
13270
|
-
return destNode;
|
|
13271
13295
|
}
|
|
13272
|
-
return
|
|
13296
|
+
return result;
|
|
13273
13297
|
}
|
|
13274
13298
|
/**
|
|
13275
|
-
*
|
|
13276
|
-
* @remarks Time O(
|
|
13277
|
-
* @
|
|
13278
|
-
*
|
|
13279
|
-
*
|
|
13299
|
+
* Reduces the multiset to a single value.
|
|
13300
|
+
* @remarks Time O(n), Space O(1)
|
|
13301
|
+
* @example
|
|
13302
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13303
|
+
* const total = ms.reduce((acc, key, count) => acc + count, 0); // 6
|
|
13280
13304
|
*/
|
|
13281
|
-
|
|
13282
|
-
|
|
13283
|
-
|
|
13305
|
+
reduce(callback, initialValue) {
|
|
13306
|
+
let acc = initialValue;
|
|
13307
|
+
for (const [k, c] of this.entries()) {
|
|
13308
|
+
acc = callback(acc, k, c);
|
|
13309
|
+
}
|
|
13310
|
+
return acc;
|
|
13311
|
+
}
|
|
13312
|
+
/**
|
|
13313
|
+
* Maps keys and counts to a new TreeMultiSet.
|
|
13314
|
+
* When multiple keys map to the same new key, counts are merged (added).
|
|
13315
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13316
|
+
* @example
|
|
13317
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13318
|
+
* const mapped = ms.map((key, count) => [key * 10, count]);
|
|
13319
|
+
* // TreeMultiSet { 10: 2, 20: 1, 30: 3 }
|
|
13320
|
+
* @example
|
|
13321
|
+
* // Collision: counts merge
|
|
13322
|
+
* const ms = new TreeMultiSet([1, 2, 3]);
|
|
13323
|
+
* const merged = ms.map((key, count) => [key % 2, count]);
|
|
13324
|
+
* // { 0: 1, 1: 2 } (1 and 3 both map to 1, counts add)
|
|
13325
|
+
*/
|
|
13326
|
+
map(mapper, options) {
|
|
13327
|
+
const result = new _TreeMultiSet([], {
|
|
13328
|
+
comparator: options == null ? void 0 : options.comparator,
|
|
13329
|
+
isMapMode: __privateGet(this, _core4)._isMapMode
|
|
13330
|
+
});
|
|
13331
|
+
for (const [k, c] of this.entries()) {
|
|
13332
|
+
const [newKey, newCount] = mapper(k, c);
|
|
13333
|
+
result.add(newKey, newCount);
|
|
13334
|
+
}
|
|
13335
|
+
return result;
|
|
13336
|
+
}
|
|
13337
|
+
/**
|
|
13338
|
+
* Creates an independent copy of this multiset.
|
|
13339
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13340
|
+
* @example
|
|
13341
|
+
* const ms = new TreeMultiSet([1, 1, 2]);
|
|
13342
|
+
* const copy = ms.clone();
|
|
13343
|
+
* copy.add(3);
|
|
13344
|
+
* ms.has(3); // false (original unchanged)
|
|
13345
|
+
*/
|
|
13346
|
+
clone() {
|
|
13347
|
+
const result = new _TreeMultiSet([], {
|
|
13348
|
+
comparator: __privateGet(this, _isDefaultComparator4) ? void 0 : this.comparator,
|
|
13349
|
+
isMapMode: __privateGet(this, _core4)._isMapMode
|
|
13350
|
+
});
|
|
13351
|
+
for (const [k, c] of this.entries()) {
|
|
13352
|
+
result.add(k, c);
|
|
13353
|
+
}
|
|
13354
|
+
return result;
|
|
13355
|
+
}
|
|
13356
|
+
// ━━━ Tree utilities ━━━
|
|
13357
|
+
/**
|
|
13358
|
+
* Returns keys within the given range.
|
|
13359
|
+
* @remarks Time O(log n + k), Space O(k) where k is result size
|
|
13360
|
+
* @example
|
|
13361
|
+
* const ms = new TreeMultiSet([10, 20, 30, 40, 50]);
|
|
13362
|
+
* ms.rangeSearch([15, 45]); // [20, 30, 40]
|
|
13363
|
+
*/
|
|
13364
|
+
rangeSearch(range, callback) {
|
|
13365
|
+
const cb = callback != null ? callback : ((k) => k);
|
|
13366
|
+
return __privateGet(this, _core4).rangeSearch(range, (node) => cb(node.key));
|
|
13367
|
+
}
|
|
13368
|
+
/**
|
|
13369
|
+
* Prints the internal tree structure (for debugging).
|
|
13370
|
+
* @remarks Time O(n), Space O(n)
|
|
13371
|
+
* @example
|
|
13372
|
+
* const ms = new TreeMultiSet([1, 2, 3]);
|
|
13373
|
+
* ms.print();
|
|
13374
|
+
*/
|
|
13375
|
+
print() {
|
|
13376
|
+
__privateGet(this, _core4).print();
|
|
13284
13377
|
}
|
|
13285
13378
|
};
|
|
13286
|
-
|
|
13287
|
-
|
|
13379
|
+
_core4 = new WeakMap();
|
|
13380
|
+
_isDefaultComparator4 = new WeakMap();
|
|
13381
|
+
__name(_TreeMultiSet, "TreeMultiSet");
|
|
13382
|
+
var TreeMultiSet = _TreeMultiSet;
|
|
13288
13383
|
|
|
13289
13384
|
// src/data-structures/priority-queue/priority-queue.ts
|
|
13290
13385
|
var _PriorityQueue = class _PriorityQueue extends Heap {
|
|
@@ -14491,6 +14586,13 @@ var TreeNode = _TreeNode;
|
|
|
14491
14586
|
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
14492
14587
|
* @license MIT License
|
|
14493
14588
|
*/
|
|
14589
|
+
/**
|
|
14590
|
+
* data-structure-typed
|
|
14591
|
+
*
|
|
14592
|
+
* @author Pablo Zeng
|
|
14593
|
+
* @copyright Copyright (c) 2022 Pablo Zeng
|
|
14594
|
+
* @license MIT License
|
|
14595
|
+
*/
|
|
14494
14596
|
/**
|
|
14495
14597
|
* data-structure-typed
|
|
14496
14598
|
*
|
|
@@ -14500,10 +14602,6 @@ var TreeNode = _TreeNode;
|
|
|
14500
14602
|
*/
|
|
14501
14603
|
|
|
14502
14604
|
exports.AVLTree = AVLTree;
|
|
14503
|
-
exports.AVLTreeCounter = AVLTreeCounter;
|
|
14504
|
-
exports.AVLTreeCounterNode = AVLTreeCounterNode;
|
|
14505
|
-
exports.AVLTreeMultiMap = AVLTreeMultiMap;
|
|
14506
|
-
exports.AVLTreeMultiMapNode = AVLTreeMultiMapNode;
|
|
14507
14605
|
exports.AVLTreeNode = AVLTreeNode;
|
|
14508
14606
|
exports.AbstractEdge = AbstractEdge;
|
|
14509
14607
|
exports.AbstractGraph = AbstractGraph;
|
|
@@ -14550,11 +14648,12 @@ exports.SinglyLinkedListNode = SinglyLinkedListNode;
|
|
|
14550
14648
|
exports.SkipList = SkipList;
|
|
14551
14649
|
exports.SkipListNode = SkipListNode;
|
|
14552
14650
|
exports.Stack = Stack;
|
|
14553
|
-
exports.
|
|
14554
|
-
exports.TreeCounterNode = TreeCounterNode;
|
|
14651
|
+
exports.TreeMap = TreeMap;
|
|
14555
14652
|
exports.TreeMultiMap = TreeMultiMap;
|
|
14556
14653
|
exports.TreeMultiMapNode = TreeMultiMapNode;
|
|
14654
|
+
exports.TreeMultiSet = TreeMultiSet;
|
|
14557
14655
|
exports.TreeNode = TreeNode;
|
|
14656
|
+
exports.TreeSet = TreeSet;
|
|
14558
14657
|
exports.Trie = Trie;
|
|
14559
14658
|
exports.TrieNode = TrieNode;
|
|
14560
14659
|
exports.UndirectedEdge = UndirectedEdge;
|