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,7 +1,14 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
2
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
9
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
10
|
+
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);
|
|
11
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
5
12
|
|
|
6
13
|
// src/data-structures/base/iterable-entry-base.ts
|
|
7
14
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
@@ -6993,6 +7000,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
6993
7000
|
__publicField(this, "iterationType", "ITERATIVE");
|
|
6994
7001
|
__publicField(this, "_isMapMode", true);
|
|
6995
7002
|
__publicField(this, "_isDuplicate", false);
|
|
7003
|
+
// Map mode acceleration store:
|
|
7004
|
+
// - isMapMode=false: unused
|
|
7005
|
+
// - isMapMode=true: key -> node reference (O(1) has/getNode + fast get)
|
|
6996
7006
|
__publicField(this, "_store", /* @__PURE__ */ new Map());
|
|
6997
7007
|
__publicField(this, "_root");
|
|
6998
7008
|
__publicField(this, "_size", 0);
|
|
@@ -7088,7 +7098,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7088
7098
|
* @returns The newly created node.
|
|
7089
7099
|
*/
|
|
7090
7100
|
createNode(key, value) {
|
|
7091
|
-
return new BinaryTreeNode(key,
|
|
7101
|
+
return new BinaryTreeNode(key, value);
|
|
7092
7102
|
}
|
|
7093
7103
|
/**
|
|
7094
7104
|
* Creates a new, empty tree of the same type and configuration.
|
|
@@ -7235,11 +7245,11 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7235
7245
|
* @returns True if the addition was successful, false otherwise.
|
|
7236
7246
|
*/
|
|
7237
7247
|
set(keyNodeOrEntry, value) {
|
|
7238
|
-
const [newNode
|
|
7248
|
+
const [newNode] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
7239
7249
|
if (newNode === void 0) return false;
|
|
7240
7250
|
if (!this._root) {
|
|
7241
7251
|
this._setRoot(newNode);
|
|
7242
|
-
if (this._isMapMode
|
|
7252
|
+
if (this._isMapMode && newNode !== null && newNode !== void 0) this._store.set(newNode.key, newNode);
|
|
7243
7253
|
this._size = 1;
|
|
7244
7254
|
return true;
|
|
7245
7255
|
}
|
|
@@ -7251,7 +7261,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7251
7261
|
if (!this._isDuplicate) {
|
|
7252
7262
|
if (newNode !== null && cur.key === newNode.key) {
|
|
7253
7263
|
this._replaceNode(cur, newNode);
|
|
7254
|
-
if (this._isMapMode) this.
|
|
7264
|
+
if (this._isMapMode && newNode !== null) this._store.set(cur.key, newNode);
|
|
7255
7265
|
return true;
|
|
7256
7266
|
}
|
|
7257
7267
|
}
|
|
@@ -7271,7 +7281,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7271
7281
|
} else if (potentialParent.right === void 0) {
|
|
7272
7282
|
potentialParent.right = newNode;
|
|
7273
7283
|
}
|
|
7274
|
-
if (this._isMapMode
|
|
7284
|
+
if (this._isMapMode && newNode !== null && newNode !== void 0) this._store.set(newNode.key, newNode);
|
|
7275
7285
|
this._size++;
|
|
7276
7286
|
return true;
|
|
7277
7287
|
}
|
|
@@ -7356,6 +7366,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7356
7366
|
if (leftSubTreeRightMost) {
|
|
7357
7367
|
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
7358
7368
|
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
7369
|
+
if (this._isMapMode) {
|
|
7370
|
+
this._store.set(curr.key, curr);
|
|
7371
|
+
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
7372
|
+
}
|
|
7359
7373
|
if (parentOfLeftSubTreeMax) {
|
|
7360
7374
|
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
7361
7375
|
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
@@ -7439,6 +7453,13 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7439
7453
|
* @returns The first matching node, or undefined if not found.
|
|
7440
7454
|
*/
|
|
7441
7455
|
getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7456
|
+
if (this._isMapMode && keyNodeEntryOrPredicate !== null && keyNodeEntryOrPredicate !== void 0) {
|
|
7457
|
+
if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
7458
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7459
|
+
if (key === null || key === void 0) return;
|
|
7460
|
+
return this._store.get(key);
|
|
7461
|
+
}
|
|
7462
|
+
}
|
|
7442
7463
|
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType)[0];
|
|
7443
7464
|
}
|
|
7444
7465
|
/**
|
|
@@ -7451,15 +7472,22 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7451
7472
|
* @returns The associated value, or undefined.
|
|
7452
7473
|
*/
|
|
7453
7474
|
get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7454
|
-
var _a;
|
|
7475
|
+
var _a, _b;
|
|
7455
7476
|
if (this._isMapMode) {
|
|
7456
7477
|
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7457
7478
|
if (key === null || key === void 0) return;
|
|
7458
|
-
return this._store.get(key);
|
|
7479
|
+
return (_a = this._store.get(key)) == null ? void 0 : _a.value;
|
|
7459
7480
|
}
|
|
7460
|
-
return (
|
|
7481
|
+
return (_b = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _b.value;
|
|
7461
7482
|
}
|
|
7462
7483
|
has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
|
|
7484
|
+
if (this._isMapMode && keyNodeEntryOrPredicate !== void 0 && keyNodeEntryOrPredicate !== null) {
|
|
7485
|
+
if (!this._isPredicate(keyNodeEntryOrPredicate)) {
|
|
7486
|
+
const key = this._extractKey(keyNodeEntryOrPredicate);
|
|
7487
|
+
if (key === null || key === void 0) return false;
|
|
7488
|
+
return this._store.has(key);
|
|
7489
|
+
}
|
|
7490
|
+
}
|
|
7463
7491
|
return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
|
|
7464
7492
|
}
|
|
7465
7493
|
/**
|
|
@@ -8204,8 +8232,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8204
8232
|
}
|
|
8205
8233
|
current = stack.pop();
|
|
8206
8234
|
if (this.isRealNode(current)) {
|
|
8207
|
-
|
|
8208
|
-
else yield [current.key, current.value];
|
|
8235
|
+
yield [current.key, current.value];
|
|
8209
8236
|
current = current.right;
|
|
8210
8237
|
}
|
|
8211
8238
|
}
|
|
@@ -8213,8 +8240,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8213
8240
|
if (node.left && this.isRealNode(node)) {
|
|
8214
8241
|
yield* this[Symbol.iterator](node.left);
|
|
8215
8242
|
}
|
|
8216
|
-
|
|
8217
|
-
else yield [node.key, node.value];
|
|
8243
|
+
yield [node.key, node.value];
|
|
8218
8244
|
if (node.right && this.isRealNode(node)) {
|
|
8219
8245
|
yield* this[Symbol.iterator](node.right);
|
|
8220
8246
|
}
|
|
@@ -8292,8 +8318,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8292
8318
|
(node) => {
|
|
8293
8319
|
if (node === null) cloned.set(null);
|
|
8294
8320
|
else {
|
|
8295
|
-
|
|
8296
|
-
else cloned.set([node.key, node.value]);
|
|
8321
|
+
cloned.set([node.key, node.value]);
|
|
8297
8322
|
}
|
|
8298
8323
|
},
|
|
8299
8324
|
this._root,
|
|
@@ -8301,7 +8326,6 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8301
8326
|
true
|
|
8302
8327
|
// Include nulls
|
|
8303
8328
|
);
|
|
8304
|
-
if (this._isMapMode) cloned._store = this._store;
|
|
8305
8329
|
}
|
|
8306
8330
|
/**
|
|
8307
8331
|
* (Protected) Recursive helper for `toVisual`.
|
|
@@ -8464,8 +8488,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8464
8488
|
*/
|
|
8465
8489
|
_setValue(key, value) {
|
|
8466
8490
|
if (key === null || key === void 0) return false;
|
|
8467
|
-
|
|
8468
|
-
|
|
8491
|
+
const node = this._store.get(key);
|
|
8492
|
+
if (!node) return false;
|
|
8493
|
+
node.value = value;
|
|
8494
|
+
return true;
|
|
8469
8495
|
}
|
|
8470
8496
|
/**
|
|
8471
8497
|
* (Protected) Clears all nodes from the tree.
|
|
@@ -8674,7 +8700,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8674
8700
|
* @returns The newly created BSTNode.
|
|
8675
8701
|
*/
|
|
8676
8702
|
createNode(key, value) {
|
|
8677
|
-
return new BSTNode(key,
|
|
8703
|
+
return new BSTNode(key, value);
|
|
8678
8704
|
}
|
|
8679
8705
|
/**
|
|
8680
8706
|
* Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
@@ -8915,11 +8941,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8915
8941
|
* @returns True if the addition was successful, false otherwise.
|
|
8916
8942
|
*/
|
|
8917
8943
|
set(keyNodeOrEntry, value) {
|
|
8918
|
-
const [newNode
|
|
8944
|
+
const [newNode] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
8919
8945
|
if (newNode === void 0) return false;
|
|
8920
8946
|
if (this._root === void 0) {
|
|
8921
8947
|
this._setRoot(newNode);
|
|
8922
|
-
if (this._isMapMode
|
|
8948
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
8923
8949
|
this._size++;
|
|
8924
8950
|
return true;
|
|
8925
8951
|
}
|
|
@@ -8927,12 +8953,12 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8927
8953
|
while (current !== void 0) {
|
|
8928
8954
|
if (this._compare(current.key, newNode.key) === 0) {
|
|
8929
8955
|
this._replaceNode(current, newNode);
|
|
8930
|
-
if (this._isMapMode) this.
|
|
8956
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(current.key, newNode);
|
|
8931
8957
|
return true;
|
|
8932
8958
|
} else if (this._compare(current.key, newNode.key) > 0) {
|
|
8933
8959
|
if (current.left === void 0) {
|
|
8934
8960
|
current.left = newNode;
|
|
8935
|
-
if (this._isMapMode
|
|
8961
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
8936
8962
|
this._size++;
|
|
8937
8963
|
return true;
|
|
8938
8964
|
}
|
|
@@ -8940,7 +8966,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8940
8966
|
} else {
|
|
8941
8967
|
if (current.right === void 0) {
|
|
8942
8968
|
current.right = newNode;
|
|
8943
|
-
if (this._isMapMode
|
|
8969
|
+
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
8944
8970
|
this._size++;
|
|
8945
8971
|
return true;
|
|
8946
8972
|
}
|
|
@@ -10495,7 +10521,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10495
10521
|
* @returns The newly created AVLTreeNode.
|
|
10496
10522
|
*/
|
|
10497
10523
|
createNode(key, value) {
|
|
10498
|
-
return new AVLTreeNode(key,
|
|
10524
|
+
return new AVLTreeNode(key, value);
|
|
10499
10525
|
}
|
|
10500
10526
|
/**
|
|
10501
10527
|
* Checks if the given item is an `AVLTreeNode` instance.
|
|
@@ -11049,7 +11075,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11049
11075
|
* @returns A new RedBlackTreeNode instance.
|
|
11050
11076
|
*/
|
|
11051
11077
|
createNode(key, value, color = "BLACK") {
|
|
11052
|
-
return new RedBlackTreeNode(key,
|
|
11078
|
+
return new RedBlackTreeNode(key, value, color);
|
|
11053
11079
|
}
|
|
11054
11080
|
/**
|
|
11055
11081
|
* Type guard: check whether the input is a RedBlackTreeNode.
|
|
@@ -11200,20 +11226,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11200
11226
|
if (minN !== NIL) {
|
|
11201
11227
|
const cMin = comparator(key, minN.key);
|
|
11202
11228
|
if (cMin === 0) {
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
else this._setValue(key, nextValue);
|
|
11206
|
-
} else minN.value = nextValue;
|
|
11229
|
+
minN.value = nextValue;
|
|
11230
|
+
if (this._isMapMode) this._store.set(key, minN);
|
|
11207
11231
|
return { node: minN, created: false };
|
|
11208
11232
|
}
|
|
11209
11233
|
const minL = minN.left;
|
|
11210
11234
|
if (cMin < 0 && (minL === NIL || minL === null || minL === void 0)) {
|
|
11211
11235
|
const newNode2 = this.createNode(key, nextValue);
|
|
11212
11236
|
this._attachNewNode(minN, "left", newNode2);
|
|
11213
|
-
if (this._isMapMode)
|
|
11214
|
-
if (nextValue !== void 0) this._store.set(newNode2.key, nextValue);
|
|
11215
|
-
else this._setValue(newNode2.key, nextValue);
|
|
11216
|
-
}
|
|
11237
|
+
if (this._isMapMode) this._store.set(newNode2.key, newNode2);
|
|
11217
11238
|
this._size++;
|
|
11218
11239
|
this._setMinCache(newNode2);
|
|
11219
11240
|
if (header._right === NIL) this._setMaxCache(newNode2);
|
|
@@ -11223,20 +11244,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11223
11244
|
const maxN = (_b = header._right) != null ? _b : NIL;
|
|
11224
11245
|
const cMax = comparator(key, maxN.key);
|
|
11225
11246
|
if (cMax === 0) {
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
else this._setValue(key, nextValue);
|
|
11229
|
-
} else maxN.value = nextValue;
|
|
11247
|
+
maxN.value = nextValue;
|
|
11248
|
+
if (this._isMapMode) this._store.set(key, maxN);
|
|
11230
11249
|
return { node: maxN, created: false };
|
|
11231
11250
|
}
|
|
11232
11251
|
const maxR = maxN.right;
|
|
11233
11252
|
if (cMax > 0 && (maxR === NIL || maxR === null || maxR === void 0)) {
|
|
11234
11253
|
const newNode2 = this.createNode(key, nextValue);
|
|
11235
11254
|
this._attachNewNode(maxN, "right", newNode2);
|
|
11236
|
-
if (this._isMapMode)
|
|
11237
|
-
if (nextValue !== void 0) this._store.set(newNode2.key, nextValue);
|
|
11238
|
-
else this._setValue(newNode2.key, nextValue);
|
|
11239
|
-
}
|
|
11255
|
+
if (this._isMapMode) this._store.set(newNode2.key, newNode2);
|
|
11240
11256
|
this._size++;
|
|
11241
11257
|
this._setMaxCache(newNode2);
|
|
11242
11258
|
if (header._left === NIL) this._setMinCache(newNode2);
|
|
@@ -11256,12 +11272,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11256
11272
|
if (lastCompared < 0) current = (_d = current.left) != null ? _d : NIL;
|
|
11257
11273
|
else if (lastCompared > 0) current = (_e = current.right) != null ? _e : NIL;
|
|
11258
11274
|
else {
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
else this._setValue(key, nextValue);
|
|
11262
|
-
} else {
|
|
11263
|
-
current.value = nextValue;
|
|
11264
|
-
}
|
|
11275
|
+
current.value = nextValue;
|
|
11276
|
+
if (isMapMode) store.set(key, current);
|
|
11265
11277
|
return { node: current, created: false };
|
|
11266
11278
|
}
|
|
11267
11279
|
}
|
|
@@ -11280,10 +11292,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11280
11292
|
this._insertFixup(newNode);
|
|
11281
11293
|
if (this.isRealNode(this._root)) this._root.color = "BLACK";
|
|
11282
11294
|
else return void 0;
|
|
11283
|
-
if (isMapMode)
|
|
11284
|
-
if (nextValue !== void 0) store.set(newNode.key, nextValue);
|
|
11285
|
-
else this._setValue(newNode.key, nextValue);
|
|
11286
|
-
}
|
|
11295
|
+
if (isMapMode) store.set(newNode.key, newNode);
|
|
11287
11296
|
this._size++;
|
|
11288
11297
|
const hMin = (_f = this._header._left) != null ? _f : NIL;
|
|
11289
11298
|
const hMax = (_g = this._header._right) != null ? _g : NIL;
|
|
@@ -11311,10 +11320,11 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11311
11320
|
* @remarks Time O(log n) average, Space O(1)
|
|
11312
11321
|
*/
|
|
11313
11322
|
_setKV(key, nextValue) {
|
|
11314
|
-
if (this._isMapMode
|
|
11323
|
+
if (this._isMapMode) {
|
|
11315
11324
|
const store = this._store;
|
|
11316
|
-
|
|
11317
|
-
|
|
11325
|
+
const node = store.get(key);
|
|
11326
|
+
if (node) {
|
|
11327
|
+
node.value = nextValue;
|
|
11318
11328
|
return true;
|
|
11319
11329
|
}
|
|
11320
11330
|
}
|
|
@@ -11339,10 +11349,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11339
11349
|
const cmp = this._compare.bind(this);
|
|
11340
11350
|
const c0 = cmp(key, hint.key);
|
|
11341
11351
|
if (c0 === 0) {
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
else this._setValue(key, value);
|
|
11345
|
-
} else hint.value = value;
|
|
11352
|
+
hint.value = value;
|
|
11353
|
+
if (this._isMapMode) this._store.set(key, hint);
|
|
11346
11354
|
return hint;
|
|
11347
11355
|
}
|
|
11348
11356
|
if (c0 < 0) {
|
|
@@ -11350,10 +11358,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11350
11358
|
const newNode = this.createNode(key, value);
|
|
11351
11359
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11352
11360
|
this._attachNewNode(hint, "left", newNode);
|
|
11353
|
-
if (this._isMapMode)
|
|
11354
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11355
|
-
else this._setValue(key, value);
|
|
11356
|
-
}
|
|
11361
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11357
11362
|
this._size++;
|
|
11358
11363
|
const NIL = this.NIL;
|
|
11359
11364
|
const hMin = (_b = this._header._left) != null ? _b : NIL;
|
|
@@ -11370,10 +11375,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11370
11375
|
const newNode = this.createNode(key, value);
|
|
11371
11376
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11372
11377
|
this._attachNewNode(pred, "right", newNode);
|
|
11373
|
-
if (this._isMapMode)
|
|
11374
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11375
|
-
else this._setValue(key, value);
|
|
11376
|
-
}
|
|
11378
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11377
11379
|
this._size++;
|
|
11378
11380
|
const NIL = this.NIL;
|
|
11379
11381
|
const hMin = (_e = this._header._left) != null ? _e : NIL;
|
|
@@ -11388,10 +11390,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11388
11390
|
const newNode = this.createNode(key, value);
|
|
11389
11391
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11390
11392
|
this._attachNewNode(hint, "right", newNode);
|
|
11391
|
-
if (this._isMapMode)
|
|
11392
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11393
|
-
else this._setValue(key, value);
|
|
11394
|
-
}
|
|
11393
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11395
11394
|
this._size++;
|
|
11396
11395
|
const NIL = this.NIL;
|
|
11397
11396
|
const hMin = (_h = this._header._left) != null ? _h : NIL;
|
|
@@ -11408,10 +11407,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11408
11407
|
const newNode = this.createNode(key, value);
|
|
11409
11408
|
if (!this.isRealNode(newNode)) return void 0;
|
|
11410
11409
|
this._attachNewNode(succ, "left", newNode);
|
|
11411
|
-
if (this._isMapMode)
|
|
11412
|
-
if (value !== void 0) this._store.set(key, value);
|
|
11413
|
-
else this._setValue(key, value);
|
|
11414
|
-
}
|
|
11410
|
+
if (this._isMapMode) this._store.set(key, newNode);
|
|
11415
11411
|
this._size++;
|
|
11416
11412
|
const NIL = this.NIL;
|
|
11417
11413
|
const hMin = (_k = this._header._left) != null ? _k : NIL;
|
|
@@ -11458,12 +11454,24 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11458
11454
|
} else {
|
|
11459
11455
|
return false;
|
|
11460
11456
|
}
|
|
11461
|
-
if (this._isMapMode)
|
|
11457
|
+
if (this._isMapMode) {
|
|
11458
|
+
const n = this.getNode(newNode.key);
|
|
11459
|
+
if (this.isRealNode(n)) {
|
|
11460
|
+
n.value = newValue;
|
|
11461
|
+
this._store.set(n.key, n);
|
|
11462
|
+
}
|
|
11463
|
+
}
|
|
11462
11464
|
this._size++;
|
|
11463
11465
|
return true;
|
|
11464
11466
|
}
|
|
11465
11467
|
if (insertStatus === "UPDATED") {
|
|
11466
|
-
if (this._isMapMode)
|
|
11468
|
+
if (this._isMapMode) {
|
|
11469
|
+
const n = this.getNode(newNode.key);
|
|
11470
|
+
if (this.isRealNode(n)) {
|
|
11471
|
+
n.value = newValue;
|
|
11472
|
+
this._store.set(n.key, n);
|
|
11473
|
+
}
|
|
11474
|
+
}
|
|
11467
11475
|
return true;
|
|
11468
11476
|
}
|
|
11469
11477
|
return false;
|
|
@@ -11833,1456 +11841,1543 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11833
11841
|
__name(_RedBlackTree, "RedBlackTree");
|
|
11834
11842
|
var RedBlackTree = _RedBlackTree;
|
|
11835
11843
|
|
|
11836
|
-
// src/data-structures/binary-tree/
|
|
11837
|
-
var
|
|
11844
|
+
// src/data-structures/binary-tree/tree-set.ts
|
|
11845
|
+
var _core, _isDefaultComparator, _userComparator;
|
|
11846
|
+
var _TreeSet = class _TreeSet {
|
|
11838
11847
|
/**
|
|
11839
|
-
* Create
|
|
11840
|
-
*
|
|
11841
|
-
* @
|
|
11842
|
-
*
|
|
11843
|
-
* @returns New AVLTreeMultiMapNode instance.
|
|
11848
|
+
* Create a TreeSet from an iterable of keys.
|
|
11849
|
+
*
|
|
11850
|
+
* @throws {TypeError} When using the default comparator and encountering unsupported key types,
|
|
11851
|
+
* or invalid keys (e.g. `NaN`, invalid `Date`).
|
|
11844
11852
|
*/
|
|
11845
|
-
constructor(
|
|
11846
|
-
|
|
11847
|
-
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
this.
|
|
11855
|
-
this.value = value;
|
|
11853
|
+
constructor(elements = [], options = {}) {
|
|
11854
|
+
__privateAdd(this, _core);
|
|
11855
|
+
__privateAdd(this, _isDefaultComparator);
|
|
11856
|
+
__privateAdd(this, _userComparator);
|
|
11857
|
+
var _a;
|
|
11858
|
+
__privateSet(this, _userComparator, options.comparator);
|
|
11859
|
+
const comparator = (_a = options.comparator) != null ? _a : _TreeSet.createDefaultComparator();
|
|
11860
|
+
__privateSet(this, _isDefaultComparator, options.comparator === void 0);
|
|
11861
|
+
__privateSet(this, _core, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
11862
|
+
for (const k of elements) this.add(k);
|
|
11856
11863
|
}
|
|
11857
11864
|
/**
|
|
11858
|
-
*
|
|
11859
|
-
*
|
|
11860
|
-
*
|
|
11865
|
+
* Create the strict default comparator.
|
|
11866
|
+
*
|
|
11867
|
+
* Supports:
|
|
11868
|
+
* - `number` (rejects `NaN`; treats `-0` and `0` as equal)
|
|
11869
|
+
* - `string`
|
|
11870
|
+
* - `Date` (orders by `getTime()`, rejects invalid dates)
|
|
11871
|
+
*
|
|
11872
|
+
* For other key types, a custom comparator must be provided.
|
|
11861
11873
|
*/
|
|
11862
|
-
|
|
11863
|
-
return
|
|
11874
|
+
static createDefaultComparator() {
|
|
11875
|
+
return (a, b) => {
|
|
11876
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
11877
|
+
if (Number.isNaN(a) || Number.isNaN(b)) throw new TypeError("TreeSet: NaN is not a valid key");
|
|
11878
|
+
const aa = Object.is(a, -0) ? 0 : a;
|
|
11879
|
+
const bb = Object.is(b, -0) ? 0 : b;
|
|
11880
|
+
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
11881
|
+
}
|
|
11882
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
11883
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
11884
|
+
}
|
|
11885
|
+
if (a instanceof Date && b instanceof Date) {
|
|
11886
|
+
const ta = a.getTime();
|
|
11887
|
+
const tb = b.getTime();
|
|
11888
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) throw new TypeError("TreeSet: invalid Date key");
|
|
11889
|
+
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
11890
|
+
}
|
|
11891
|
+
throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys");
|
|
11892
|
+
};
|
|
11864
11893
|
}
|
|
11865
11894
|
/**
|
|
11866
|
-
*
|
|
11867
|
-
* @remarks Time O(1), Space O(1)
|
|
11868
|
-
* @param v - New left child node, or null/undefined.
|
|
11869
|
-
* @returns void
|
|
11895
|
+
* Number of elements in the set.
|
|
11870
11896
|
*/
|
|
11871
|
-
|
|
11872
|
-
|
|
11873
|
-
|
|
11897
|
+
get size() {
|
|
11898
|
+
return __privateGet(this, _core).size;
|
|
11899
|
+
}
|
|
11900
|
+
/**
|
|
11901
|
+
* Whether the set is empty.
|
|
11902
|
+
*/
|
|
11903
|
+
isEmpty() {
|
|
11904
|
+
return this.size === 0;
|
|
11905
|
+
}
|
|
11906
|
+
_validateKey(key) {
|
|
11907
|
+
if (!__privateGet(this, _isDefaultComparator)) return;
|
|
11908
|
+
if (typeof key === "number") {
|
|
11909
|
+
if (Number.isNaN(key)) throw new TypeError("TreeSet: NaN is not a valid key");
|
|
11910
|
+
return;
|
|
11874
11911
|
}
|
|
11875
|
-
|
|
11912
|
+
if (typeof key === "string") return;
|
|
11913
|
+
if (key instanceof Date) {
|
|
11914
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeSet: invalid Date key");
|
|
11915
|
+
return;
|
|
11916
|
+
}
|
|
11917
|
+
throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys");
|
|
11876
11918
|
}
|
|
11877
11919
|
/**
|
|
11878
|
-
*
|
|
11879
|
-
* @remarks
|
|
11880
|
-
* @returns Right child node, or null/undefined.
|
|
11920
|
+
* Add a key to the set (no-op if already present).
|
|
11921
|
+
* @remarks Expected time O(log n)
|
|
11881
11922
|
*/
|
|
11882
|
-
|
|
11883
|
-
|
|
11923
|
+
add(key) {
|
|
11924
|
+
this._validateKey(key);
|
|
11925
|
+
__privateGet(this, _core).set(key, void 0);
|
|
11926
|
+
return this;
|
|
11884
11927
|
}
|
|
11885
11928
|
/**
|
|
11886
|
-
*
|
|
11887
|
-
* @remarks
|
|
11888
|
-
* @param v - New right child node, or null/undefined.
|
|
11889
|
-
* @returns void
|
|
11929
|
+
* Test whether a key exists.
|
|
11930
|
+
* @remarks Expected time O(log n)
|
|
11890
11931
|
*/
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
}
|
|
11895
|
-
this._right = v;
|
|
11932
|
+
has(key) {
|
|
11933
|
+
this._validateKey(key);
|
|
11934
|
+
return __privateGet(this, _core).has(key);
|
|
11896
11935
|
}
|
|
11897
11936
|
/**
|
|
11898
|
-
*
|
|
11899
|
-
* @
|
|
11900
|
-
*
|
|
11901
|
-
* @returns The height.
|
|
11937
|
+
* Delete a key.
|
|
11938
|
+
* @returns `true` if the key existed; otherwise `false`.
|
|
11939
|
+
* @remarks Expected time O(log n)
|
|
11902
11940
|
*/
|
|
11903
|
-
|
|
11904
|
-
|
|
11941
|
+
delete(key) {
|
|
11942
|
+
var _a;
|
|
11943
|
+
this._validateKey(key);
|
|
11944
|
+
const res = __privateGet(this, _core).delete(key);
|
|
11945
|
+
return Array.isArray(res) && res.length > 0 && !!((_a = res[0]) == null ? void 0 : _a.deleted);
|
|
11905
11946
|
}
|
|
11906
11947
|
/**
|
|
11907
|
-
*
|
|
11908
|
-
* @remarks Time O(1), Space O(1)
|
|
11909
|
-
*
|
|
11910
|
-
* @param value - The new height.
|
|
11948
|
+
* Remove all keys.
|
|
11911
11949
|
*/
|
|
11912
|
-
|
|
11913
|
-
this.
|
|
11950
|
+
clear() {
|
|
11951
|
+
__privateGet(this, _core).clear();
|
|
11914
11952
|
}
|
|
11915
11953
|
/**
|
|
11916
|
-
*
|
|
11917
|
-
* @remarks Time O(1), Space O(1)
|
|
11918
|
-
*
|
|
11919
|
-
* @returns The node's color.
|
|
11954
|
+
* Iterate over keys in ascending order.
|
|
11920
11955
|
*/
|
|
11921
|
-
|
|
11922
|
-
return this.
|
|
11956
|
+
keys() {
|
|
11957
|
+
return __privateGet(this, _core).keys();
|
|
11923
11958
|
}
|
|
11924
11959
|
/**
|
|
11925
|
-
*
|
|
11926
|
-
* @remarks Time O(1), Space O(1)
|
|
11960
|
+
* Iterate over values in ascending order.
|
|
11927
11961
|
*
|
|
11928
|
-
*
|
|
11962
|
+
* Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
11929
11963
|
*/
|
|
11930
|
-
|
|
11931
|
-
this.
|
|
11964
|
+
values() {
|
|
11965
|
+
return this.keys();
|
|
11932
11966
|
}
|
|
11933
11967
|
/**
|
|
11934
|
-
*
|
|
11935
|
-
* @remarks Time O(1), Space O(1)
|
|
11968
|
+
* Iterate over `[value, value]` pairs (native Set convention).
|
|
11936
11969
|
*
|
|
11937
|
-
*
|
|
11970
|
+
* Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
11938
11971
|
*/
|
|
11939
|
-
|
|
11940
|
-
|
|
11972
|
+
*entries() {
|
|
11973
|
+
for (const k of this.keys()) yield [k, k];
|
|
11974
|
+
}
|
|
11975
|
+
[Symbol.iterator]() {
|
|
11976
|
+
return this.keys();
|
|
11941
11977
|
}
|
|
11942
11978
|
/**
|
|
11943
|
-
*
|
|
11944
|
-
* @remarks Time O(1), Space O(1)
|
|
11979
|
+
* Visit each value in ascending order.
|
|
11945
11980
|
*
|
|
11946
|
-
*
|
|
11981
|
+
* Callback follows native Set convention: `(value, value2, set)`.
|
|
11947
11982
|
*/
|
|
11948
|
-
|
|
11949
|
-
this.
|
|
11983
|
+
forEach(cb, thisArg) {
|
|
11984
|
+
for (const k of this) cb.call(thisArg, k, k, this);
|
|
11950
11985
|
}
|
|
11951
11986
|
/**
|
|
11952
|
-
*
|
|
11953
|
-
* @remarks Time O(1), Space O(1)
|
|
11987
|
+
* Create a new TreeSet by mapping each value to a new key.
|
|
11954
11988
|
*
|
|
11955
|
-
*
|
|
11989
|
+
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
11990
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
11956
11991
|
*/
|
|
11957
|
-
|
|
11958
|
-
|
|
11959
|
-
|
|
11960
|
-
|
|
11961
|
-
|
|
11962
|
-
|
|
11963
|
-
} else if (this.parent.right === this) {
|
|
11964
|
-
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
11992
|
+
map(callbackfn, options = {}, thisArg) {
|
|
11993
|
+
const out = new _TreeSet([], options);
|
|
11994
|
+
let index = 0;
|
|
11995
|
+
for (const v of this) {
|
|
11996
|
+
const mk = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
11997
|
+
out.add(mk);
|
|
11965
11998
|
}
|
|
11966
|
-
return
|
|
11999
|
+
return out;
|
|
11967
12000
|
}
|
|
11968
|
-
};
|
|
11969
|
-
__name(_AVLTreeMultiMapNode, "AVLTreeMultiMapNode");
|
|
11970
|
-
var AVLTreeMultiMapNode = _AVLTreeMultiMapNode;
|
|
11971
|
-
var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
11972
12001
|
/**
|
|
11973
|
-
* Create
|
|
11974
|
-
* @remarks Time O(
|
|
11975
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
11976
|
-
* @param [options] - Options for AVLTreeMultiMap (comparator, reverse, map mode).
|
|
11977
|
-
* @returns New AVLTreeMultiMap instance.
|
|
12002
|
+
* Create a new TreeSet containing only values that satisfy the predicate.
|
|
12003
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
11978
12004
|
*/
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
12005
|
+
filter(callbackfn, thisArg) {
|
|
12006
|
+
const out = new _TreeSet([], { comparator: __privateGet(this, _userComparator) });
|
|
12007
|
+
let index = 0;
|
|
12008
|
+
for (const v of this) {
|
|
12009
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12010
|
+
if (ok) out.add(v);
|
|
11983
12011
|
}
|
|
11984
|
-
|
|
11985
|
-
createNode(key, value = []) {
|
|
11986
|
-
return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
12012
|
+
return out;
|
|
11987
12013
|
}
|
|
11988
12014
|
/**
|
|
11989
|
-
*
|
|
11990
|
-
* @remarks Time O(
|
|
11991
|
-
*
|
|
11992
|
-
* @param keyNodeOrEntry - The item to check.
|
|
11993
|
-
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
12015
|
+
* Reduce values into a single accumulator.
|
|
12016
|
+
* @remarks Time O(n), Space O(1)
|
|
11994
12017
|
*/
|
|
11995
|
-
|
|
11996
|
-
|
|
12018
|
+
reduce(callbackfn, initialValue) {
|
|
12019
|
+
let acc = initialValue;
|
|
12020
|
+
let index = 0;
|
|
12021
|
+
for (const v of this) acc = callbackfn(acc, v, index++, this);
|
|
12022
|
+
return acc;
|
|
11997
12023
|
}
|
|
11998
12024
|
/**
|
|
11999
|
-
*
|
|
12000
|
-
* @remarks Time O(
|
|
12001
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
12002
|
-
* @param [value] - Single value to set when a bare key is provided.
|
|
12003
|
-
* @returns True if inserted or appended; false if ignored.
|
|
12025
|
+
* Test whether all values satisfy a predicate.
|
|
12026
|
+
* @remarks Time O(n), Space O(1)
|
|
12004
12027
|
*/
|
|
12005
|
-
|
|
12006
|
-
|
|
12007
|
-
const
|
|
12008
|
-
|
|
12009
|
-
|
|
12010
|
-
const existingValues = this.get(key);
|
|
12011
|
-
if (existingValues !== void 0 && values !== void 0) {
|
|
12012
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12013
|
-
return true;
|
|
12014
|
-
}
|
|
12015
|
-
return false;
|
|
12016
|
-
}, "_setToValues");
|
|
12017
|
-
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
12018
|
-
const existingNode = this.getNode(key);
|
|
12019
|
-
if (this.isRealNode(existingNode)) {
|
|
12020
|
-
const existingValues = this.get(existingNode);
|
|
12021
|
-
if (existingValues === void 0) {
|
|
12022
|
-
super.set(key, values);
|
|
12023
|
-
return true;
|
|
12024
|
-
}
|
|
12025
|
-
if (values !== void 0) {
|
|
12026
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12027
|
-
return true;
|
|
12028
|
-
} else {
|
|
12029
|
-
return false;
|
|
12030
|
-
}
|
|
12031
|
-
} else {
|
|
12032
|
-
return super.set(key, values);
|
|
12033
|
-
}
|
|
12034
|
-
}, "_setByNode");
|
|
12035
|
-
if (this._isMapMode) {
|
|
12036
|
-
return _setByNode() || _setToValues();
|
|
12037
|
-
}
|
|
12038
|
-
return _setToValues() || _setByNode();
|
|
12039
|
-
}, "_commonAdd");
|
|
12040
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
12041
|
-
const [key, values] = keyNodeOrEntry;
|
|
12042
|
-
return _commonAdd(key, value !== void 0 ? [value] : values);
|
|
12028
|
+
every(callbackfn, thisArg) {
|
|
12029
|
+
let index = 0;
|
|
12030
|
+
for (const v of this) {
|
|
12031
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12032
|
+
if (!ok) return false;
|
|
12043
12033
|
}
|
|
12044
|
-
return
|
|
12034
|
+
return true;
|
|
12045
12035
|
}
|
|
12046
12036
|
/**
|
|
12047
|
-
*
|
|
12048
|
-
* @remarks Time O(
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
if (Array.isArray(values)) {
|
|
12056
|
-
const index = values.indexOf(value);
|
|
12057
|
-
if (index === -1) return false;
|
|
12058
|
-
values.splice(index, 1);
|
|
12059
|
-
if (values.length === 0) this.delete(keyNodeOrEntry);
|
|
12060
|
-
return true;
|
|
12037
|
+
* Test whether any value satisfies a predicate.
|
|
12038
|
+
* @remarks Time O(n), Space O(1)
|
|
12039
|
+
*/
|
|
12040
|
+
some(callbackfn, thisArg) {
|
|
12041
|
+
let index = 0;
|
|
12042
|
+
for (const v of this) {
|
|
12043
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12044
|
+
if (ok) return true;
|
|
12061
12045
|
}
|
|
12062
12046
|
return false;
|
|
12063
12047
|
}
|
|
12064
12048
|
/**
|
|
12065
|
-
*
|
|
12066
|
-
* @remarks Time O(
|
|
12067
|
-
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
12068
|
-
* @returns True if rebalancing succeeded (tree not empty).
|
|
12049
|
+
* Find the first value that satisfies a predicate.
|
|
12050
|
+
* @remarks Time O(n), Space O(1)
|
|
12069
12051
|
*/
|
|
12070
|
-
|
|
12071
|
-
|
|
12072
|
-
const
|
|
12073
|
-
|
|
12074
|
-
|
|
12075
|
-
|
|
12076
|
-
|
|
12077
|
-
const m = l + (r - l >> 1);
|
|
12078
|
-
const root = nodes[m];
|
|
12079
|
-
root.left = build(l, m - 1, root);
|
|
12080
|
-
root.right = build(m + 1, r, root);
|
|
12081
|
-
root.parent = parent;
|
|
12082
|
-
const lh = root.left ? root.left.height : -1;
|
|
12083
|
-
const rh = root.right ? root.right.height : -1;
|
|
12084
|
-
root.height = Math.max(lh, rh) + 1;
|
|
12085
|
-
return root;
|
|
12086
|
-
}, "build");
|
|
12087
|
-
const newRoot = build(0, n - 1, void 0);
|
|
12088
|
-
this._setRoot(newRoot);
|
|
12089
|
-
this._size = n;
|
|
12090
|
-
return true;
|
|
12052
|
+
find(callbackfn, thisArg) {
|
|
12053
|
+
let index = 0;
|
|
12054
|
+
for (const v of this) {
|
|
12055
|
+
const ok = thisArg === void 0 ? callbackfn(v, index++, this) : callbackfn.call(thisArg, v, index++, this);
|
|
12056
|
+
if (ok) return v;
|
|
12057
|
+
}
|
|
12058
|
+
return void 0;
|
|
12091
12059
|
}
|
|
12092
12060
|
/**
|
|
12093
|
-
*
|
|
12094
|
-
* @remarks Time O(
|
|
12095
|
-
* @template MK
|
|
12096
|
-
* @template MV
|
|
12097
|
-
* @template MR
|
|
12098
|
-
* @param callback - Function mapping (key, values, index, tree) → [newKey, newValue].
|
|
12099
|
-
* @param [options] - Options for the output tree.
|
|
12100
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
12101
|
-
* @returns The mapped AVLTree or AVLTreeMultiMap depending on MV; see overloads.
|
|
12061
|
+
* Materialize the set into an array of keys.
|
|
12062
|
+
* @remarks Time O(n), Space O(n)
|
|
12102
12063
|
*/
|
|
12103
|
-
|
|
12104
|
-
|
|
12105
|
-
let i = 0;
|
|
12106
|
-
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
12107
|
-
return out;
|
|
12064
|
+
toArray() {
|
|
12065
|
+
return [...this];
|
|
12108
12066
|
}
|
|
12109
12067
|
/**
|
|
12110
|
-
*
|
|
12111
|
-
* @remarks Time O(
|
|
12112
|
-
* @template TK
|
|
12113
|
-
* @template TV
|
|
12114
|
-
* @template TR
|
|
12115
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
12116
|
-
* @returns An empty like-kind instance.
|
|
12068
|
+
* Print a human-friendly representation.
|
|
12069
|
+
* @remarks Time O(n), Space O(n)
|
|
12117
12070
|
*/
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
const Ctor = this.constructor;
|
|
12121
|
-
return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
12071
|
+
print() {
|
|
12072
|
+
__privateGet(this, _core).print();
|
|
12122
12073
|
}
|
|
12074
|
+
// Navigable operations
|
|
12123
12075
|
/**
|
|
12124
|
-
*
|
|
12125
|
-
* @remarks Time O(N log N), Space O(N)
|
|
12126
|
-
* @template TK
|
|
12127
|
-
* @template TV
|
|
12128
|
-
* @template TR
|
|
12129
|
-
* @param iter - Iterable used to seed the new tree.
|
|
12130
|
-
* @param [options] - Options merged with the current snapshot.
|
|
12131
|
-
* @returns A like-kind AVLTree built from the iterable.
|
|
12076
|
+
* Smallest key in the set.
|
|
12132
12077
|
*/
|
|
12133
|
-
|
|
12134
|
-
|
|
12135
|
-
const Ctor = this.constructor;
|
|
12136
|
-
return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
|
|
12078
|
+
first() {
|
|
12079
|
+
return __privateGet(this, _core).getLeftMost();
|
|
12137
12080
|
}
|
|
12138
|
-
};
|
|
12139
|
-
__name(_AVLTreeMultiMap, "AVLTreeMultiMap");
|
|
12140
|
-
var AVLTreeMultiMap = _AVLTreeMultiMap;
|
|
12141
|
-
|
|
12142
|
-
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
12143
|
-
var _TreeMultiMapNode = class _TreeMultiMapNode {
|
|
12144
12081
|
/**
|
|
12145
|
-
*
|
|
12146
|
-
* @remarks Time O(1), Space O(1)
|
|
12147
|
-
* @param key - Key of the node.
|
|
12148
|
-
* @param [value] - Initial array of values.
|
|
12149
|
-
* @returns New TreeMultiMapNode instance.
|
|
12082
|
+
* Largest key in the set.
|
|
12150
12083
|
*/
|
|
12151
|
-
|
|
12152
|
-
|
|
12153
|
-
__publicField(this, "value");
|
|
12154
|
-
__publicField(this, "parent");
|
|
12155
|
-
__publicField(this, "_left");
|
|
12156
|
-
__publicField(this, "_right");
|
|
12157
|
-
__publicField(this, "_height", 0);
|
|
12158
|
-
__publicField(this, "_color", "BLACK");
|
|
12159
|
-
__publicField(this, "_count", 1);
|
|
12160
|
-
this.key = key;
|
|
12161
|
-
this.value = value;
|
|
12162
|
-
this.color = color;
|
|
12084
|
+
last() {
|
|
12085
|
+
return __privateGet(this, _core).getRightMost();
|
|
12163
12086
|
}
|
|
12164
12087
|
/**
|
|
12165
|
-
*
|
|
12166
|
-
* @remarks Time O(1), Space O(1)
|
|
12167
|
-
* @returns Left child node, or null/undefined.
|
|
12088
|
+
* Remove and return the smallest key.
|
|
12168
12089
|
*/
|
|
12169
|
-
|
|
12170
|
-
|
|
12090
|
+
pollFirst() {
|
|
12091
|
+
const k = this.first();
|
|
12092
|
+
if (k === void 0) return void 0;
|
|
12093
|
+
this.delete(k);
|
|
12094
|
+
return k;
|
|
12171
12095
|
}
|
|
12172
12096
|
/**
|
|
12173
|
-
*
|
|
12174
|
-
* @remarks Time O(1), Space O(1)
|
|
12175
|
-
* @param v - New left child node, or null/undefined.
|
|
12176
|
-
* @returns void
|
|
12097
|
+
* Remove and return the largest key.
|
|
12177
12098
|
*/
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12099
|
+
pollLast() {
|
|
12100
|
+
const k = this.last();
|
|
12101
|
+
if (k === void 0) return void 0;
|
|
12102
|
+
this.delete(k);
|
|
12103
|
+
return k;
|
|
12183
12104
|
}
|
|
12184
12105
|
/**
|
|
12185
|
-
*
|
|
12186
|
-
* @remarks Time O(1), Space O(1)
|
|
12187
|
-
* @returns Right child node, or null/undefined.
|
|
12106
|
+
* Smallest key that is >= the given key.
|
|
12188
12107
|
*/
|
|
12189
|
-
|
|
12190
|
-
|
|
12108
|
+
ceiling(key) {
|
|
12109
|
+
this._validateKey(key);
|
|
12110
|
+
return __privateGet(this, _core).ceiling(key);
|
|
12191
12111
|
}
|
|
12192
12112
|
/**
|
|
12193
|
-
*
|
|
12194
|
-
* @remarks Time O(1), Space O(1)
|
|
12195
|
-
* @param v - New right child node, or null/undefined.
|
|
12196
|
-
* @returns void
|
|
12113
|
+
* Largest key that is <= the given key.
|
|
12197
12114
|
*/
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
}
|
|
12202
|
-
this._right = v;
|
|
12115
|
+
floor(key) {
|
|
12116
|
+
this._validateKey(key);
|
|
12117
|
+
return __privateGet(this, _core).floor(key);
|
|
12203
12118
|
}
|
|
12204
12119
|
/**
|
|
12205
|
-
*
|
|
12206
|
-
* @remarks Time O(1), Space O(1)
|
|
12207
|
-
*
|
|
12208
|
-
* @returns The height.
|
|
12120
|
+
* Smallest key that is > the given key.
|
|
12209
12121
|
*/
|
|
12210
|
-
|
|
12211
|
-
|
|
12122
|
+
higher(key) {
|
|
12123
|
+
this._validateKey(key);
|
|
12124
|
+
return __privateGet(this, _core).higher(key);
|
|
12212
12125
|
}
|
|
12213
12126
|
/**
|
|
12214
|
-
*
|
|
12215
|
-
* @remarks Time O(1), Space O(1)
|
|
12216
|
-
*
|
|
12217
|
-
* @param value - The new height.
|
|
12127
|
+
* Largest key that is < the given key.
|
|
12218
12128
|
*/
|
|
12219
|
-
|
|
12220
|
-
this.
|
|
12129
|
+
lower(key) {
|
|
12130
|
+
this._validateKey(key);
|
|
12131
|
+
return __privateGet(this, _core).lower(key);
|
|
12221
12132
|
}
|
|
12222
12133
|
/**
|
|
12223
|
-
*
|
|
12224
|
-
* @remarks Time O(1), Space O(1)
|
|
12134
|
+
* Return all keys in a given range.
|
|
12225
12135
|
*
|
|
12226
|
-
* @
|
|
12136
|
+
* @param range `[low, high]`
|
|
12137
|
+
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
12227
12138
|
*/
|
|
12228
|
-
|
|
12229
|
-
|
|
12139
|
+
rangeSearch(range, options = {}) {
|
|
12140
|
+
const { lowInclusive = true, highInclusive = true } = options;
|
|
12141
|
+
const [low, high] = range;
|
|
12142
|
+
this._validateKey(low);
|
|
12143
|
+
this._validateKey(high);
|
|
12144
|
+
const keys = __privateGet(this, _core).rangeSearch([low, high]);
|
|
12145
|
+
const out = [];
|
|
12146
|
+
const cmp = __privateGet(this, _core).comparator;
|
|
12147
|
+
for (const k of keys) {
|
|
12148
|
+
if (k === void 0) continue;
|
|
12149
|
+
if (!lowInclusive && cmp(k, low) === 0) continue;
|
|
12150
|
+
if (!highInclusive && cmp(k, high) === 0) continue;
|
|
12151
|
+
out.push(k);
|
|
12152
|
+
}
|
|
12153
|
+
return out;
|
|
12154
|
+
}
|
|
12155
|
+
};
|
|
12156
|
+
_core = new WeakMap();
|
|
12157
|
+
_isDefaultComparator = new WeakMap();
|
|
12158
|
+
_userComparator = new WeakMap();
|
|
12159
|
+
__name(_TreeSet, "TreeSet");
|
|
12160
|
+
var TreeSet = _TreeSet;
|
|
12161
|
+
|
|
12162
|
+
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
12163
|
+
var _TreeMultiMapNode = class _TreeMultiMapNode extends RedBlackTreeNode {
|
|
12164
|
+
constructor(key, value = []) {
|
|
12165
|
+
super(key, value);
|
|
12230
12166
|
}
|
|
12167
|
+
};
|
|
12168
|
+
__name(_TreeMultiMapNode, "TreeMultiMapNode");
|
|
12169
|
+
var TreeMultiMapNode = _TreeMultiMapNode;
|
|
12170
|
+
var _core2, _isDefaultComparator2;
|
|
12171
|
+
var _TreeMultiMap = class _TreeMultiMap {
|
|
12231
12172
|
/**
|
|
12232
|
-
*
|
|
12173
|
+
* Creates a new TreeMultiMap.
|
|
12174
|
+
* @param keysNodesEntriesOrRaws - Initial entries
|
|
12175
|
+
* @param options - Configuration options
|
|
12176
|
+
* @remarks Time O(m log m), Space O(m) where m is the number of initial entries
|
|
12177
|
+
*/
|
|
12178
|
+
constructor(keysNodesEntriesOrRaws = [], options = {}) {
|
|
12179
|
+
__privateAdd(this, _core2);
|
|
12180
|
+
__privateAdd(this, _isDefaultComparator2);
|
|
12181
|
+
var _a;
|
|
12182
|
+
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
12183
|
+
__privateSet(this, _isDefaultComparator2, options.comparator === void 0);
|
|
12184
|
+
__privateSet(this, _core2, new RedBlackTree([], { ...options, comparator, isMapMode: options.isMapMode }));
|
|
12185
|
+
for (const x of keysNodesEntriesOrRaws) {
|
|
12186
|
+
if (x === null || x === void 0) continue;
|
|
12187
|
+
if (Array.isArray(x)) {
|
|
12188
|
+
const [k, bucket] = x;
|
|
12189
|
+
if (k === null || k === void 0) continue;
|
|
12190
|
+
if (bucket !== void 0) {
|
|
12191
|
+
__privateGet(this, _core2).set(k, [...bucket]);
|
|
12192
|
+
} else {
|
|
12193
|
+
__privateGet(this, _core2).set(k, []);
|
|
12194
|
+
}
|
|
12195
|
+
continue;
|
|
12196
|
+
}
|
|
12197
|
+
__privateGet(this, _core2).set(x, []);
|
|
12198
|
+
}
|
|
12199
|
+
}
|
|
12200
|
+
/**
|
|
12201
|
+
* Validates the key against the default comparator rules.
|
|
12233
12202
|
* @remarks Time O(1), Space O(1)
|
|
12234
|
-
*
|
|
12235
|
-
* @param value - The new color.
|
|
12236
12203
|
*/
|
|
12237
|
-
|
|
12238
|
-
this
|
|
12204
|
+
_validateKey(key) {
|
|
12205
|
+
if (!__privateGet(this, _isDefaultComparator2)) return;
|
|
12206
|
+
if (typeof key === "number") {
|
|
12207
|
+
if (Number.isNaN(key)) throw new TypeError("TreeMultiMap: NaN is not a valid key");
|
|
12208
|
+
return;
|
|
12209
|
+
}
|
|
12210
|
+
if (typeof key === "string") return;
|
|
12211
|
+
if (key instanceof Date) {
|
|
12212
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeMultiMap: invalid Date key");
|
|
12213
|
+
return;
|
|
12214
|
+
}
|
|
12215
|
+
throw new TypeError("TreeMultiMap: comparator is required for non-number/non-string/non-Date keys");
|
|
12239
12216
|
}
|
|
12240
12217
|
/**
|
|
12241
|
-
*
|
|
12218
|
+
* Number of distinct keys.
|
|
12242
12219
|
* @remarks Time O(1), Space O(1)
|
|
12243
|
-
*
|
|
12244
|
-
* @returns The subtree node count.
|
|
12245
12220
|
*/
|
|
12246
|
-
get
|
|
12247
|
-
return this.
|
|
12221
|
+
get size() {
|
|
12222
|
+
return __privateGet(this, _core2).size;
|
|
12248
12223
|
}
|
|
12249
12224
|
/**
|
|
12250
|
-
*
|
|
12225
|
+
* Whether the map is empty.
|
|
12251
12226
|
* @remarks Time O(1), Space O(1)
|
|
12252
|
-
*
|
|
12253
|
-
* @param value - The new count.
|
|
12254
12227
|
*/
|
|
12255
|
-
|
|
12256
|
-
this.
|
|
12228
|
+
isEmpty() {
|
|
12229
|
+
return this.size === 0;
|
|
12257
12230
|
}
|
|
12258
12231
|
/**
|
|
12259
|
-
*
|
|
12232
|
+
* Removes all entries from the map.
|
|
12260
12233
|
* @remarks Time O(1), Space O(1)
|
|
12261
|
-
*
|
|
12262
|
-
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
12263
12234
|
*/
|
|
12264
|
-
|
|
12265
|
-
|
|
12266
|
-
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
12267
|
-
}
|
|
12268
|
-
if (this.parent.left === this) {
|
|
12269
|
-
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
12270
|
-
} else if (this.parent.right === this) {
|
|
12271
|
-
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
12272
|
-
}
|
|
12273
|
-
return "MAL_NODE";
|
|
12235
|
+
clear() {
|
|
12236
|
+
__privateGet(this, _core2).clear();
|
|
12274
12237
|
}
|
|
12275
|
-
};
|
|
12276
|
-
__name(_TreeMultiMapNode, "TreeMultiMapNode");
|
|
12277
|
-
var TreeMultiMapNode = _TreeMultiMapNode;
|
|
12278
|
-
var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
12279
12238
|
/**
|
|
12280
|
-
*
|
|
12281
|
-
* @remarks Time O(
|
|
12282
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
12283
|
-
* @param [options] - Options for TreeMultiMap (comparator, reverse, map mode).
|
|
12284
|
-
* @returns New TreeMultiMap instance.
|
|
12239
|
+
* Bucket length for a key (missing => 0).
|
|
12240
|
+
* @remarks Time O(log n), Space O(1)
|
|
12285
12241
|
*/
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
this.setMany(keysNodesEntriesOrRaws);
|
|
12290
|
-
}
|
|
12242
|
+
count(key) {
|
|
12243
|
+
const b = this.get(key);
|
|
12244
|
+
return Array.isArray(b) ? b.length : 0;
|
|
12291
12245
|
}
|
|
12292
|
-
|
|
12293
|
-
|
|
12246
|
+
/**
|
|
12247
|
+
* Total number of values across all buckets (Σ bucket.length).
|
|
12248
|
+
* @remarks Time O(n), Space O(1)
|
|
12249
|
+
*/
|
|
12250
|
+
get totalSize() {
|
|
12251
|
+
let sum = 0;
|
|
12252
|
+
for (const [, bucket] of this) sum += bucket.length;
|
|
12253
|
+
return sum;
|
|
12294
12254
|
}
|
|
12295
12255
|
/**
|
|
12296
|
-
*
|
|
12297
|
-
* @remarks Time O(
|
|
12298
|
-
*
|
|
12299
|
-
* @param keyNodeOrEntry - The item to check.
|
|
12300
|
-
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
12256
|
+
* Whether the map contains the given key.
|
|
12257
|
+
* @remarks Time O(log n), Space O(1)
|
|
12301
12258
|
*/
|
|
12302
|
-
|
|
12303
|
-
|
|
12259
|
+
has(key) {
|
|
12260
|
+
this._validateKey(key);
|
|
12261
|
+
return __privateGet(this, _core2).has(key);
|
|
12304
12262
|
}
|
|
12305
12263
|
/**
|
|
12306
|
-
*
|
|
12307
|
-
* @remarks Time O(log
|
|
12308
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
12309
|
-
* @param [value] - Single value to set when a bare key is provided.
|
|
12310
|
-
* @returns True if inserted or appended; false if ignored.
|
|
12264
|
+
* Live bucket reference (do not auto-delete key if bucket becomes empty via mutation).
|
|
12265
|
+
* @remarks Time O(log n), Space O(1)
|
|
12311
12266
|
*/
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
if (key === void 0 || key === null) return false;
|
|
12316
|
-
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
12317
|
-
const existingValues = this.get(key);
|
|
12318
|
-
if (existingValues !== void 0 && values !== void 0) {
|
|
12319
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12320
|
-
return true;
|
|
12321
|
-
}
|
|
12322
|
-
return false;
|
|
12323
|
-
}, "_setToValues");
|
|
12324
|
-
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
12325
|
-
const existingNode = this.getNode(key);
|
|
12326
|
-
if (this.isRealNode(existingNode)) {
|
|
12327
|
-
const existingValues = this.get(existingNode);
|
|
12328
|
-
if (existingValues === void 0) {
|
|
12329
|
-
super.set(key, values);
|
|
12330
|
-
return true;
|
|
12331
|
-
}
|
|
12332
|
-
if (values !== void 0) {
|
|
12333
|
-
for (const value2 of values) existingValues.push(value2);
|
|
12334
|
-
return true;
|
|
12335
|
-
} else {
|
|
12336
|
-
return false;
|
|
12337
|
-
}
|
|
12338
|
-
} else {
|
|
12339
|
-
return super.set(key, values);
|
|
12340
|
-
}
|
|
12341
|
-
}, "_setByNode");
|
|
12342
|
-
if (this._isMapMode) {
|
|
12343
|
-
return _setByNode() || _setToValues();
|
|
12344
|
-
}
|
|
12345
|
-
return _setToValues() || _setByNode();
|
|
12346
|
-
}, "_commonAdd");
|
|
12347
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
12348
|
-
const [key, values] = keyNodeOrEntry;
|
|
12349
|
-
return _commonAdd(key, value !== void 0 ? [value] : values);
|
|
12350
|
-
}
|
|
12351
|
-
return _commonAdd(keyNodeOrEntry, value !== void 0 ? [value] : void 0);
|
|
12267
|
+
get(key) {
|
|
12268
|
+
this._validateKey(key);
|
|
12269
|
+
return __privateGet(this, _core2).get(key);
|
|
12352
12270
|
}
|
|
12353
12271
|
/**
|
|
12354
|
-
*
|
|
12355
|
-
* @remarks Time O(log
|
|
12356
|
-
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
if (Array.isArray(values)) {
|
|
12363
|
-
const index = values.indexOf(value);
|
|
12364
|
-
if (index === -1) return false;
|
|
12365
|
-
values.splice(index, 1);
|
|
12366
|
-
if (values.length === 0) this.delete(keyNodeOrEntry);
|
|
12272
|
+
* Append a single value.
|
|
12273
|
+
* @remarks Time O(log n), Space O(1)
|
|
12274
|
+
*/
|
|
12275
|
+
add(key, value) {
|
|
12276
|
+
this._validateKey(key);
|
|
12277
|
+
const bucket = __privateGet(this, _core2).get(key);
|
|
12278
|
+
if (bucket) {
|
|
12279
|
+
bucket.push(value);
|
|
12367
12280
|
return true;
|
|
12368
12281
|
}
|
|
12369
|
-
return
|
|
12282
|
+
return __privateGet(this, _core2).set(key, [value]);
|
|
12283
|
+
}
|
|
12284
|
+
set(entry, value) {
|
|
12285
|
+
if (entry === null || entry === void 0) return false;
|
|
12286
|
+
if (Array.isArray(entry)) {
|
|
12287
|
+
const [k, bucket] = entry;
|
|
12288
|
+
if (k === null || k === void 0) return false;
|
|
12289
|
+
if (value !== void 0) return this.add(k, value);
|
|
12290
|
+
if (bucket === void 0) {
|
|
12291
|
+
return __privateGet(this, _core2).set(k, []);
|
|
12292
|
+
}
|
|
12293
|
+
const existing = __privateGet(this, _core2).get(k);
|
|
12294
|
+
if (existing) {
|
|
12295
|
+
existing.push(...bucket);
|
|
12296
|
+
return true;
|
|
12297
|
+
}
|
|
12298
|
+
return __privateGet(this, _core2).set(k, [...bucket]);
|
|
12299
|
+
}
|
|
12300
|
+
if (value !== void 0) return this.add(entry, value);
|
|
12301
|
+
return __privateGet(this, _core2).set(entry, []);
|
|
12370
12302
|
}
|
|
12371
12303
|
/**
|
|
12372
|
-
*
|
|
12373
|
-
* @remarks Time O(
|
|
12374
|
-
* @template MK
|
|
12375
|
-
* @template MV
|
|
12376
|
-
* @template MR
|
|
12377
|
-
* @param callback - Function mapping (key, values, index, tree) → [newKey, newValue].
|
|
12378
|
-
* @param [options] - Options for the output tree.
|
|
12379
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
12380
|
-
* @returns A new RedBlackTree (or TreeMultiMap when mapping to array values; see overloads).
|
|
12304
|
+
* Deletes a key and its entire bucket.
|
|
12305
|
+
* @remarks Time O(log n), Space O(1)
|
|
12381
12306
|
*/
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
12386
|
-
return out;
|
|
12307
|
+
delete(key) {
|
|
12308
|
+
this._validateKey(key);
|
|
12309
|
+
return __privateGet(this, _core2).delete(key).length > 0;
|
|
12387
12310
|
}
|
|
12388
12311
|
/**
|
|
12389
|
-
*
|
|
12390
|
-
* @remarks Time O(
|
|
12391
|
-
* @template TK
|
|
12392
|
-
* @template TV
|
|
12393
|
-
* @template TR
|
|
12394
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
12395
|
-
* @returns An empty like-kind instance.
|
|
12312
|
+
* Check if a specific value exists in a key's bucket.
|
|
12313
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12396
12314
|
*/
|
|
12397
|
-
|
|
12398
|
-
|
|
12399
|
-
|
|
12400
|
-
return
|
|
12315
|
+
hasEntry(key, value, eq = Object.is) {
|
|
12316
|
+
const bucket = this.get(key);
|
|
12317
|
+
if (!Array.isArray(bucket)) return false;
|
|
12318
|
+
return bucket.some((v) => eq(v, value));
|
|
12401
12319
|
}
|
|
12402
12320
|
/**
|
|
12403
|
-
*
|
|
12404
|
-
* @remarks Time O(
|
|
12405
|
-
* @template TK
|
|
12406
|
-
* @template TV
|
|
12407
|
-
* @template TR
|
|
12408
|
-
* @param iter - Iterable used to seed the new tree.
|
|
12409
|
-
* @param [options] - Options merged with the current snapshot.
|
|
12410
|
-
* @returns A like-kind RedBlackTree built from the iterable.
|
|
12321
|
+
* Delete a single occurrence of a value from a key's bucket.
|
|
12322
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12411
12323
|
*/
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12324
|
+
deleteValue(key, value, eq = Object.is) {
|
|
12325
|
+
const bucket = this.get(key);
|
|
12326
|
+
if (!Array.isArray(bucket)) return false;
|
|
12327
|
+
const idx = bucket.findIndex((v) => eq(v, value));
|
|
12328
|
+
if (idx === -1) return false;
|
|
12329
|
+
bucket.splice(idx, 1);
|
|
12330
|
+
if (bucket.length === 0) this.delete(key);
|
|
12331
|
+
return true;
|
|
12416
12332
|
}
|
|
12417
|
-
};
|
|
12418
|
-
__name(_TreeMultiMap, "TreeMultiMap");
|
|
12419
|
-
var TreeMultiMap = _TreeMultiMap;
|
|
12420
|
-
|
|
12421
|
-
// src/data-structures/binary-tree/tree-counter.ts
|
|
12422
|
-
var _TreeCounterNode = class _TreeCounterNode {
|
|
12423
12333
|
/**
|
|
12424
|
-
*
|
|
12425
|
-
* @remarks Time O(
|
|
12426
|
-
* @param key - Key of the node.
|
|
12427
|
-
* @param [value] - Value associated with the key (ignored in map mode).
|
|
12428
|
-
* @param [count] - Initial count for this node (default 1).
|
|
12429
|
-
* @param color - Initial color ('RED' or 'BLACK').
|
|
12430
|
-
* @returns New TreeCounterNode instance.
|
|
12334
|
+
* Delete all occurrences of a value from a key's bucket.
|
|
12335
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12431
12336
|
*/
|
|
12432
|
-
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
this.count = count;
|
|
12337
|
+
deleteValues(key, value, eq = Object.is) {
|
|
12338
|
+
const bucket = this.get(key);
|
|
12339
|
+
if (!Array.isArray(bucket) || bucket.length === 0) return 0;
|
|
12340
|
+
let removed = 0;
|
|
12341
|
+
for (let i = bucket.length - 1; i >= 0; i--) {
|
|
12342
|
+
if (eq(bucket[i], value)) {
|
|
12343
|
+
bucket.splice(i, 1);
|
|
12344
|
+
removed++;
|
|
12345
|
+
}
|
|
12346
|
+
}
|
|
12347
|
+
if (bucket.length === 0 && removed > 0) this.delete(key);
|
|
12348
|
+
return removed;
|
|
12445
12349
|
}
|
|
12350
|
+
// ---- iteration (bucket view) ----
|
|
12446
12351
|
/**
|
|
12447
|
-
*
|
|
12448
|
-
* @remarks Time O(
|
|
12449
|
-
* @returns Left child node, or null/undefined.
|
|
12352
|
+
* Iterates over all entries as [key, bucket] pairs.
|
|
12353
|
+
* @remarks Time O(n), Space O(1)
|
|
12450
12354
|
*/
|
|
12451
|
-
|
|
12452
|
-
|
|
12355
|
+
*[Symbol.iterator]() {
|
|
12356
|
+
for (const [k, v] of __privateGet(this, _core2)) {
|
|
12357
|
+
yield [k, v != null ? v : []];
|
|
12358
|
+
}
|
|
12453
12359
|
}
|
|
12454
12360
|
/**
|
|
12455
|
-
*
|
|
12456
|
-
* @remarks Time O(
|
|
12457
|
-
* @param v - New left child node, or null/undefined.
|
|
12458
|
-
* @returns void
|
|
12361
|
+
* Iterates over all keys.
|
|
12362
|
+
* @remarks Time O(n), Space O(1)
|
|
12459
12363
|
*/
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
v.parent = this;
|
|
12463
|
-
}
|
|
12464
|
-
this._left = v;
|
|
12364
|
+
*keys() {
|
|
12365
|
+
yield* __privateGet(this, _core2).keys();
|
|
12465
12366
|
}
|
|
12466
12367
|
/**
|
|
12467
|
-
*
|
|
12468
|
-
* @remarks Time O(
|
|
12469
|
-
* @returns Right child node, or null/undefined.
|
|
12368
|
+
* Iterates over all buckets.
|
|
12369
|
+
* @remarks Time O(n), Space O(1)
|
|
12470
12370
|
*/
|
|
12471
|
-
|
|
12472
|
-
|
|
12371
|
+
*values() {
|
|
12372
|
+
for (const [, bucket] of this) yield bucket;
|
|
12473
12373
|
}
|
|
12374
|
+
// ---- entry-flat views ----
|
|
12474
12375
|
/**
|
|
12475
|
-
*
|
|
12476
|
-
* @remarks Time O(
|
|
12477
|
-
* @param v - New right child node, or null/undefined.
|
|
12478
|
-
* @returns void
|
|
12376
|
+
* Iterates over all entries for a specific key.
|
|
12377
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12479
12378
|
*/
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
this._right = v;
|
|
12379
|
+
*entriesOf(key) {
|
|
12380
|
+
const bucket = this.get(key);
|
|
12381
|
+
if (!Array.isArray(bucket)) return;
|
|
12382
|
+
for (const v of bucket) yield [key, v];
|
|
12485
12383
|
}
|
|
12486
12384
|
/**
|
|
12487
|
-
*
|
|
12488
|
-
* @remarks Time O(
|
|
12489
|
-
*
|
|
12490
|
-
* @returns The height.
|
|
12385
|
+
* Iterates over all values for a specific key.
|
|
12386
|
+
* @remarks Time O(log n + m), Space O(1) where m is bucket size
|
|
12491
12387
|
*/
|
|
12492
|
-
|
|
12493
|
-
|
|
12388
|
+
*valuesOf(key) {
|
|
12389
|
+
const bucket = this.get(key);
|
|
12390
|
+
if (!Array.isArray(bucket)) return;
|
|
12391
|
+
yield* bucket;
|
|
12494
12392
|
}
|
|
12495
12393
|
/**
|
|
12496
|
-
*
|
|
12497
|
-
* @remarks Time O(
|
|
12498
|
-
*
|
|
12499
|
-
* @param value - The new height.
|
|
12394
|
+
* Iterates over all [key, value] pairs (flattened from buckets).
|
|
12395
|
+
* @remarks Time O(T), Space O(1) where T is totalSize
|
|
12500
12396
|
*/
|
|
12501
|
-
|
|
12502
|
-
this
|
|
12397
|
+
*flatEntries() {
|
|
12398
|
+
for (const [k, bucket] of this) {
|
|
12399
|
+
for (const v of bucket) yield [k, v];
|
|
12400
|
+
}
|
|
12503
12401
|
}
|
|
12402
|
+
// ━━━ Navigable methods (return [K, V[]] | undefined) ━━━
|
|
12504
12403
|
/**
|
|
12505
|
-
*
|
|
12506
|
-
* @remarks Time O(
|
|
12507
|
-
*
|
|
12508
|
-
*
|
|
12404
|
+
* Returns the entry with the smallest key.
|
|
12405
|
+
* @remarks Time O(log n), Space O(1)
|
|
12406
|
+
* @example
|
|
12407
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12408
|
+
* map.first(); // [1, ['a']]
|
|
12509
12409
|
*/
|
|
12510
|
-
|
|
12511
|
-
|
|
12410
|
+
first() {
|
|
12411
|
+
const k = __privateGet(this, _core2).getLeftMost();
|
|
12412
|
+
if (k === void 0) return void 0;
|
|
12413
|
+
const b = this.get(k);
|
|
12414
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12512
12415
|
}
|
|
12513
12416
|
/**
|
|
12514
|
-
*
|
|
12515
|
-
* @remarks Time O(
|
|
12516
|
-
*
|
|
12517
|
-
*
|
|
12417
|
+
* Returns the entry with the largest key.
|
|
12418
|
+
* @remarks Time O(log n), Space O(1)
|
|
12419
|
+
* @example
|
|
12420
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12421
|
+
* map.last(); // [2, ['b']]
|
|
12518
12422
|
*/
|
|
12519
|
-
|
|
12520
|
-
|
|
12423
|
+
last() {
|
|
12424
|
+
const k = __privateGet(this, _core2).getRightMost();
|
|
12425
|
+
if (k === void 0) return void 0;
|
|
12426
|
+
const b = this.get(k);
|
|
12427
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12521
12428
|
}
|
|
12522
12429
|
/**
|
|
12523
|
-
*
|
|
12524
|
-
* @remarks Time O(
|
|
12525
|
-
*
|
|
12526
|
-
*
|
|
12430
|
+
* Removes and returns the entry with the smallest key.
|
|
12431
|
+
* @remarks Time O(log n), Space O(1)
|
|
12432
|
+
* @example
|
|
12433
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12434
|
+
* map.pollFirst(); // [1, ['a']]
|
|
12435
|
+
* map.has(1); // false
|
|
12527
12436
|
*/
|
|
12528
|
-
|
|
12529
|
-
|
|
12437
|
+
pollFirst() {
|
|
12438
|
+
const e = this.first();
|
|
12439
|
+
if (!e) return void 0;
|
|
12440
|
+
this.delete(e[0]);
|
|
12441
|
+
return e;
|
|
12530
12442
|
}
|
|
12531
12443
|
/**
|
|
12532
|
-
*
|
|
12533
|
-
* @remarks Time O(
|
|
12534
|
-
*
|
|
12535
|
-
*
|
|
12444
|
+
* Removes and returns the entry with the largest key.
|
|
12445
|
+
* @remarks Time O(log n), Space O(1)
|
|
12446
|
+
* @example
|
|
12447
|
+
* const map = new TreeMultiMap([[1, ['a']], [2, ['b']]]);
|
|
12448
|
+
* map.pollLast(); // [2, ['b']]
|
|
12449
|
+
* map.has(2); // false
|
|
12536
12450
|
*/
|
|
12537
|
-
|
|
12538
|
-
|
|
12451
|
+
pollLast() {
|
|
12452
|
+
const e = this.last();
|
|
12453
|
+
if (!e) return void 0;
|
|
12454
|
+
this.delete(e[0]);
|
|
12455
|
+
return e;
|
|
12539
12456
|
}
|
|
12540
12457
|
/**
|
|
12541
|
-
*
|
|
12542
|
-
* @remarks Time O(
|
|
12543
|
-
*
|
|
12544
|
-
*
|
|
12458
|
+
* Returns the entry with the smallest key >= given key.
|
|
12459
|
+
* @remarks Time O(log n), Space O(1)
|
|
12460
|
+
* @example
|
|
12461
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12462
|
+
* map.ceiling(15); // [20, ['b']]
|
|
12463
|
+
* map.ceiling(20); // [20, ['b']]
|
|
12545
12464
|
*/
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
} else if (this.parent.right === this) {
|
|
12553
|
-
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
12554
|
-
}
|
|
12555
|
-
return "MAL_NODE";
|
|
12465
|
+
ceiling(key) {
|
|
12466
|
+
this._validateKey(key);
|
|
12467
|
+
const k = __privateGet(this, _core2).ceiling(key);
|
|
12468
|
+
if (k === void 0) return void 0;
|
|
12469
|
+
const b = this.get(k);
|
|
12470
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12556
12471
|
}
|
|
12557
|
-
};
|
|
12558
|
-
__name(_TreeCounterNode, "TreeCounterNode");
|
|
12559
|
-
var TreeCounterNode = _TreeCounterNode;
|
|
12560
|
-
var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
12561
12472
|
/**
|
|
12562
|
-
*
|
|
12563
|
-
* @remarks Time O(
|
|
12564
|
-
* @
|
|
12565
|
-
*
|
|
12566
|
-
*
|
|
12473
|
+
* Returns the entry with the largest key <= given key.
|
|
12474
|
+
* @remarks Time O(log n), Space O(1)
|
|
12475
|
+
* @example
|
|
12476
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12477
|
+
* map.floor(25); // [20, ['b']]
|
|
12478
|
+
* map.floor(20); // [20, ['b']]
|
|
12479
|
+
*/
|
|
12480
|
+
floor(key) {
|
|
12481
|
+
this._validateKey(key);
|
|
12482
|
+
const k = __privateGet(this, _core2).floor(key);
|
|
12483
|
+
if (k === void 0) return void 0;
|
|
12484
|
+
const b = this.get(k);
|
|
12485
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12486
|
+
}
|
|
12487
|
+
/**
|
|
12488
|
+
* Returns the entry with the smallest key > given key.
|
|
12489
|
+
* @remarks Time O(log n), Space O(1)
|
|
12490
|
+
* @example
|
|
12491
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12492
|
+
* map.higher(10); // [20, ['b']]
|
|
12493
|
+
* map.higher(15); // [20, ['b']]
|
|
12567
12494
|
*/
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
if (
|
|
12495
|
+
higher(key) {
|
|
12496
|
+
this._validateKey(key);
|
|
12497
|
+
const k = __privateGet(this, _core2).higher(key);
|
|
12498
|
+
if (k === void 0) return void 0;
|
|
12499
|
+
const b = this.get(k);
|
|
12500
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12572
12501
|
}
|
|
12573
12502
|
/**
|
|
12574
|
-
*
|
|
12575
|
-
* @remarks Time O(
|
|
12576
|
-
* @
|
|
12503
|
+
* Returns the entry with the largest key < given key.
|
|
12504
|
+
* @remarks Time O(log n), Space O(1)
|
|
12505
|
+
* @example
|
|
12506
|
+
* const map = new TreeMultiMap([[10, ['a']], [20, ['b']], [30, ['c']]]);
|
|
12507
|
+
* map.lower(20); // [10, ['a']]
|
|
12508
|
+
* map.lower(15); // [10, ['a']]
|
|
12577
12509
|
*/
|
|
12578
|
-
|
|
12579
|
-
|
|
12510
|
+
lower(key) {
|
|
12511
|
+
this._validateKey(key);
|
|
12512
|
+
const k = __privateGet(this, _core2).lower(key);
|
|
12513
|
+
if (k === void 0) return void 0;
|
|
12514
|
+
const b = this.get(k);
|
|
12515
|
+
return b === void 0 ? void 0 : [k, b];
|
|
12580
12516
|
}
|
|
12517
|
+
// ━━━ Tree utilities ━━━
|
|
12581
12518
|
/**
|
|
12582
|
-
*
|
|
12583
|
-
* @remarks Time O(
|
|
12584
|
-
* @returns Total count recomputed from nodes.
|
|
12519
|
+
* Prints the internal tree structure (for debugging).
|
|
12520
|
+
* @remarks Time O(n), Space O(n)
|
|
12585
12521
|
*/
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
this.dfs((node) => sum += node ? node.count : 0);
|
|
12589
|
-
return sum;
|
|
12522
|
+
print(...args) {
|
|
12523
|
+
return __privateGet(this, _core2).print(...args);
|
|
12590
12524
|
}
|
|
12591
|
-
|
|
12592
|
-
|
|
12525
|
+
/**
|
|
12526
|
+
* Executes a callback for each entry.
|
|
12527
|
+
* @remarks Time O(n), Space O(1)
|
|
12528
|
+
*/
|
|
12529
|
+
forEach(callback) {
|
|
12530
|
+
for (const [k, v] of this) {
|
|
12531
|
+
callback(v, k, this);
|
|
12532
|
+
}
|
|
12593
12533
|
}
|
|
12594
12534
|
/**
|
|
12595
|
-
*
|
|
12596
|
-
* @remarks Time O(
|
|
12597
|
-
* @returns True if the value is a TreeCounterNode.
|
|
12535
|
+
* Creates a new map with entries that pass the predicate.
|
|
12536
|
+
* @remarks Time O(n), Space O(n)
|
|
12598
12537
|
*/
|
|
12599
|
-
|
|
12600
|
-
|
|
12538
|
+
filter(predicate) {
|
|
12539
|
+
const filtered = [];
|
|
12540
|
+
for (const [k, v] of this) {
|
|
12541
|
+
if (predicate(v, k, this)) filtered.push([k, v]);
|
|
12542
|
+
}
|
|
12543
|
+
return new _TreeMultiMap(filtered, { comparator: this.comparator });
|
|
12601
12544
|
}
|
|
12602
12545
|
/**
|
|
12603
|
-
*
|
|
12604
|
-
* @remarks Time O(log
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
set(keyNodeOrEntry, value, count = 1) {
|
|
12611
|
-
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12612
|
-
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12613
|
-
const isSuccessAdded = super.set(newNode, newValue);
|
|
12614
|
-
if (isSuccessAdded) {
|
|
12615
|
-
this._count += orgCount;
|
|
12616
|
-
return true;
|
|
12617
|
-
} else {
|
|
12618
|
-
return false;
|
|
12546
|
+
* Creates a new map by transforming each entry.
|
|
12547
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12548
|
+
*/
|
|
12549
|
+
map(mapper) {
|
|
12550
|
+
const mapped = [];
|
|
12551
|
+
for (const [k, v] of this) {
|
|
12552
|
+
mapped.push(mapper(v, k, this));
|
|
12619
12553
|
}
|
|
12554
|
+
return new _TreeMultiMap(mapped, { comparator: this.comparator });
|
|
12620
12555
|
}
|
|
12621
12556
|
/**
|
|
12622
|
-
*
|
|
12623
|
-
* @remarks Time O(
|
|
12624
|
-
* @param keyNodeEntryRawOrPredicate - Key, node, or [key, value] entry identifying the node.
|
|
12625
|
-
* @param [ignoreCount] - If true, remove the node regardless of its count.
|
|
12626
|
-
* @returns Array of deletion results including deleted node and a rebalance hint when present.
|
|
12557
|
+
* Reduces all entries to a single value.
|
|
12558
|
+
* @remarks Time O(n), Space O(1)
|
|
12627
12559
|
*/
|
|
12628
|
-
|
|
12629
|
-
|
|
12560
|
+
reduce(callback, initialValue) {
|
|
12561
|
+
let acc = initialValue;
|
|
12562
|
+
for (const [k, v] of this) {
|
|
12563
|
+
acc = callback(acc, v, k, this);
|
|
12564
|
+
}
|
|
12565
|
+
return acc;
|
|
12566
|
+
}
|
|
12567
|
+
/**
|
|
12568
|
+
* Sets multiple entries at once.
|
|
12569
|
+
* @remarks Time O(m log n), Space O(m) where m is input size
|
|
12570
|
+
*/
|
|
12571
|
+
setMany(keysNodesEntriesOrRaws) {
|
|
12630
12572
|
const results = [];
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
else nodeToDelete = this.isRealNode(keyNodeEntryRawOrPredicate) ? keyNodeEntryRawOrPredicate : this.getNode(keyNodeEntryRawOrPredicate);
|
|
12634
|
-
if (!nodeToDelete) {
|
|
12635
|
-
return results;
|
|
12573
|
+
for (const x of keysNodesEntriesOrRaws) {
|
|
12574
|
+
results.push(this.set(x, void 0));
|
|
12636
12575
|
}
|
|
12637
|
-
|
|
12638
|
-
|
|
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
|
-
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
12689
|
-
this._transplant(nodeToDelete, successor);
|
|
12690
|
-
this._count -= nodeToDelete.count;
|
|
12691
|
-
} else {
|
|
12692
|
-
nodeToDelete.count--;
|
|
12693
|
-
this._count--;
|
|
12694
|
-
results.push({ deleted: nodeToDelete, needBalanced: void 0 });
|
|
12695
|
-
return results;
|
|
12696
|
-
}
|
|
12697
|
-
successor.left = nodeToDelete.left;
|
|
12698
|
-
if (this.isRealNode(successor.left)) {
|
|
12699
|
-
successor.left.parent = successor;
|
|
12700
|
-
}
|
|
12701
|
-
successor.color = nodeToDelete.color;
|
|
12576
|
+
return results;
|
|
12577
|
+
}
|
|
12578
|
+
/**
|
|
12579
|
+
* Searches for entries within a key range.
|
|
12580
|
+
* @remarks Time O(log n + k), Space O(k) where k is result size
|
|
12581
|
+
*/
|
|
12582
|
+
rangeSearch(range, callback, isBalanced) {
|
|
12583
|
+
return __privateGet(this, _core2).rangeSearch(range, callback, isBalanced);
|
|
12584
|
+
}
|
|
12585
|
+
/**
|
|
12586
|
+
* Creates a shallow clone of this map.
|
|
12587
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12588
|
+
*/
|
|
12589
|
+
clone() {
|
|
12590
|
+
return new _TreeMultiMap(this, { comparator: this.comparator, isMapMode: __privateGet(this, _core2)._isMapMode });
|
|
12591
|
+
}
|
|
12592
|
+
/**
|
|
12593
|
+
* Expose comparator for advanced usage/testing (read-only).
|
|
12594
|
+
* @remarks Time O(1), Space O(1)
|
|
12595
|
+
*/
|
|
12596
|
+
get comparator() {
|
|
12597
|
+
return __privateGet(this, _core2)._comparator;
|
|
12598
|
+
}
|
|
12599
|
+
};
|
|
12600
|
+
_core2 = new WeakMap();
|
|
12601
|
+
_isDefaultComparator2 = new WeakMap();
|
|
12602
|
+
__name(_TreeMultiMap, "TreeMultiMap");
|
|
12603
|
+
var TreeMultiMap = _TreeMultiMap;
|
|
12604
|
+
|
|
12605
|
+
// src/data-structures/binary-tree/tree-map.ts
|
|
12606
|
+
var _core3, _isDefaultComparator3, _userComparator2;
|
|
12607
|
+
var _TreeMap = class _TreeMap {
|
|
12608
|
+
/**
|
|
12609
|
+
* Create a TreeMap from an iterable of `[key, value]` entries.
|
|
12610
|
+
*
|
|
12611
|
+
* @throws {TypeError} If any entry is not a 2-tuple-like value, or when using the default comparator
|
|
12612
|
+
* and encountering unsupported/invalid keys (e.g. `NaN`, invalid `Date`).
|
|
12613
|
+
*/
|
|
12614
|
+
constructor(entries = [], options = {}) {
|
|
12615
|
+
__privateAdd(this, _core3);
|
|
12616
|
+
__privateAdd(this, _isDefaultComparator3);
|
|
12617
|
+
__privateAdd(this, _userComparator2);
|
|
12618
|
+
var _a;
|
|
12619
|
+
__privateSet(this, _userComparator2, options.comparator);
|
|
12620
|
+
const comparator = (_a = options.comparator) != null ? _a : _TreeMap.createDefaultComparator();
|
|
12621
|
+
__privateSet(this, _isDefaultComparator3, options.comparator === void 0);
|
|
12622
|
+
__privateSet(this, _core3, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
12623
|
+
for (const item of entries) {
|
|
12624
|
+
if (!Array.isArray(item) || item.length < 2) {
|
|
12625
|
+
throw new TypeError("TreeMap: each entry must be a [key, value] tuple");
|
|
12702
12626
|
}
|
|
12627
|
+
const k = item[0];
|
|
12628
|
+
const v = item[1];
|
|
12629
|
+
this.set(k, v);
|
|
12703
12630
|
}
|
|
12704
|
-
|
|
12705
|
-
|
|
12706
|
-
|
|
12631
|
+
}
|
|
12632
|
+
/**
|
|
12633
|
+
* Create the strict default comparator.
|
|
12634
|
+
*
|
|
12635
|
+
* Supports:
|
|
12636
|
+
* - `number` (rejects `NaN`; treats `-0` and `0` as equal)
|
|
12637
|
+
* - `string`
|
|
12638
|
+
* - `Date` (orders by `getTime()`, rejects invalid dates)
|
|
12639
|
+
*
|
|
12640
|
+
* For other key types, a custom comparator must be provided.
|
|
12641
|
+
*/
|
|
12642
|
+
static createDefaultComparator() {
|
|
12643
|
+
return (a, b) => {
|
|
12644
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
12645
|
+
if (Number.isNaN(a) || Number.isNaN(b)) throw new TypeError("TreeMap: NaN is not a valid key");
|
|
12646
|
+
const aa = Object.is(a, -0) ? 0 : a;
|
|
12647
|
+
const bb = Object.is(b, -0) ? 0 : b;
|
|
12648
|
+
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
12649
|
+
}
|
|
12650
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
12651
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
12652
|
+
}
|
|
12653
|
+
if (a instanceof Date && b instanceof Date) {
|
|
12654
|
+
const ta = a.getTime();
|
|
12655
|
+
const tb = b.getTime();
|
|
12656
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) throw new TypeError("TreeMap: invalid Date key");
|
|
12657
|
+
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
12658
|
+
}
|
|
12659
|
+
throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys");
|
|
12660
|
+
};
|
|
12661
|
+
}
|
|
12662
|
+
_validateKey(key) {
|
|
12663
|
+
if (!__privateGet(this, _isDefaultComparator3)) return;
|
|
12664
|
+
if (typeof key === "number") {
|
|
12665
|
+
if (Number.isNaN(key)) throw new TypeError("TreeMap: NaN is not a valid key");
|
|
12666
|
+
return;
|
|
12707
12667
|
}
|
|
12708
|
-
|
|
12709
|
-
|
|
12668
|
+
if (typeof key === "string") return;
|
|
12669
|
+
if (key instanceof Date) {
|
|
12670
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeMap: invalid Date key");
|
|
12671
|
+
return;
|
|
12672
|
+
}
|
|
12673
|
+
throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys");
|
|
12710
12674
|
}
|
|
12711
12675
|
/**
|
|
12712
|
-
*
|
|
12713
|
-
|
|
12714
|
-
|
|
12676
|
+
* Number of entries in the map.
|
|
12677
|
+
*/
|
|
12678
|
+
get size() {
|
|
12679
|
+
return __privateGet(this, _core3).size;
|
|
12680
|
+
}
|
|
12681
|
+
/**
|
|
12682
|
+
* Whether the map is empty.
|
|
12683
|
+
*/
|
|
12684
|
+
isEmpty() {
|
|
12685
|
+
return this.size === 0;
|
|
12686
|
+
}
|
|
12687
|
+
/**
|
|
12688
|
+
* Set or overwrite a value for a key.
|
|
12689
|
+
* @remarks Expected time O(log n)
|
|
12690
|
+
*/
|
|
12691
|
+
set(key, value) {
|
|
12692
|
+
this._validateKey(key);
|
|
12693
|
+
__privateGet(this, _core3).set(key, value);
|
|
12694
|
+
return this;
|
|
12695
|
+
}
|
|
12696
|
+
/**
|
|
12697
|
+
* Get the value under a key.
|
|
12698
|
+
* @remarks Expected time O(log n)
|
|
12699
|
+
*/
|
|
12700
|
+
get(key) {
|
|
12701
|
+
this._validateKey(key);
|
|
12702
|
+
return __privateGet(this, _core3).get(key);
|
|
12703
|
+
}
|
|
12704
|
+
/**
|
|
12705
|
+
* Test whether a key exists.
|
|
12706
|
+
* @remarks Expected time O(log n)
|
|
12707
|
+
*/
|
|
12708
|
+
has(key) {
|
|
12709
|
+
this._validateKey(key);
|
|
12710
|
+
return __privateGet(this, _core3).has(key);
|
|
12711
|
+
}
|
|
12712
|
+
/**
|
|
12713
|
+
* Delete a key.
|
|
12714
|
+
* @returns `true` if the key existed; otherwise `false`.
|
|
12715
|
+
* @remarks Expected time O(log n)
|
|
12716
|
+
*/
|
|
12717
|
+
delete(key) {
|
|
12718
|
+
var _a;
|
|
12719
|
+
this._validateKey(key);
|
|
12720
|
+
const res = __privateGet(this, _core3).delete(key);
|
|
12721
|
+
return Array.isArray(res) && res.length > 0 && !!((_a = res[0]) == null ? void 0 : _a.deleted);
|
|
12722
|
+
}
|
|
12723
|
+
/**
|
|
12724
|
+
* Remove all entries.
|
|
12715
12725
|
*/
|
|
12716
12726
|
clear() {
|
|
12717
|
-
|
|
12718
|
-
this._count = 0;
|
|
12727
|
+
__privateGet(this, _core3).clear();
|
|
12719
12728
|
}
|
|
12720
12729
|
/**
|
|
12721
|
-
*
|
|
12722
|
-
* @remarks Time O(N), Space O(N)
|
|
12723
|
-
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
12724
|
-
* @returns True if rebalancing succeeded (tree not empty).
|
|
12730
|
+
* Iterate over keys in ascending order.
|
|
12725
12731
|
*/
|
|
12726
|
-
|
|
12727
|
-
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
for (const nd of nodes) total += nd ? nd.count : 0;
|
|
12732
|
-
this._clearNodes();
|
|
12733
|
-
const build = /* @__PURE__ */ __name((l, r, parent) => {
|
|
12734
|
-
if (l > r) return void 0;
|
|
12735
|
-
const m = l + (r - l >> 1);
|
|
12736
|
-
const root = nodes[m];
|
|
12737
|
-
const leftChild = build(l, m - 1, root);
|
|
12738
|
-
const rightChild = build(m + 1, r, root);
|
|
12739
|
-
root.left = leftChild;
|
|
12740
|
-
root.right = rightChild;
|
|
12741
|
-
root.parent = parent;
|
|
12742
|
-
return root;
|
|
12743
|
-
}, "build");
|
|
12744
|
-
const newRoot = build(0, n - 1, void 0);
|
|
12745
|
-
this._setRoot(newRoot);
|
|
12746
|
-
this._size = n;
|
|
12747
|
-
this._count = total;
|
|
12748
|
-
return true;
|
|
12732
|
+
keys() {
|
|
12733
|
+
return __privateGet(this, _core3).keys();
|
|
12734
|
+
}
|
|
12735
|
+
_entryFromKey(k) {
|
|
12736
|
+
return [k, __privateGet(this, _core3).get(k)];
|
|
12749
12737
|
}
|
|
12750
12738
|
/**
|
|
12751
|
-
*
|
|
12752
|
-
*
|
|
12753
|
-
*
|
|
12754
|
-
* @template MV
|
|
12755
|
-
* @template MR
|
|
12756
|
-
* @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
|
|
12757
|
-
* @param [options] - Options for the output tree.
|
|
12758
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
12759
|
-
* @returns A new TreeCounter with mapped entries.
|
|
12739
|
+
* Iterate over values in ascending key order.
|
|
12740
|
+
*
|
|
12741
|
+
* Note: values may be `undefined` (TreeMap allows storing `undefined`, like native `Map`).
|
|
12760
12742
|
*/
|
|
12761
|
-
|
|
12762
|
-
const
|
|
12743
|
+
*values() {
|
|
12744
|
+
for (const k of this.keys()) yield this._entryFromKey(k)[1];
|
|
12745
|
+
}
|
|
12746
|
+
/**
|
|
12747
|
+
* Iterate over `[key, value]` entries in ascending key order.
|
|
12748
|
+
*
|
|
12749
|
+
* Note: values may be `undefined`.
|
|
12750
|
+
*/
|
|
12751
|
+
*entries() {
|
|
12752
|
+
for (const k of this.keys()) yield this._entryFromKey(k);
|
|
12753
|
+
}
|
|
12754
|
+
[Symbol.iterator]() {
|
|
12755
|
+
return this.entries();
|
|
12756
|
+
}
|
|
12757
|
+
/**
|
|
12758
|
+
* Visit each entry in ascending key order.
|
|
12759
|
+
*
|
|
12760
|
+
* Note: callback value may be `undefined`.
|
|
12761
|
+
*/
|
|
12762
|
+
forEach(cb, thisArg) {
|
|
12763
|
+
for (const [k, v] of this) cb.call(thisArg, v, k, this);
|
|
12764
|
+
}
|
|
12765
|
+
/**
|
|
12766
|
+
* Create a new TreeMap by mapping each entry to a new `[key, value]` entry.
|
|
12767
|
+
*
|
|
12768
|
+
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
12769
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
12770
|
+
*/
|
|
12771
|
+
map(callbackfn, options = {}, thisArg) {
|
|
12772
|
+
const out = new _TreeMap([], options);
|
|
12763
12773
|
let index = 0;
|
|
12764
|
-
for (const [
|
|
12765
|
-
|
|
12774
|
+
for (const [k, v] of this) {
|
|
12775
|
+
const [mk, mv] = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12776
|
+
out.set(mk, mv);
|
|
12766
12777
|
}
|
|
12767
12778
|
return out;
|
|
12768
12779
|
}
|
|
12769
12780
|
/**
|
|
12770
|
-
*
|
|
12771
|
-
* @remarks Time O(
|
|
12772
|
-
* @returns A deep copy of this tree.
|
|
12781
|
+
* Create a new TreeMap containing only entries that satisfy the predicate.
|
|
12782
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
12773
12783
|
*/
|
|
12774
|
-
|
|
12775
|
-
const out = this
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
if (
|
|
12780
|
-
const outNode = out.getNode(node.key);
|
|
12781
|
-
if (outNode) outNode.count = node.count;
|
|
12784
|
+
filter(callbackfn, thisArg) {
|
|
12785
|
+
const out = new _TreeMap([], { comparator: __privateGet(this, _userComparator2) });
|
|
12786
|
+
let index = 0;
|
|
12787
|
+
for (const [k, v] of this) {
|
|
12788
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12789
|
+
if (ok) out.set(k, v);
|
|
12782
12790
|
}
|
|
12783
12791
|
return out;
|
|
12784
12792
|
}
|
|
12785
12793
|
/**
|
|
12786
|
-
*
|
|
12787
|
-
* @remarks Time O(
|
|
12788
|
-
* @template TK
|
|
12789
|
-
* @template TV
|
|
12790
|
-
* @template TR
|
|
12791
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
12792
|
-
* @returns An empty like-kind instance.
|
|
12794
|
+
* Reduce entries into a single accumulator.
|
|
12795
|
+
* @remarks Time O(n), Space O(1)
|
|
12793
12796
|
*/
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
+
reduce(callbackfn, initialValue) {
|
|
12798
|
+
let acc = initialValue;
|
|
12799
|
+
let index = 0;
|
|
12800
|
+
for (const [k, v] of this) acc = callbackfn(acc, v, k, index++, this);
|
|
12801
|
+
return acc;
|
|
12797
12802
|
}
|
|
12798
12803
|
/**
|
|
12799
|
-
*
|
|
12800
|
-
* @remarks Time O(
|
|
12801
|
-
* @template TK
|
|
12802
|
-
* @template TV
|
|
12803
|
-
* @template TR
|
|
12804
|
-
* @param iter - Iterable used to seed the new tree.
|
|
12805
|
-
* @param [options] - Options merged with the current snapshot.
|
|
12806
|
-
* @returns A like-kind TreeCounter built from the iterable.
|
|
12804
|
+
* Test whether all entries satisfy a predicate.
|
|
12805
|
+
* @remarks Time O(n), Space O(1)
|
|
12807
12806
|
*/
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
}
|
|
12807
|
+
every(callbackfn, thisArg) {
|
|
12808
|
+
let index = 0;
|
|
12809
|
+
for (const [k, v] of this) {
|
|
12810
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12811
|
+
if (!ok) return false;
|
|
12812
|
+
}
|
|
12813
|
+
return true;
|
|
12814
12814
|
}
|
|
12815
12815
|
/**
|
|
12816
|
-
*
|
|
12817
|
-
* @remarks Time O(
|
|
12818
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry.
|
|
12819
|
-
* @param [value] - Value used when a bare key is provided.
|
|
12820
|
-
* @param [count] - Count increment to apply (default 1).
|
|
12821
|
-
* @returns Tuple [node, value] where node may be undefined.
|
|
12816
|
+
* Test whether any entry satisfies a predicate.
|
|
12817
|
+
* @remarks Time O(n), Space O(1)
|
|
12822
12818
|
*/
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
if (key === void 0 || key === null) return [void 0, void 0];
|
|
12829
|
-
const finalValue = value != null ? value : entryValue;
|
|
12830
|
-
return [this.createNode(key, finalValue, "BLACK", count), finalValue];
|
|
12819
|
+
some(callbackfn, thisArg) {
|
|
12820
|
+
let index = 0;
|
|
12821
|
+
for (const [k, v] of this) {
|
|
12822
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12823
|
+
if (ok) return true;
|
|
12831
12824
|
}
|
|
12832
|
-
return
|
|
12825
|
+
return false;
|
|
12833
12826
|
}
|
|
12834
12827
|
/**
|
|
12835
|
-
*
|
|
12836
|
-
* @
|
|
12837
|
-
* @
|
|
12838
|
-
* @param destNode - Destination node (or key) to receive properties.
|
|
12839
|
-
* @returns Destination node after swap, or undefined.
|
|
12828
|
+
* Find the first entry that satisfies a predicate.
|
|
12829
|
+
* @returns The first matching `[key, value]` tuple, or `undefined`.
|
|
12830
|
+
* @remarks Time O(n), Space O(1)
|
|
12840
12831
|
*/
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
const tempNode = this.createNode(key, value, color, count);
|
|
12847
|
-
if (tempNode) {
|
|
12848
|
-
tempNode.color = color;
|
|
12849
|
-
destNode.key = srcNode.key;
|
|
12850
|
-
if (!this._isMapMode) destNode.value = srcNode.value;
|
|
12851
|
-
destNode.count = srcNode.count;
|
|
12852
|
-
destNode.color = srcNode.color;
|
|
12853
|
-
srcNode.key = tempNode.key;
|
|
12854
|
-
if (!this._isMapMode) srcNode.value = tempNode.value;
|
|
12855
|
-
srcNode.count = tempNode.count;
|
|
12856
|
-
srcNode.color = tempNode.color;
|
|
12857
|
-
}
|
|
12858
|
-
return destNode;
|
|
12832
|
+
find(callbackfn, thisArg) {
|
|
12833
|
+
let index = 0;
|
|
12834
|
+
for (const [k, v] of this) {
|
|
12835
|
+
const ok = thisArg === void 0 ? callbackfn(v, k, index++, this) : callbackfn.call(thisArg, v, k, index++, this);
|
|
12836
|
+
if (ok) return [k, v];
|
|
12859
12837
|
}
|
|
12860
12838
|
return void 0;
|
|
12861
12839
|
}
|
|
12862
12840
|
/**
|
|
12863
|
-
*
|
|
12864
|
-
* @remarks Time O(
|
|
12865
|
-
* @param oldNode - Node being replaced.
|
|
12866
|
-
* @param newNode - Replacement node.
|
|
12867
|
-
* @returns The new node after replacement.
|
|
12841
|
+
* Materialize the map into an array of `[key, value]` tuples.
|
|
12842
|
+
* @remarks Time O(n), Space O(n)
|
|
12868
12843
|
*/
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12844
|
+
toArray() {
|
|
12845
|
+
return [...this];
|
|
12846
|
+
}
|
|
12847
|
+
/**
|
|
12848
|
+
* Print a human-friendly representation.
|
|
12849
|
+
* @remarks Time O(n), Space O(n)
|
|
12850
|
+
*/
|
|
12851
|
+
print() {
|
|
12852
|
+
__privateGet(this, _core3).print();
|
|
12853
|
+
}
|
|
12854
|
+
// Navigable operations (return entry tuples)
|
|
12855
|
+
// Note: returned tuple values may be `undefined`.
|
|
12856
|
+
/**
|
|
12857
|
+
* Smallest entry by key.
|
|
12858
|
+
*/
|
|
12859
|
+
first() {
|
|
12860
|
+
const k = __privateGet(this, _core3).getLeftMost();
|
|
12861
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12862
|
+
}
|
|
12863
|
+
/**
|
|
12864
|
+
* Largest entry by key.
|
|
12865
|
+
*/
|
|
12866
|
+
last() {
|
|
12867
|
+
const k = __privateGet(this, _core3).getRightMost();
|
|
12868
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12869
|
+
}
|
|
12870
|
+
/**
|
|
12871
|
+
* Remove and return the smallest entry.
|
|
12872
|
+
*/
|
|
12873
|
+
pollFirst() {
|
|
12874
|
+
const entry = this.first();
|
|
12875
|
+
if (!entry) return void 0;
|
|
12876
|
+
this.delete(entry[0]);
|
|
12877
|
+
return entry;
|
|
12878
|
+
}
|
|
12879
|
+
/**
|
|
12880
|
+
* Remove and return the largest entry.
|
|
12881
|
+
*/
|
|
12882
|
+
pollLast() {
|
|
12883
|
+
const entry = this.last();
|
|
12884
|
+
if (!entry) return void 0;
|
|
12885
|
+
this.delete(entry[0]);
|
|
12886
|
+
return entry;
|
|
12887
|
+
}
|
|
12888
|
+
/**
|
|
12889
|
+
* Smallest entry whose key is >= the given key.
|
|
12890
|
+
*/
|
|
12891
|
+
ceiling(key) {
|
|
12892
|
+
this._validateKey(key);
|
|
12893
|
+
const k = __privateGet(this, _core3).ceiling(key);
|
|
12894
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12895
|
+
}
|
|
12896
|
+
/**
|
|
12897
|
+
* Largest entry whose key is <= the given key.
|
|
12898
|
+
*/
|
|
12899
|
+
floor(key) {
|
|
12900
|
+
this._validateKey(key);
|
|
12901
|
+
const k = __privateGet(this, _core3).floor(key);
|
|
12902
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12903
|
+
}
|
|
12904
|
+
/**
|
|
12905
|
+
* Smallest entry whose key is > the given key.
|
|
12906
|
+
*/
|
|
12907
|
+
higher(key) {
|
|
12908
|
+
this._validateKey(key);
|
|
12909
|
+
const k = __privateGet(this, _core3).higher(key);
|
|
12910
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12911
|
+
}
|
|
12912
|
+
/**
|
|
12913
|
+
* Largest entry whose key is < the given key.
|
|
12914
|
+
*/
|
|
12915
|
+
lower(key) {
|
|
12916
|
+
this._validateKey(key);
|
|
12917
|
+
const k = __privateGet(this, _core3).lower(key);
|
|
12918
|
+
return k === void 0 ? void 0 : this._entryFromKey(k);
|
|
12919
|
+
}
|
|
12920
|
+
/**
|
|
12921
|
+
* Return all entries in a given key range.
|
|
12922
|
+
*
|
|
12923
|
+
* @param range `[low, high]`
|
|
12924
|
+
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
12925
|
+
*/
|
|
12926
|
+
rangeSearch(range, options = {}) {
|
|
12927
|
+
const { lowInclusive = true, highInclusive = true } = options;
|
|
12928
|
+
const [low, high] = range;
|
|
12929
|
+
this._validateKey(low);
|
|
12930
|
+
this._validateKey(high);
|
|
12931
|
+
const keys = __privateGet(this, _core3).rangeSearch([low, high]);
|
|
12932
|
+
const out = [];
|
|
12933
|
+
const cmp = __privateGet(this, _core3).comparator;
|
|
12934
|
+
for (const k of keys) {
|
|
12935
|
+
if (k === void 0) continue;
|
|
12936
|
+
if (!lowInclusive && cmp(k, low) === 0) continue;
|
|
12937
|
+
if (!highInclusive && cmp(k, high) === 0) continue;
|
|
12938
|
+
out.push(this._entryFromKey(k));
|
|
12939
|
+
}
|
|
12940
|
+
return out;
|
|
12872
12941
|
}
|
|
12873
12942
|
};
|
|
12874
|
-
|
|
12875
|
-
|
|
12943
|
+
_core3 = new WeakMap();
|
|
12944
|
+
_isDefaultComparator3 = new WeakMap();
|
|
12945
|
+
_userComparator2 = new WeakMap();
|
|
12946
|
+
__name(_TreeMap, "TreeMap");
|
|
12947
|
+
var TreeMap = _TreeMap;
|
|
12876
12948
|
|
|
12877
|
-
// src/data-structures/binary-tree/
|
|
12878
|
-
var
|
|
12949
|
+
// src/data-structures/binary-tree/tree-multi-set.ts
|
|
12950
|
+
var _core4, _isDefaultComparator4;
|
|
12951
|
+
var _TreeMultiSet = class _TreeMultiSet {
|
|
12952
|
+
// total occurrences (sumCounts)
|
|
12953
|
+
/**
|
|
12954
|
+
* Creates a new TreeMultiSet.
|
|
12955
|
+
* @param elements - Initial elements to add
|
|
12956
|
+
* @param options - Configuration options
|
|
12957
|
+
* @remarks Time O(m log m), Space O(m) where m is the number of initial elements
|
|
12958
|
+
*/
|
|
12959
|
+
constructor(elements = [], options = {}) {
|
|
12960
|
+
__privateAdd(this, _core4);
|
|
12961
|
+
__privateAdd(this, _isDefaultComparator4);
|
|
12962
|
+
__publicField(this, "_size", 0);
|
|
12963
|
+
var _a;
|
|
12964
|
+
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
12965
|
+
__privateSet(this, _isDefaultComparator4, options.comparator === void 0);
|
|
12966
|
+
__privateSet(this, _core4, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
12967
|
+
for (const k of elements) this.add(k);
|
|
12968
|
+
}
|
|
12879
12969
|
/**
|
|
12880
|
-
*
|
|
12970
|
+
* Validates the key against the default comparator rules.
|
|
12881
12971
|
* @remarks Time O(1), Space O(1)
|
|
12882
|
-
* @param key - Key of the node.
|
|
12883
|
-
* @param [value] - Associated value (ignored in map mode).
|
|
12884
|
-
* @param [count] - Initial count for this node (default 1).
|
|
12885
|
-
* @returns New AVLTreeCounterNode instance.
|
|
12886
12972
|
*/
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12973
|
+
_validateKey(key) {
|
|
12974
|
+
if (!__privateGet(this, _isDefaultComparator4)) return;
|
|
12975
|
+
if (typeof key === "number") {
|
|
12976
|
+
if (Number.isNaN(key)) throw new TypeError("TreeMultiSet: NaN is not a valid key");
|
|
12977
|
+
return;
|
|
12978
|
+
}
|
|
12979
|
+
if (typeof key === "string") return;
|
|
12980
|
+
if (key instanceof Date) {
|
|
12981
|
+
if (Number.isNaN(key.getTime())) throw new TypeError("TreeMultiSet: invalid Date key");
|
|
12982
|
+
return;
|
|
12983
|
+
}
|
|
12984
|
+
throw new TypeError("TreeMultiSet: comparator is required for non-number/non-string/non-Date keys");
|
|
12985
|
+
}
|
|
12986
|
+
/**
|
|
12987
|
+
* Validates that count is a non-negative safe integer.
|
|
12988
|
+
* @remarks Time O(1), Space O(1)
|
|
12989
|
+
*/
|
|
12990
|
+
_validateCount(n) {
|
|
12991
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new RangeError("TreeMultiSet: count must be a safe integer >= 0");
|
|
12899
12992
|
}
|
|
12900
12993
|
/**
|
|
12901
|
-
*
|
|
12994
|
+
* Total occurrences (sumCounts).
|
|
12902
12995
|
* @remarks Time O(1), Space O(1)
|
|
12903
|
-
* @returns Left child node, or null/undefined.
|
|
12904
12996
|
*/
|
|
12905
|
-
get
|
|
12906
|
-
return this.
|
|
12997
|
+
get size() {
|
|
12998
|
+
return this._size;
|
|
12907
12999
|
}
|
|
12908
13000
|
/**
|
|
12909
|
-
*
|
|
13001
|
+
* Number of distinct keys.
|
|
12910
13002
|
* @remarks Time O(1), Space O(1)
|
|
12911
|
-
* @param v - New left child node, or null/undefined.
|
|
12912
|
-
* @returns void
|
|
12913
13003
|
*/
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
v.parent = this;
|
|
12917
|
-
}
|
|
12918
|
-
this._left = v;
|
|
13004
|
+
get distinctSize() {
|
|
13005
|
+
return __privateGet(this, _core4).size;
|
|
12919
13006
|
}
|
|
12920
13007
|
/**
|
|
12921
|
-
*
|
|
13008
|
+
* Whether the multiset is empty.
|
|
12922
13009
|
* @remarks Time O(1), Space O(1)
|
|
12923
|
-
* @returns Right child node, or null/undefined.
|
|
12924
13010
|
*/
|
|
12925
|
-
|
|
12926
|
-
return this.
|
|
13011
|
+
isEmpty() {
|
|
13012
|
+
return this.size === 0;
|
|
12927
13013
|
}
|
|
12928
13014
|
/**
|
|
12929
|
-
*
|
|
12930
|
-
* @remarks Time O(
|
|
12931
|
-
* @param v - New right child node, or null/undefined.
|
|
12932
|
-
* @returns void
|
|
13015
|
+
* Whether the multiset contains the given key.
|
|
13016
|
+
* @remarks Time O(log n), Space O(1)
|
|
12933
13017
|
*/
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
|
|
12937
|
-
}
|
|
12938
|
-
this._right = v;
|
|
13018
|
+
has(key) {
|
|
13019
|
+
this._validateKey(key);
|
|
13020
|
+
return this.count(key) > 0;
|
|
12939
13021
|
}
|
|
12940
13022
|
/**
|
|
12941
|
-
*
|
|
12942
|
-
* @remarks Time O(
|
|
12943
|
-
*
|
|
12944
|
-
* @returns The height.
|
|
13023
|
+
* Returns the count of occurrences for the given key.
|
|
13024
|
+
* @remarks Time O(log n), Space O(1)
|
|
12945
13025
|
*/
|
|
12946
|
-
|
|
12947
|
-
|
|
13026
|
+
count(key) {
|
|
13027
|
+
var _a;
|
|
13028
|
+
this._validateKey(key);
|
|
13029
|
+
return (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
12948
13030
|
}
|
|
12949
13031
|
/**
|
|
12950
|
-
*
|
|
12951
|
-
* @
|
|
12952
|
-
*
|
|
12953
|
-
* @param value - The new height.
|
|
13032
|
+
* Add `n` occurrences of `key`.
|
|
13033
|
+
* @returns True if the multiset changed.
|
|
13034
|
+
* @remarks Time O(log n), Space O(1)
|
|
12954
13035
|
*/
|
|
12955
|
-
|
|
12956
|
-
|
|
13036
|
+
add(key, n = 1) {
|
|
13037
|
+
var _a;
|
|
13038
|
+
this._validateKey(key);
|
|
13039
|
+
this._validateCount(n);
|
|
13040
|
+
if (n === 0) return false;
|
|
13041
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13042
|
+
const next = old + n;
|
|
13043
|
+
__privateGet(this, _core4).set(key, next);
|
|
13044
|
+
this._size += n;
|
|
13045
|
+
return true;
|
|
12957
13046
|
}
|
|
12958
13047
|
/**
|
|
12959
|
-
*
|
|
12960
|
-
* @
|
|
12961
|
-
*
|
|
12962
|
-
* @returns The node's color.
|
|
13048
|
+
* Set count for `key` to exactly `n`.
|
|
13049
|
+
* @returns True if changed.
|
|
13050
|
+
* @remarks Time O(log n), Space O(1)
|
|
12963
13051
|
*/
|
|
12964
|
-
|
|
12965
|
-
|
|
13052
|
+
setCount(key, n) {
|
|
13053
|
+
var _a;
|
|
13054
|
+
this._validateKey(key);
|
|
13055
|
+
this._validateCount(n);
|
|
13056
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13057
|
+
if (old === n) return false;
|
|
13058
|
+
if (n === 0) {
|
|
13059
|
+
if (old !== 0) __privateGet(this, _core4).delete(key);
|
|
13060
|
+
} else {
|
|
13061
|
+
__privateGet(this, _core4).set(key, n);
|
|
13062
|
+
}
|
|
13063
|
+
this._size += n - old;
|
|
13064
|
+
return true;
|
|
12966
13065
|
}
|
|
12967
13066
|
/**
|
|
12968
|
-
*
|
|
12969
|
-
* @
|
|
12970
|
-
*
|
|
12971
|
-
* @param value - The new color.
|
|
13067
|
+
* Delete `n` occurrences of `key` (default 1).
|
|
13068
|
+
* @returns True if any occurrence was removed.
|
|
13069
|
+
* @remarks Time O(log n), Space O(1)
|
|
12972
13070
|
*/
|
|
12973
|
-
|
|
12974
|
-
|
|
13071
|
+
delete(key, n = 1) {
|
|
13072
|
+
var _a;
|
|
13073
|
+
this._validateKey(key);
|
|
13074
|
+
this._validateCount(n);
|
|
13075
|
+
if (n === 0) return false;
|
|
13076
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13077
|
+
if (old === 0) return false;
|
|
13078
|
+
const removed = Math.min(old, n);
|
|
13079
|
+
const next = old - removed;
|
|
13080
|
+
if (next === 0) __privateGet(this, _core4).delete(key);
|
|
13081
|
+
else __privateGet(this, _core4).set(key, next);
|
|
13082
|
+
this._size -= removed;
|
|
13083
|
+
return true;
|
|
12975
13084
|
}
|
|
12976
13085
|
/**
|
|
12977
|
-
*
|
|
12978
|
-
* @
|
|
12979
|
-
*
|
|
12980
|
-
* @returns The subtree node count.
|
|
13086
|
+
* Delete all occurrences of the given key.
|
|
13087
|
+
* @returns True if any occurrence was removed.
|
|
13088
|
+
* @remarks Time O(log n), Space O(1)
|
|
12981
13089
|
*/
|
|
12982
|
-
|
|
12983
|
-
|
|
13090
|
+
deleteAll(key) {
|
|
13091
|
+
var _a;
|
|
13092
|
+
this._validateKey(key);
|
|
13093
|
+
const old = (_a = __privateGet(this, _core4).get(key)) != null ? _a : 0;
|
|
13094
|
+
if (old === 0) return false;
|
|
13095
|
+
__privateGet(this, _core4).delete(key);
|
|
13096
|
+
this._size -= old;
|
|
13097
|
+
return true;
|
|
12984
13098
|
}
|
|
12985
13099
|
/**
|
|
12986
|
-
*
|
|
12987
|
-
* @remarks Time O(
|
|
12988
|
-
*
|
|
12989
|
-
* @param value - The new count.
|
|
13100
|
+
* Iterates over distinct keys (each key yielded once).
|
|
13101
|
+
* @remarks Time O(n), Space O(1)
|
|
12990
13102
|
*/
|
|
12991
|
-
|
|
12992
|
-
this.
|
|
13103
|
+
*keysDistinct() {
|
|
13104
|
+
yield* __privateGet(this, _core4).keys();
|
|
12993
13105
|
}
|
|
12994
13106
|
/**
|
|
12995
|
-
*
|
|
12996
|
-
* @remarks Time O(
|
|
12997
|
-
*
|
|
12998
|
-
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
13107
|
+
* Iterates over entries as [key, count] pairs.
|
|
13108
|
+
* @remarks Time O(n), Space O(1)
|
|
12999
13109
|
*/
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13110
|
+
*entries() {
|
|
13111
|
+
for (const [k, v] of __privateGet(this, _core4)) {
|
|
13112
|
+
yield [k, v != null ? v : 0];
|
|
13003
13113
|
}
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13114
|
+
}
|
|
13115
|
+
/**
|
|
13116
|
+
* Expanded iteration (default). Each key is yielded `count(key)` times.
|
|
13117
|
+
* @remarks Time O(size), Space O(1) where size is total occurrences
|
|
13118
|
+
*/
|
|
13119
|
+
*[Symbol.iterator]() {
|
|
13120
|
+
for (const [k, c] of this.entries()) {
|
|
13121
|
+
for (let i = 0; i < c; i++) yield k;
|
|
13008
13122
|
}
|
|
13009
|
-
return "MAL_NODE";
|
|
13010
13123
|
}
|
|
13011
|
-
};
|
|
13012
|
-
__name(_AVLTreeCounterNode, "AVLTreeCounterNode");
|
|
13013
|
-
var AVLTreeCounterNode = _AVLTreeCounterNode;
|
|
13014
|
-
var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
13015
13124
|
/**
|
|
13016
|
-
*
|
|
13017
|
-
* @remarks Time O(
|
|
13018
|
-
* @param keysNodesEntriesOrRaws
|
|
13019
|
-
* @param options
|
|
13020
|
-
* @returns New AVLTreeCounterNode instance.
|
|
13125
|
+
* Returns an array with all elements (expanded).
|
|
13126
|
+
* @remarks Time O(size), Space O(size)
|
|
13021
13127
|
*/
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
__publicField(this, "_count", 0);
|
|
13025
|
-
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
13128
|
+
toArray() {
|
|
13129
|
+
return [...this];
|
|
13026
13130
|
}
|
|
13027
|
-
|
|
13028
|
-
|
|
13131
|
+
/**
|
|
13132
|
+
* Returns an array with distinct keys only.
|
|
13133
|
+
* @remarks Time O(n), Space O(n)
|
|
13134
|
+
*/
|
|
13135
|
+
toDistinctArray() {
|
|
13136
|
+
return [...this.keysDistinct()];
|
|
13029
13137
|
}
|
|
13030
13138
|
/**
|
|
13031
|
-
*
|
|
13032
|
-
* @remarks Time O(
|
|
13033
|
-
* @returns Total count recomputed from nodes.
|
|
13139
|
+
* Returns an array of [key, count] entries.
|
|
13140
|
+
* @remarks Time O(n), Space O(n)
|
|
13034
13141
|
*/
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
this.dfs((node) => sum += node.count);
|
|
13038
|
-
return sum;
|
|
13142
|
+
toEntries() {
|
|
13143
|
+
return [...this.entries()];
|
|
13039
13144
|
}
|
|
13040
|
-
|
|
13041
|
-
|
|
13145
|
+
/**
|
|
13146
|
+
* Expose comparator for advanced usage/testing (read-only).
|
|
13147
|
+
* @remarks Time O(1), Space O(1)
|
|
13148
|
+
*/
|
|
13149
|
+
get comparator() {
|
|
13150
|
+
return __privateGet(this, _core4)._comparator;
|
|
13042
13151
|
}
|
|
13152
|
+
// ━━━ clear ━━━
|
|
13043
13153
|
/**
|
|
13044
|
-
*
|
|
13154
|
+
* Remove all elements from the multiset.
|
|
13045
13155
|
* @remarks Time O(1), Space O(1)
|
|
13046
|
-
* @
|
|
13156
|
+
* @example
|
|
13157
|
+
* const ms = new TreeMultiSet([1, 2, 2, 3]);
|
|
13158
|
+
* ms.clear();
|
|
13159
|
+
* ms.size; // 0
|
|
13047
13160
|
*/
|
|
13048
|
-
|
|
13049
|
-
|
|
13161
|
+
clear() {
|
|
13162
|
+
__privateGet(this, _core4).clear();
|
|
13163
|
+
this._size = 0;
|
|
13050
13164
|
}
|
|
13165
|
+
// ━━━ Navigable methods ━━━
|
|
13051
13166
|
/**
|
|
13052
|
-
*
|
|
13053
|
-
* @remarks Time O(log
|
|
13054
|
-
* @
|
|
13055
|
-
*
|
|
13056
|
-
*
|
|
13057
|
-
* @returns True if inserted/updated; false if ignored.
|
|
13167
|
+
* Returns the smallest key, or undefined if empty.
|
|
13168
|
+
* @remarks Time O(log n), Space O(1)
|
|
13169
|
+
* @example
|
|
13170
|
+
* const ms = new TreeMultiSet([3, 1, 4]);
|
|
13171
|
+
* ms.first(); // 1
|
|
13058
13172
|
*/
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
if (newNode === void 0) return false;
|
|
13062
|
-
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
13063
|
-
const inserted = super.set(newNode, newValue);
|
|
13064
|
-
if (inserted) {
|
|
13065
|
-
this._count += orgNodeCount;
|
|
13066
|
-
}
|
|
13067
|
-
return true;
|
|
13173
|
+
first() {
|
|
13174
|
+
return __privateGet(this, _core4).getLeftMost();
|
|
13068
13175
|
}
|
|
13069
13176
|
/**
|
|
13070
|
-
*
|
|
13071
|
-
* @remarks Time O(log
|
|
13072
|
-
* @
|
|
13073
|
-
*
|
|
13074
|
-
*
|
|
13177
|
+
* Returns the largest key, or undefined if empty.
|
|
13178
|
+
* @remarks Time O(log n), Space O(1)
|
|
13179
|
+
* @example
|
|
13180
|
+
* const ms = new TreeMultiSet([3, 1, 4]);
|
|
13181
|
+
* ms.last(); // 4
|
|
13075
13182
|
*/
|
|
13076
|
-
|
|
13077
|
-
|
|
13078
|
-
const deletedResult = [];
|
|
13079
|
-
if (!this.root) return deletedResult;
|
|
13080
|
-
const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
|
|
13081
|
-
if (!curr) return deletedResult;
|
|
13082
|
-
const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
|
|
13083
|
-
let needBalanced = void 0, orgCurrent = curr;
|
|
13084
|
-
if (curr.count > 1 && !ignoreCount) {
|
|
13085
|
-
curr.count--;
|
|
13086
|
-
this._count--;
|
|
13087
|
-
} else {
|
|
13088
|
-
if (!curr.left) {
|
|
13089
|
-
if (!parent) {
|
|
13090
|
-
if (curr.right !== void 0 && curr.right !== null) this._setRoot(curr.right);
|
|
13091
|
-
} else {
|
|
13092
|
-
const { familyPosition: fp } = curr;
|
|
13093
|
-
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
13094
|
-
parent.left = curr.right;
|
|
13095
|
-
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
13096
|
-
parent.right = curr.right;
|
|
13097
|
-
}
|
|
13098
|
-
needBalanced = parent;
|
|
13099
|
-
}
|
|
13100
|
-
} else {
|
|
13101
|
-
const leftSubTreeRightMost = curr.left ? this.getRightMost((node) => node, curr.left) : void 0;
|
|
13102
|
-
if (leftSubTreeRightMost) {
|
|
13103
|
-
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
13104
|
-
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
13105
|
-
if (parentOfLeftSubTreeMax) {
|
|
13106
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
|
|
13107
|
-
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
13108
|
-
} else {
|
|
13109
|
-
parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
13110
|
-
}
|
|
13111
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
13112
|
-
}
|
|
13113
|
-
}
|
|
13114
|
-
}
|
|
13115
|
-
this._size = this._size - 1;
|
|
13116
|
-
if (orgCurrent) this._count -= orgCurrent.count;
|
|
13117
|
-
}
|
|
13118
|
-
deletedResult.push({ deleted: orgCurrent, needBalanced });
|
|
13119
|
-
if (needBalanced) {
|
|
13120
|
-
this._balancePath(needBalanced);
|
|
13121
|
-
}
|
|
13122
|
-
return deletedResult;
|
|
13183
|
+
last() {
|
|
13184
|
+
return __privateGet(this, _core4).getRightMost();
|
|
13123
13185
|
}
|
|
13124
13186
|
/**
|
|
13125
|
-
*
|
|
13126
|
-
* @remarks Time O(
|
|
13127
|
-
* @
|
|
13187
|
+
* Removes all occurrences of the smallest key and returns it.
|
|
13188
|
+
* @remarks Time O(log n), Space O(1)
|
|
13189
|
+
* @example
|
|
13190
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3]);
|
|
13191
|
+
* ms.pollFirst(); // 1
|
|
13192
|
+
* ms.has(1); // false
|
|
13128
13193
|
*/
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13194
|
+
pollFirst() {
|
|
13195
|
+
const key = this.first();
|
|
13196
|
+
if (key === void 0) return void 0;
|
|
13197
|
+
this.deleteAll(key);
|
|
13198
|
+
return key;
|
|
13132
13199
|
}
|
|
13133
13200
|
/**
|
|
13134
|
-
*
|
|
13135
|
-
* @remarks Time O(
|
|
13136
|
-
* @
|
|
13137
|
-
*
|
|
13201
|
+
* Removes all occurrences of the largest key and returns it.
|
|
13202
|
+
* @remarks Time O(log n), Space O(1)
|
|
13203
|
+
* @example
|
|
13204
|
+
* const ms = new TreeMultiSet([1, 2, 3, 3]);
|
|
13205
|
+
* ms.pollLast(); // 3
|
|
13206
|
+
* ms.has(3); // false
|
|
13138
13207
|
*/
|
|
13139
|
-
|
|
13140
|
-
const
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
for (const nd of nodes) total += nd ? nd.count : 0;
|
|
13145
|
-
this._clearNodes();
|
|
13146
|
-
const build = /* @__PURE__ */ __name((l, r, parent) => {
|
|
13147
|
-
if (l > r) return void 0;
|
|
13148
|
-
const m = l + (r - l >> 1);
|
|
13149
|
-
const root = nodes[m];
|
|
13150
|
-
root.left = build(l, m - 1, root);
|
|
13151
|
-
root.right = build(m + 1, r, root);
|
|
13152
|
-
root.parent = parent;
|
|
13153
|
-
const lh = root.left ? root.left.height : -1;
|
|
13154
|
-
const rh = root.right ? root.right.height : -1;
|
|
13155
|
-
root.height = Math.max(lh, rh) + 1;
|
|
13156
|
-
return root;
|
|
13157
|
-
}, "build");
|
|
13158
|
-
const newRoot = build(0, n - 1, void 0);
|
|
13159
|
-
this._setRoot(newRoot);
|
|
13160
|
-
this._size = n;
|
|
13161
|
-
this._count = total;
|
|
13162
|
-
return true;
|
|
13208
|
+
pollLast() {
|
|
13209
|
+
const key = this.last();
|
|
13210
|
+
if (key === void 0) return void 0;
|
|
13211
|
+
this.deleteAll(key);
|
|
13212
|
+
return key;
|
|
13163
13213
|
}
|
|
13164
13214
|
/**
|
|
13165
|
-
*
|
|
13166
|
-
* @remarks Time O(
|
|
13167
|
-
* @
|
|
13215
|
+
* Returns the smallest key >= given key, or undefined.
|
|
13216
|
+
* @remarks Time O(log n), Space O(1)
|
|
13217
|
+
* @example
|
|
13218
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13219
|
+
* ms.ceiling(15); // 20
|
|
13220
|
+
* ms.ceiling(20); // 20
|
|
13168
13221
|
*/
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
this.bfs((node) => out.set(node.key, void 0, node.count));
|
|
13173
|
-
} else {
|
|
13174
|
-
this.bfs((node) => out.set(node.key, node.value, node.count));
|
|
13175
|
-
}
|
|
13176
|
-
if (this._isMapMode) out._store = this._store;
|
|
13177
|
-
return out;
|
|
13222
|
+
ceiling(key) {
|
|
13223
|
+
this._validateKey(key);
|
|
13224
|
+
return __privateGet(this, _core4).ceiling(key);
|
|
13178
13225
|
}
|
|
13179
13226
|
/**
|
|
13180
|
-
*
|
|
13181
|
-
* @remarks Time O(
|
|
13182
|
-
* @
|
|
13183
|
-
*
|
|
13184
|
-
*
|
|
13185
|
-
*
|
|
13186
|
-
* @param [options] - Options for the output tree.
|
|
13187
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
13188
|
-
* @returns A new AVLTreeCounter with mapped entries.
|
|
13227
|
+
* Returns the largest key <= given key, or undefined.
|
|
13228
|
+
* @remarks Time O(log n), Space O(1)
|
|
13229
|
+
* @example
|
|
13230
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13231
|
+
* ms.floor(25); // 20
|
|
13232
|
+
* ms.floor(20); // 20
|
|
13189
13233
|
*/
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
for (const [key, value] of this) {
|
|
13194
|
-
out.set(callback.call(thisArg, value, key, index++, this));
|
|
13195
|
-
}
|
|
13196
|
-
return out;
|
|
13234
|
+
floor(key) {
|
|
13235
|
+
this._validateKey(key);
|
|
13236
|
+
return __privateGet(this, _core4).floor(key);
|
|
13197
13237
|
}
|
|
13198
13238
|
/**
|
|
13199
|
-
*
|
|
13200
|
-
* @remarks Time O(
|
|
13201
|
-
* @
|
|
13202
|
-
*
|
|
13203
|
-
*
|
|
13204
|
-
*
|
|
13205
|
-
* @returns An empty like-kind instance.
|
|
13239
|
+
* Returns the smallest key > given key, or undefined.
|
|
13240
|
+
* @remarks Time O(log n), Space O(1)
|
|
13241
|
+
* @example
|
|
13242
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13243
|
+
* ms.higher(10); // 20
|
|
13244
|
+
* ms.higher(15); // 20
|
|
13206
13245
|
*/
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
return
|
|
13246
|
+
higher(key) {
|
|
13247
|
+
this._validateKey(key);
|
|
13248
|
+
return __privateGet(this, _core4).higher(key);
|
|
13210
13249
|
}
|
|
13211
13250
|
/**
|
|
13212
|
-
*
|
|
13213
|
-
* @remarks Time O(
|
|
13214
|
-
* @
|
|
13215
|
-
*
|
|
13216
|
-
*
|
|
13217
|
-
*
|
|
13218
|
-
* @param [options] - Options merged with the current snapshot.
|
|
13219
|
-
* @returns A like-kind AVLTreeCounter built from the iterable.
|
|
13251
|
+
* Returns the largest key < given key, or undefined.
|
|
13252
|
+
* @remarks Time O(log n), Space O(1)
|
|
13253
|
+
* @example
|
|
13254
|
+
* const ms = new TreeMultiSet([10, 20, 30]);
|
|
13255
|
+
* ms.lower(20); // 10
|
|
13256
|
+
* ms.lower(15); // 10
|
|
13220
13257
|
*/
|
|
13221
|
-
|
|
13222
|
-
|
|
13223
|
-
return
|
|
13258
|
+
lower(key) {
|
|
13259
|
+
this._validateKey(key);
|
|
13260
|
+
return __privateGet(this, _core4).lower(key);
|
|
13224
13261
|
}
|
|
13262
|
+
// ━━━ Functional methods ━━━
|
|
13225
13263
|
/**
|
|
13226
|
-
*
|
|
13227
|
-
* @remarks Time O(
|
|
13228
|
-
* @
|
|
13229
|
-
*
|
|
13230
|
-
*
|
|
13231
|
-
*
|
|
13264
|
+
* Iterates over distinct keys with their counts.
|
|
13265
|
+
* @remarks Time O(n), Space O(1)
|
|
13266
|
+
* @example
|
|
13267
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13268
|
+
* ms.forEach((key, count) => console.log(`${key}: ${count}`));
|
|
13269
|
+
* // 1: 2, 2: 1, 3: 3
|
|
13232
13270
|
*/
|
|
13233
|
-
|
|
13234
|
-
|
|
13235
|
-
|
|
13236
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
13237
|
-
const [key, entryValue] = keyNodeOrEntry;
|
|
13238
|
-
if (key === void 0 || key === null) return [void 0, void 0];
|
|
13239
|
-
const finalValue = value != null ? value : entryValue;
|
|
13240
|
-
return [this.createNode(key, finalValue, count), finalValue];
|
|
13271
|
+
forEach(callback) {
|
|
13272
|
+
for (const [k, c] of this.entries()) {
|
|
13273
|
+
callback(k, c);
|
|
13241
13274
|
}
|
|
13242
|
-
return [this.createNode(keyNodeOrEntry, value, count), value];
|
|
13243
13275
|
}
|
|
13244
13276
|
/**
|
|
13245
|
-
*
|
|
13246
|
-
* @remarks Time O(
|
|
13247
|
-
* @
|
|
13248
|
-
*
|
|
13249
|
-
*
|
|
13277
|
+
* Creates a new TreeMultiSet with entries that match the predicate.
|
|
13278
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13279
|
+
* @example
|
|
13280
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13281
|
+
* const filtered = ms.filter((key, count) => count >= 2);
|
|
13282
|
+
* // TreeMultiSet { 1: 2, 3: 3 }
|
|
13250
13283
|
*/
|
|
13251
|
-
|
|
13252
|
-
|
|
13253
|
-
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
|
|
13257
|
-
if (
|
|
13258
|
-
|
|
13259
|
-
destNode.key = srcNode.key;
|
|
13260
|
-
if (!this._isMapMode) destNode.value = srcNode.value;
|
|
13261
|
-
destNode.count = srcNode.count;
|
|
13262
|
-
destNode.height = srcNode.height;
|
|
13263
|
-
srcNode.key = tempNode.key;
|
|
13264
|
-
if (!this._isMapMode) srcNode.value = tempNode.value;
|
|
13265
|
-
srcNode.count = tempNode.count;
|
|
13266
|
-
srcNode.height = tempNode.height;
|
|
13284
|
+
filter(predicate) {
|
|
13285
|
+
const result = new _TreeMultiSet([], {
|
|
13286
|
+
comparator: __privateGet(this, _isDefaultComparator4) ? void 0 : this.comparator,
|
|
13287
|
+
isMapMode: __privateGet(this, _core4)._isMapMode
|
|
13288
|
+
});
|
|
13289
|
+
for (const [k, c] of this.entries()) {
|
|
13290
|
+
if (predicate(k, c)) {
|
|
13291
|
+
result.add(k, c);
|
|
13267
13292
|
}
|
|
13268
|
-
return destNode;
|
|
13269
13293
|
}
|
|
13270
|
-
return
|
|
13294
|
+
return result;
|
|
13271
13295
|
}
|
|
13272
13296
|
/**
|
|
13273
|
-
*
|
|
13274
|
-
* @remarks Time O(
|
|
13275
|
-
* @
|
|
13276
|
-
*
|
|
13277
|
-
*
|
|
13297
|
+
* Reduces the multiset to a single value.
|
|
13298
|
+
* @remarks Time O(n), Space O(1)
|
|
13299
|
+
* @example
|
|
13300
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13301
|
+
* const total = ms.reduce((acc, key, count) => acc + count, 0); // 6
|
|
13278
13302
|
*/
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
13303
|
+
reduce(callback, initialValue) {
|
|
13304
|
+
let acc = initialValue;
|
|
13305
|
+
for (const [k, c] of this.entries()) {
|
|
13306
|
+
acc = callback(acc, k, c);
|
|
13307
|
+
}
|
|
13308
|
+
return acc;
|
|
13309
|
+
}
|
|
13310
|
+
/**
|
|
13311
|
+
* Maps keys and counts to a new TreeMultiSet.
|
|
13312
|
+
* When multiple keys map to the same new key, counts are merged (added).
|
|
13313
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13314
|
+
* @example
|
|
13315
|
+
* const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
|
|
13316
|
+
* const mapped = ms.map((key, count) => [key * 10, count]);
|
|
13317
|
+
* // TreeMultiSet { 10: 2, 20: 1, 30: 3 }
|
|
13318
|
+
* @example
|
|
13319
|
+
* // Collision: counts merge
|
|
13320
|
+
* const ms = new TreeMultiSet([1, 2, 3]);
|
|
13321
|
+
* const merged = ms.map((key, count) => [key % 2, count]);
|
|
13322
|
+
* // { 0: 1, 1: 2 } (1 and 3 both map to 1, counts add)
|
|
13323
|
+
*/
|
|
13324
|
+
map(mapper, options) {
|
|
13325
|
+
const result = new _TreeMultiSet([], {
|
|
13326
|
+
comparator: options == null ? void 0 : options.comparator,
|
|
13327
|
+
isMapMode: __privateGet(this, _core4)._isMapMode
|
|
13328
|
+
});
|
|
13329
|
+
for (const [k, c] of this.entries()) {
|
|
13330
|
+
const [newKey, newCount] = mapper(k, c);
|
|
13331
|
+
result.add(newKey, newCount);
|
|
13332
|
+
}
|
|
13333
|
+
return result;
|
|
13334
|
+
}
|
|
13335
|
+
/**
|
|
13336
|
+
* Creates an independent copy of this multiset.
|
|
13337
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13338
|
+
* @example
|
|
13339
|
+
* const ms = new TreeMultiSet([1, 1, 2]);
|
|
13340
|
+
* const copy = ms.clone();
|
|
13341
|
+
* copy.add(3);
|
|
13342
|
+
* ms.has(3); // false (original unchanged)
|
|
13343
|
+
*/
|
|
13344
|
+
clone() {
|
|
13345
|
+
const result = new _TreeMultiSet([], {
|
|
13346
|
+
comparator: __privateGet(this, _isDefaultComparator4) ? void 0 : this.comparator,
|
|
13347
|
+
isMapMode: __privateGet(this, _core4)._isMapMode
|
|
13348
|
+
});
|
|
13349
|
+
for (const [k, c] of this.entries()) {
|
|
13350
|
+
result.add(k, c);
|
|
13351
|
+
}
|
|
13352
|
+
return result;
|
|
13353
|
+
}
|
|
13354
|
+
// ━━━ Tree utilities ━━━
|
|
13355
|
+
/**
|
|
13356
|
+
* Returns keys within the given range.
|
|
13357
|
+
* @remarks Time O(log n + k), Space O(k) where k is result size
|
|
13358
|
+
* @example
|
|
13359
|
+
* const ms = new TreeMultiSet([10, 20, 30, 40, 50]);
|
|
13360
|
+
* ms.rangeSearch([15, 45]); // [20, 30, 40]
|
|
13361
|
+
*/
|
|
13362
|
+
rangeSearch(range, callback) {
|
|
13363
|
+
const cb = callback != null ? callback : ((k) => k);
|
|
13364
|
+
return __privateGet(this, _core4).rangeSearch(range, (node) => cb(node.key));
|
|
13365
|
+
}
|
|
13366
|
+
/**
|
|
13367
|
+
* Prints the internal tree structure (for debugging).
|
|
13368
|
+
* @remarks Time O(n), Space O(n)
|
|
13369
|
+
* @example
|
|
13370
|
+
* const ms = new TreeMultiSet([1, 2, 3]);
|
|
13371
|
+
* ms.print();
|
|
13372
|
+
*/
|
|
13373
|
+
print() {
|
|
13374
|
+
__privateGet(this, _core4).print();
|
|
13282
13375
|
}
|
|
13283
13376
|
};
|
|
13284
|
-
|
|
13285
|
-
|
|
13377
|
+
_core4 = new WeakMap();
|
|
13378
|
+
_isDefaultComparator4 = new WeakMap();
|
|
13379
|
+
__name(_TreeMultiSet, "TreeMultiSet");
|
|
13380
|
+
var TreeMultiSet = _TreeMultiSet;
|
|
13286
13381
|
|
|
13287
13382
|
// src/data-structures/priority-queue/priority-queue.ts
|
|
13288
13383
|
var _PriorityQueue = class _PriorityQueue extends Heap {
|
|
@@ -14489,6 +14584,13 @@ var TreeNode = _TreeNode;
|
|
|
14489
14584
|
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
14490
14585
|
* @license MIT License
|
|
14491
14586
|
*/
|
|
14587
|
+
/**
|
|
14588
|
+
* data-structure-typed
|
|
14589
|
+
*
|
|
14590
|
+
* @author Pablo Zeng
|
|
14591
|
+
* @copyright Copyright (c) 2022 Pablo Zeng
|
|
14592
|
+
* @license MIT License
|
|
14593
|
+
*/
|
|
14492
14594
|
/**
|
|
14493
14595
|
* data-structure-typed
|
|
14494
14596
|
*
|
|
@@ -14497,6 +14599,6 @@ var TreeNode = _TreeNode;
|
|
|
14497
14599
|
* @license MIT License
|
|
14498
14600
|
*/
|
|
14499
14601
|
|
|
14500
|
-
export { AVLTree,
|
|
14602
|
+
export { AVLTree, AVLTreeNode, AbstractEdge, AbstractGraph, AbstractVertex, BST, BSTNode, BinaryIndexedTree, BinaryTree, BinaryTreeNode, Character, DFSOperation, Deque, DirectedEdge, DirectedGraph, DirectedVertex, DoublyLinkedList, DoublyLinkedListNode, FibonacciHeap, FibonacciHeapNode, HashMap, Heap, IterableElementBase, IterableEntryBase, LinkedHashMap, LinkedListQueue, MapEdge, MapGraph, MapVertex, Matrix, MaxHeap, MaxPriorityQueue, MinHeap, MinPriorityQueue, Navigator, PriorityQueue, Queue, Range, RedBlackTree, RedBlackTreeNode, SegmentTree, SegmentTreeNode, SinglyLinkedList, SinglyLinkedListNode, SkipList, SkipListNode, Stack, TreeMap, TreeMultiMap, TreeMultiMapNode, TreeMultiSet, TreeNode, TreeSet, Trie, TrieNode, UndirectedEdge, UndirectedGraph, UndirectedVertex, arrayRemove, asyncTrampoline, calcMinUnitsRequired, getMSB, isComparable, isTrampolineThunk, isWeakKey, makeAsyncTrampoline, makeTrampoline, makeTrampolineThunk, rangeCheck, roundFixed, throwRangeError, toBinaryString, trampoline, uuidV4 };
|
|
14501
14603
|
//# sourceMappingURL=index.mjs.map
|
|
14502
14604
|
//# sourceMappingURL=index.mjs.map
|