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