@shd101wyy/yo 0.0.2
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/LICENSE.md +17 -0
- package/README.md +80 -0
- package/out/cjs/index.cjs +51 -0
- package/out/cjs/yo-cli.cjs +2158 -0
- package/out/esm/index.mjs +51 -0
- package/out/types/src/codegen/async/runtime.d.ts +2 -0
- package/out/types/src/codegen/async/state-code-gen.d.ts +10 -0
- package/out/types/src/codegen/async/state-machine.d.ts +13 -0
- package/out/types/src/codegen/c/collection.d.ts +3 -0
- package/out/types/src/codegen/codegen-c.d.ts +12 -0
- package/out/types/src/codegen/constants.d.ts +3 -0
- package/out/types/src/codegen/expressions/array.d.ts +4 -0
- package/out/types/src/codegen/expressions/generation.d.ts +11 -0
- package/out/types/src/codegen/expressions/index.d.ts +2 -0
- package/out/types/src/codegen/functions/collection.d.ts +5 -0
- package/out/types/src/codegen/functions/context.d.ts +57 -0
- package/out/types/src/codegen/functions/generation.d.ts +25 -0
- package/out/types/src/codegen/functions/index.d.ts +2 -0
- package/out/types/src/codegen/index.d.ts +20 -0
- package/out/types/src/codegen/parallelism/runtime.d.ts +2 -0
- package/out/types/src/codegen/types/collection.d.ts +8 -0
- package/out/types/src/codegen/types/generation.d.ts +13 -0
- package/out/types/src/codegen/types/index.d.ts +2 -0
- package/out/types/src/codegen/utils/fixup.d.ts +2 -0
- package/out/types/src/codegen/utils/index.d.ts +77 -0
- package/out/types/src/codegen/values/index.d.ts +1 -0
- package/out/types/src/emitter.d.ts +11 -0
- package/out/types/src/env.d.ts +85 -0
- package/out/types/src/error.d.ts +45 -0
- package/out/types/src/evaluator/async/await-analysis-types.d.ts +23 -0
- package/out/types/src/evaluator/async/await-analysis.d.ts +5 -0
- package/out/types/src/evaluator/builtins/alignof.d.ts +8 -0
- package/out/types/src/evaluator/builtins/and_or.d.ts +8 -0
- package/out/types/src/evaluator/builtins/arc_fns.d.ts +58 -0
- package/out/types/src/evaluator/builtins/array_fns.d.ts +0 -0
- package/out/types/src/evaluator/builtins/as.d.ts +8 -0
- package/out/types/src/evaluator/builtins/async_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_assert.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +33 -0
- package/out/types/src/evaluator/builtins/compt_print.d.ts +8 -0
- package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/consume.d.ts +8 -0
- package/out/types/src/evaluator/builtins/drop.d.ts +8 -0
- package/out/types/src/evaluator/builtins/dup.d.ts +8 -0
- package/out/types/src/evaluator/builtins/expr_fns.d.ts +33 -0
- package/out/types/src/evaluator/builtins/future_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/gc.d.ts +8 -0
- package/out/types/src/evaluator/builtins/gensym.d.ts +8 -0
- package/out/types/src/evaluator/builtins/impl_constraint.d.ts +8 -0
- package/out/types/src/evaluator/builtins/macro_expand.d.ts +8 -0
- package/out/types/src/evaluator/builtins/numeric_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/panic.d.ts +8 -0
- package/out/types/src/evaluator/builtins/ptr_fns.d.ts +8 -0
- package/out/types/src/evaluator/builtins/quote.d.ts +13 -0
- package/out/types/src/evaluator/builtins/rc.d.ts +8 -0
- package/out/types/src/evaluator/builtins/sizeof.d.ts +8 -0
- package/out/types/src/evaluator/builtins/the.d.ts +8 -0
- package/out/types/src/evaluator/builtins/type_fns.d.ts +28 -0
- package/out/types/src/evaluator/builtins/va_start.d.ts +8 -0
- package/out/types/src/evaluator/builtins/var_fns.d.ts +18 -0
- package/out/types/src/evaluator/calls/array.d.ts +13 -0
- package/out/types/src/evaluator/calls/array_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/closure_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/compt_function.d.ts +19 -0
- package/out/types/src/evaluator/calls/compt_list_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/function.d.ts +16 -0
- package/out/types/src/evaluator/calls/function_type.d.ts +15 -0
- package/out/types/src/evaluator/calls/helper.d.ts +42 -0
- package/out/types/src/evaluator/calls/iso.d.ts +15 -0
- package/out/types/src/evaluator/calls/module_type.d.ts +11 -0
- package/out/types/src/evaluator/calls/numeric_type.d.ts +15 -0
- package/out/types/src/evaluator/calls/pointer.d.ts +8 -0
- package/out/types/src/evaluator/calls/pointer_type.d.ts +14 -0
- package/out/types/src/evaluator/calls/type.d.ts +12 -0
- package/out/types/src/evaluator/context.d.ts +169 -0
- package/out/types/src/evaluator/exprs/_expr.d.ts +8 -0
- package/out/types/src/evaluator/exprs/assignment.d.ts +9 -0
- package/out/types/src/evaluator/exprs/begin.d.ts +10 -0
- package/out/types/src/evaluator/exprs/binding.d.ts +12 -0
- package/out/types/src/evaluator/exprs/c_include.d.ts +8 -0
- package/out/types/src/evaluator/exprs/cond.d.ts +8 -0
- package/out/types/src/evaluator/exprs/destructuring_assignment.d.ts +33 -0
- package/out/types/src/evaluator/exprs/exists.d.ts +0 -0
- package/out/types/src/evaluator/exprs/expr.d.ts +9 -0
- package/out/types/src/evaluator/exprs/extern.d.ts +8 -0
- package/out/types/src/evaluator/exprs/identifer_and_operator.d.ts +9 -0
- package/out/types/src/evaluator/exprs/import.d.ts +9 -0
- package/out/types/src/evaluator/exprs/initialization_assignment.d.ts +8 -0
- package/out/types/src/evaluator/exprs/match.d.ts +8 -0
- package/out/types/src/evaluator/exprs/open.d.ts +8 -0
- package/out/types/src/evaluator/exprs/property_access.d.ts +8 -0
- package/out/types/src/evaluator/exprs/recur.d.ts +8 -0
- package/out/types/src/evaluator/exprs/subtype_of.d.ts +21 -0
- package/out/types/src/evaluator/exprs/test.d.ts +8 -0
- package/out/types/src/evaluator/exprs/typeof.d.ts +8 -0
- package/out/types/src/evaluator/exprs/while.d.ts +8 -0
- package/out/types/src/evaluator/index.d.ts +26 -0
- package/out/types/src/evaluator/types/array.d.ts +8 -0
- package/out/types/src/evaluator/types/closure.d.ts +8 -0
- package/out/types/src/evaluator/types/compt_list.d.ts +8 -0
- package/out/types/src/evaluator/types/concrete_module.d.ts +8 -0
- package/out/types/src/evaluator/types/dyn.d.ts +8 -0
- package/out/types/src/evaluator/types/enum.d.ts +8 -0
- package/out/types/src/evaluator/types/expr_synthesizer.d.ts +14 -0
- package/out/types/src/evaluator/types/field.d.ts +14 -0
- package/out/types/src/evaluator/types/fn_module.d.ts +8 -0
- package/out/types/src/evaluator/types/function.d.ts +58 -0
- package/out/types/src/evaluator/types/future_module.d.ts +8 -0
- package/out/types/src/evaluator/types/module.d.ts +19 -0
- package/out/types/src/evaluator/types/newtype.d.ts +8 -0
- package/out/types/src/evaluator/types/object.d.ts +8 -0
- package/out/types/src/evaluator/types/proofs.d.ts +0 -0
- package/out/types/src/evaluator/types/slice.d.ts +8 -0
- package/out/types/src/evaluator/types/struct.d.ts +8 -0
- package/out/types/src/evaluator/types/synthesizer.d.ts +16 -0
- package/out/types/src/evaluator/types/tuple.d.ts +18 -0
- package/out/types/src/evaluator/types/union.d.ts +8 -0
- package/out/types/src/evaluator/types/utils.d.ts +71 -0
- package/out/types/src/evaluator/types/validation.d.ts +3 -0
- package/out/types/src/evaluator/utils/array-utils.d.ts +15 -0
- package/out/types/src/evaluator/utils/closure.d.ts +35 -0
- package/out/types/src/evaluator/utils.d.ts +4 -0
- package/out/types/src/evaluator/values/anonymous_function.d.ts +8 -0
- package/out/types/src/evaluator/values/anonymous_module.d.ts +17 -0
- package/out/types/src/evaluator/values/anonymous_struct.d.ts +8 -0
- package/out/types/src/evaluator/values/array.d.ts +8 -0
- package/out/types/src/evaluator/values/boolean.d.ts +3 -0
- package/out/types/src/evaluator/values/char.d.ts +3 -0
- package/out/types/src/evaluator/values/compt_list.d.ts +8 -0
- package/out/types/src/evaluator/values/dyn.d.ts +8 -0
- package/out/types/src/evaluator/values/float.d.ts +4 -0
- package/out/types/src/evaluator/values/integer.d.ts +4 -0
- package/out/types/src/evaluator/values/module.d.ts +58 -0
- package/out/types/src/evaluator/values/string.d.ts +3 -0
- package/out/types/src/evaluator/values/tuple.d.ts +32 -0
- package/out/types/src/expr.d.ts +456 -0
- package/out/types/src/function-value.d.ts +42 -0
- package/out/types/src/index.d.ts +4 -0
- package/out/types/src/lexer.d.ts +2 -0
- package/out/types/src/logger.d.ts +1 -0
- package/out/types/src/module-manager.d.ts +30 -0
- package/out/types/src/naming-checker.d.ts +4 -0
- package/out/types/src/parser.d.ts +33 -0
- package/out/types/src/test-runner.d.ts +30 -0
- package/out/types/src/tests/codegen.test.d.ts +1 -0
- package/out/types/src/tests/fixme.test.d.ts +1 -0
- package/out/types/src/tests/module-manager.test.d.ts +1 -0
- package/out/types/src/tests/parser.test.d.ts +1 -0
- package/out/types/src/tests/sample.test.d.ts +0 -0
- package/out/types/src/tests/std.test.d.ts +1 -0
- package/out/types/src/token.d.ts +40 -0
- package/out/types/src/type-value.d.ts +7 -0
- package/out/types/src/types/compatibility.d.ts +16 -0
- package/out/types/src/types/creators.d.ts +73 -0
- package/out/types/src/types/definitions.d.ts +218 -0
- package/out/types/src/types/guards.d.ts +70 -0
- package/out/types/src/types/hierarchy.d.ts +4 -0
- package/out/types/src/types/index.d.ts +7 -0
- package/out/types/src/types/module_field.d.ts +2 -0
- package/out/types/src/types/tags.d.ts +45 -0
- package/out/types/src/types/utils.d.ts +50 -0
- package/out/types/src/unit-value.d.ts +7 -0
- package/out/types/src/utils.d.ts +6 -0
- package/out/types/src/value-tag.d.ts +29 -0
- package/out/types/src/value.d.ts +110 -0
- package/out/types/src/yo-cli.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +57 -0
- package/scripts/check-liburing.js +76 -0
- package/std/alg/hash.yo +50 -0
- package/std/allocator.yo +113 -0
- package/std/allocators/c_allocator.yo +118 -0
- package/std/async.yo +13 -0
- package/std/collections/array_list.yo +415 -0
- package/std/collections/hash_map.yo +482 -0
- package/std/collections/hash_set.yo +706 -0
- package/std/collections/index.yo +11 -0
- package/std/collections/linked_list.yo +439 -0
- package/std/error.yo +0 -0
- package/std/gc.yo +10 -0
- package/std/index.yo +12 -0
- package/std/io/file.yo +191 -0
- package/std/io/index.yo +5 -0
- package/std/libc/assert.yo +39 -0
- package/std/libc/ctype.yo +57 -0
- package/std/libc/errno.yo +182 -0
- package/std/libc/float.yo +87 -0
- package/std/libc/index.yo +29 -0
- package/std/libc/limits.yo +65 -0
- package/std/libc/math.yo +679 -0
- package/std/libc/signal.yo +101 -0
- package/std/libc/stdatomic.yo +213 -0
- package/std/libc/stdint.yo +214 -0
- package/std/libc/stdio.yo +225 -0
- package/std/libc/stdlib.yo +204 -0
- package/std/libc/string.yo +151 -0
- package/std/libc/time.yo +92 -0
- package/std/libc/unistd.yo +130 -0
- package/std/monad.yo +152 -0
- package/std/prelude.yo +3094 -0
- package/std/string/index.yo +8 -0
- package/std/string/rune.yo +82 -0
- package/std/string/string.yo +288 -0
- package/std/sync.yo +95 -0
- package/std/thread.yo +36 -0
- package/std/time.yo +13 -0
- package/std/worker.yo +36 -0
- package/vendor/mimalloc/.gitattributes +12 -0
- package/vendor/mimalloc/CMakeLists.txt +763 -0
- package/vendor/mimalloc/LICENSE +21 -0
- package/vendor/mimalloc/SECURITY.md +41 -0
- package/vendor/mimalloc/azure-pipelines.yml +251 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64.lib +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.lib +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect.lib +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect32.dll +0 -0
- package/vendor/mimalloc/bin/mimalloc-redirect32.lib +0 -0
- package/vendor/mimalloc/bin/minject-arm64.exe +0 -0
- package/vendor/mimalloc/bin/minject.exe +0 -0
- package/vendor/mimalloc/bin/minject32.exe +0 -0
- package/vendor/mimalloc/bin/readme.md +118 -0
- package/vendor/mimalloc/cmake/JoinPaths.cmake +23 -0
- package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +19 -0
- package/vendor/mimalloc/cmake/mimalloc-config.cmake +14 -0
- package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +23 -0
- package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +28 -0
- package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +28 -0
- package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +23 -0
- package/vendor/mimalloc/contrib/docker/readme.md +10 -0
- package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +64 -0
- package/vendor/mimalloc/contrib/vcpkg/readme.md +40 -0
- package/vendor/mimalloc/contrib/vcpkg/usage +20 -0
- package/vendor/mimalloc/contrib/vcpkg/vcpkg-cmake-wrapper.cmake +20 -0
- package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +48 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-a.svg +887 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-b.svg +1185 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-a.svg +757 -0
- package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-b.svg +1028 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-1.svg +769 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-a.svg +868 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-b.svg +1157 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-2.svg +983 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-1.svg +683 -0
- package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-2.svg +854 -0
- package/vendor/mimalloc/doc/bench-2020/bench-spec-rss.svg +713 -0
- package/vendor/mimalloc/doc/bench-2020/bench-spec.svg +713 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-1.svg +890 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-2.svg +1146 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-1.svg +796 -0
- package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-2.svg +974 -0
- package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-a.svg +952 -0
- package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-b.svg +1255 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-a.svg +955 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-b.svg +1269 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-a.svg +836 -0
- package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-b.svg +1131 -0
- package/vendor/mimalloc/doc/bench-2021/bench-macmini-2021-01-30.svg +766 -0
- package/vendor/mimalloc/doc/doxyfile +2895 -0
- package/vendor/mimalloc/doc/ds-logo.jpg +0 -0
- package/vendor/mimalloc/doc/ds-logo.png +0 -0
- package/vendor/mimalloc/doc/mimalloc-doc.h +1452 -0
- package/vendor/mimalloc/doc/mimalloc-doxygen.css +60 -0
- package/vendor/mimalloc/doc/mimalloc-logo-100.png +0 -0
- package/vendor/mimalloc/doc/mimalloc-logo.png +0 -0
- package/vendor/mimalloc/doc/mimalloc-logo.svg +161 -0
- package/vendor/mimalloc/doc/spades-logo.png +0 -0
- package/vendor/mimalloc/doc/unreal-logo.svg +43 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +500 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj.filters +108 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj +508 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj.filters +111 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-test-dep.vcxproj +355 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-test.vcxproj +360 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-api.vcxproj +295 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-stress.vcxproj +292 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test.vcxproj +289 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc.sln +151 -0
- package/vendor/mimalloc/include/mimalloc/atomic.h +557 -0
- package/vendor/mimalloc/include/mimalloc/internal.h +1153 -0
- package/vendor/mimalloc/include/mimalloc/prim.h +421 -0
- package/vendor/mimalloc/include/mimalloc/track.h +145 -0
- package/vendor/mimalloc/include/mimalloc/types.h +685 -0
- package/vendor/mimalloc/include/mimalloc-new-delete.h +66 -0
- package/vendor/mimalloc/include/mimalloc-override.h +68 -0
- package/vendor/mimalloc/include/mimalloc-stats.h +103 -0
- package/vendor/mimalloc/include/mimalloc.h +612 -0
- package/vendor/mimalloc/mimalloc.pc.in +11 -0
- package/vendor/mimalloc/readme.md +946 -0
- package/vendor/mimalloc/src/alloc-aligned.c +360 -0
- package/vendor/mimalloc/src/alloc-override.c +316 -0
- package/vendor/mimalloc/src/alloc-posix.c +185 -0
- package/vendor/mimalloc/src/alloc.c +692 -0
- package/vendor/mimalloc/src/arena-abandon.c +346 -0
- package/vendor/mimalloc/src/arena.c +1043 -0
- package/vendor/mimalloc/src/bitmap.c +441 -0
- package/vendor/mimalloc/src/bitmap.h +119 -0
- package/vendor/mimalloc/src/free.c +572 -0
- package/vendor/mimalloc/src/heap.c +733 -0
- package/vendor/mimalloc/src/init.c +714 -0
- package/vendor/mimalloc/src/libc.c +334 -0
- package/vendor/mimalloc/src/options.c +663 -0
- package/vendor/mimalloc/src/os.c +770 -0
- package/vendor/mimalloc/src/page-queue.c +390 -0
- package/vendor/mimalloc/src/page.c +1049 -0
- package/vendor/mimalloc/src/prim/emscripten/prim.c +249 -0
- package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +461 -0
- package/vendor/mimalloc/src/prim/osx/prim.c +9 -0
- package/vendor/mimalloc/src/prim/prim.c +76 -0
- package/vendor/mimalloc/src/prim/readme.md +9 -0
- package/vendor/mimalloc/src/prim/unix/prim.c +934 -0
- package/vendor/mimalloc/src/prim/wasi/prim.c +284 -0
- package/vendor/mimalloc/src/prim/windows/etw-mimalloc.wprp +61 -0
- package/vendor/mimalloc/src/prim/windows/etw.h +905 -0
- package/vendor/mimalloc/src/prim/windows/etw.man +0 -0
- package/vendor/mimalloc/src/prim/windows/prim.c +878 -0
- package/vendor/mimalloc/src/prim/windows/readme.md +17 -0
- package/vendor/mimalloc/src/random.c +258 -0
- package/vendor/mimalloc/src/segment-map.c +142 -0
- package/vendor/mimalloc/src/segment.c +1702 -0
- package/vendor/mimalloc/src/static.c +41 -0
- package/vendor/mimalloc/src/stats.c +635 -0
- package/vendor/mimalloc/test/CMakeLists.txt +56 -0
- package/vendor/mimalloc/test/main-override-dep.cpp +51 -0
- package/vendor/mimalloc/test/main-override-dep.h +11 -0
- package/vendor/mimalloc/test/main-override-static.c +539 -0
- package/vendor/mimalloc/test/main-override.c +36 -0
- package/vendor/mimalloc/test/main-override.cpp +497 -0
- package/vendor/mimalloc/test/main.c +46 -0
- package/vendor/mimalloc/test/readme.md +16 -0
- package/vendor/mimalloc/test/test-api-fill.c +343 -0
- package/vendor/mimalloc/test/test-api.c +466 -0
- package/vendor/mimalloc/test/test-stress.c +428 -0
- package/vendor/mimalloc/test/test-wrong.c +92 -0
- package/vendor/mimalloc/test/testhelper.h +49 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HashMap - A high-performance hash map implementation using SwissTable algorithm
|
|
3
|
+
*
|
|
4
|
+
* SwissTable is a state-of-the-art hash table design developed by Google for Abseil.
|
|
5
|
+
* Key features:
|
|
6
|
+
* - SIMD-accelerated lookup using control bytes
|
|
7
|
+
* - Quadratic probing for collision resolution
|
|
8
|
+
* - 7/8 max load factor for good performance
|
|
9
|
+
* - Compact memory layout with metadata array
|
|
10
|
+
*
|
|
11
|
+
* Memory layout:
|
|
12
|
+
* - ctrl: Array of control bytes (metadata), one per bucket
|
|
13
|
+
* - data: Array of key-value pairs
|
|
14
|
+
*
|
|
15
|
+
* Control byte values:
|
|
16
|
+
* - 0xFF (EMPTY): Bucket is empty and never used
|
|
17
|
+
* - 0xFE (DELETED): Bucket was used but is now deleted
|
|
18
|
+
* - 0x00-0x7F: Lower 7 bits of hash (H2 hash), indicates occupied bucket
|
|
19
|
+
*
|
|
20
|
+
* Hash function splits hash into two parts:
|
|
21
|
+
* - H1: Upper bits used to find bucket group
|
|
22
|
+
* - H2: Lower 7 bits stored in control byte for fast SIMD comparison
|
|
23
|
+
*/
|
|
24
|
+
{ GlobalAllocator, AllocError } :: import "../allocator.yo";
|
|
25
|
+
{ malloc, calloc, realloc, free } :: GlobalAllocator;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* HashMap error types
|
|
29
|
+
*/
|
|
30
|
+
HashMapError :: enum(
|
|
31
|
+
AllocError(error : AllocError),
|
|
32
|
+
KeyNotFound,
|
|
33
|
+
CapacityOverflow
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Control byte constants for SwissTable
|
|
38
|
+
*/
|
|
39
|
+
CTRL_EMPTY :: u8(255);
|
|
40
|
+
CTRL_DELETED :: u8(254);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Default initial capacity (must be power of 2)
|
|
44
|
+
*/
|
|
45
|
+
DEFAULT_CAPACITY :: usize(16);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Maximum load factor: 7/8 = 0.875
|
|
49
|
+
* We resize when: size > capacity * 7 / 8
|
|
50
|
+
*/
|
|
51
|
+
MAX_LOAD_FACTOR_NUMERATOR :: usize(7);
|
|
52
|
+
MAX_LOAD_FACTOR_DENOMINATOR :: usize(8);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Bucket - Internal structure to store key-value pairs
|
|
56
|
+
*/
|
|
57
|
+
Bucket :: (fn(compt(K): Type, compt(V): Type) -> compt(Type))
|
|
58
|
+
struct(
|
|
59
|
+
key : K,
|
|
60
|
+
value : V
|
|
61
|
+
)
|
|
62
|
+
;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Extract H2 hash (lower 7 bits) from full hash
|
|
66
|
+
*/
|
|
67
|
+
h2_hash :: (fn(hash: u64) -> u8)
|
|
68
|
+
u8(hash & u64(127))
|
|
69
|
+
;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Extract H1 hash (upper bits) for bucket index
|
|
73
|
+
*/
|
|
74
|
+
h1_hash :: (fn(hash: u64, capacity: usize) -> usize)
|
|
75
|
+
(usize((hash >> u64(7))) % capacity)
|
|
76
|
+
;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* HashMap type - high-performance hash table using SwissTable
|
|
80
|
+
*
|
|
81
|
+
* Memory layout:
|
|
82
|
+
* - ctrl: Pointer to control bytes array (length = capacity)
|
|
83
|
+
* - data: Pointer to buckets array (length = capacity)
|
|
84
|
+
* - capacity: Total number of buckets (always power of 2)
|
|
85
|
+
* - size: Current number of occupied buckets
|
|
86
|
+
*/
|
|
87
|
+
HashMap :: (fn(
|
|
88
|
+
compt(K): Type,
|
|
89
|
+
compt(V): Type,
|
|
90
|
+
where(K <: (Eq(K), Hash))
|
|
91
|
+
) -> compt(Type))
|
|
92
|
+
object(
|
|
93
|
+
ctrl : ?*(u8),
|
|
94
|
+
data : ?*(Bucket(K, V)),
|
|
95
|
+
capacity : usize,
|
|
96
|
+
size : usize,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Allocate memory for HashMap with given capacity
|
|
100
|
+
* Initializes all control bytes to EMPTY
|
|
101
|
+
*/
|
|
102
|
+
_alloc_with_capacity :: (fn(capacity: usize) -> Result(Self, HashMapError))(
|
|
103
|
+
{
|
|
104
|
+
bucket_size :: sizeof(Bucket(K, V));
|
|
105
|
+
ctrl_size := capacity;
|
|
106
|
+
data_size := (capacity * bucket_size);
|
|
107
|
+
|
|
108
|
+
ctrl_result := malloc(ctrl_size);
|
|
109
|
+
match(ctrl_result,
|
|
110
|
+
.None => .Err(.AllocError(error: .OutOfMemory)),
|
|
111
|
+
.Some(ctrl_void_ptr) => {
|
|
112
|
+
ctrl_ptr := *(u8)(ctrl_void_ptr);
|
|
113
|
+
|
|
114
|
+
data_result := malloc(data_size);
|
|
115
|
+
match(data_result,
|
|
116
|
+
.None => {
|
|
117
|
+
free(.Some(*(void)(ctrl_ptr)));
|
|
118
|
+
.Err(.AllocError(error: .OutOfMemory))
|
|
119
|
+
},
|
|
120
|
+
.Some(data_void_ptr) => {
|
|
121
|
+
data_ptr := *(Bucket(K, V))(data_void_ptr);
|
|
122
|
+
|
|
123
|
+
i := usize(0);
|
|
124
|
+
while(i < capacity, i = (i + usize(1)), {
|
|
125
|
+
(ctrl_ptr &+ i).* = CTRL_EMPTY;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
.Ok(Self(
|
|
129
|
+
ctrl: .Some(ctrl_ptr),
|
|
130
|
+
data: .Some(data_ptr),
|
|
131
|
+
capacity: capacity,
|
|
132
|
+
size: usize(0)
|
|
133
|
+
))
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Create a new empty HashMap with default capacity
|
|
143
|
+
*/
|
|
144
|
+
new :: (fn() -> Self)(
|
|
145
|
+
{
|
|
146
|
+
result := Self._alloc_with_capacity(DEFAULT_CAPACITY);
|
|
147
|
+
match(result,
|
|
148
|
+
.Ok(map) => map,
|
|
149
|
+
.Err(_) => panic("Failed to allocate HashMap")
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
),
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Create a HashMap with a specific initial capacity
|
|
156
|
+
* Capacity will be rounded up to next power of 2
|
|
157
|
+
*/
|
|
158
|
+
with_capacity :: (fn(requested_capacity: usize) -> Self)(
|
|
159
|
+
{
|
|
160
|
+
capacity := cond(
|
|
161
|
+
(requested_capacity < DEFAULT_CAPACITY) => DEFAULT_CAPACITY,
|
|
162
|
+
true => {
|
|
163
|
+
c := requested_capacity;
|
|
164
|
+
c = (c - usize(1));
|
|
165
|
+
c = (c | (c >> usize(1)));
|
|
166
|
+
c = (c | (c >> usize(2)));
|
|
167
|
+
c = (c | (c >> usize(4)));
|
|
168
|
+
c = (c | (c >> usize(8)));
|
|
169
|
+
c = (c | (c >> usize(16)));
|
|
170
|
+
(c + usize(1))
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
result := Self._alloc_with_capacity(capacity);
|
|
175
|
+
match(result,
|
|
176
|
+
.Ok(map) => map,
|
|
177
|
+
.Err(_) => panic("Failed to allocate HashMap")
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get ctrl pointer (unwrapped for internal use)
|
|
184
|
+
*/
|
|
185
|
+
_ctrl_ptr :: (fn(self: Self) -> *(u8))(
|
|
186
|
+
match(self.ctrl,
|
|
187
|
+
.Some(ptr) => ptr,
|
|
188
|
+
.None => panic("HashMap ctrl pointer is null")
|
|
189
|
+
)
|
|
190
|
+
),
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get data pointer (unwrapped for internal use)
|
|
194
|
+
*/
|
|
195
|
+
_data_ptr :: (fn(self: Self) -> *(Bucket(K, V)))(
|
|
196
|
+
match(self.data,
|
|
197
|
+
.Some(ptr) => ptr,
|
|
198
|
+
.None => panic("HashMap data pointer is null")
|
|
199
|
+
)
|
|
200
|
+
),
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Find bucket index for a given key using quadratic probing
|
|
204
|
+
* Returns Some(index) if key is found, None otherwise
|
|
205
|
+
*/
|
|
206
|
+
_find_bucket :: (fn(self: Self, key: K, hash: u64) -> Option(usize))(
|
|
207
|
+
{
|
|
208
|
+
h2 := h2_hash(hash);
|
|
209
|
+
index := h1_hash(hash, self.capacity);
|
|
210
|
+
probe := usize(0);
|
|
211
|
+
ctrl_ptr := self._ctrl_ptr();
|
|
212
|
+
data_ptr := self._data_ptr();
|
|
213
|
+
|
|
214
|
+
while(probe < self.capacity, probe = (probe + usize(1)), {
|
|
215
|
+
probe_index := ((index + probe) % self.capacity);
|
|
216
|
+
ctrl_byte := (ctrl_ptr &+ probe_index).*;
|
|
217
|
+
|
|
218
|
+
cond(
|
|
219
|
+
(ctrl_byte == CTRL_EMPTY) => {
|
|
220
|
+
return .None;
|
|
221
|
+
},
|
|
222
|
+
(ctrl_byte == h2) => {
|
|
223
|
+
bucket := (data_ptr &+ probe_index).*;
|
|
224
|
+
cond(
|
|
225
|
+
(bucket.key == key) => {
|
|
226
|
+
return .Some(probe_index);
|
|
227
|
+
},
|
|
228
|
+
true => ()
|
|
229
|
+
);
|
|
230
|
+
},
|
|
231
|
+
true => ()
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
.None
|
|
236
|
+
}
|
|
237
|
+
),
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Find first available bucket (EMPTY or DELETED) for insertion
|
|
241
|
+
* Returns bucket index using quadratic probing
|
|
242
|
+
*/
|
|
243
|
+
_find_insert_bucket :: (fn(self: Self, hash: u64) -> usize)(
|
|
244
|
+
{
|
|
245
|
+
index := h1_hash(hash, self.capacity);
|
|
246
|
+
probe := usize(0);
|
|
247
|
+
ctrl_ptr := self._ctrl_ptr();
|
|
248
|
+
|
|
249
|
+
while(probe < self.capacity, probe = (probe + usize(1)), {
|
|
250
|
+
probe_index := ((index + probe) % self.capacity);
|
|
251
|
+
ctrl_byte := (ctrl_ptr &+ probe_index).*;
|
|
252
|
+
|
|
253
|
+
cond(
|
|
254
|
+
((ctrl_byte == CTRL_EMPTY) || (ctrl_byte == CTRL_DELETED)) => {
|
|
255
|
+
return probe_index;
|
|
256
|
+
},
|
|
257
|
+
true => ()
|
|
258
|
+
);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
panic("HashMap is full - should have resized")
|
|
262
|
+
}
|
|
263
|
+
),
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Check if HashMap needs resizing based on load factor
|
|
267
|
+
*/
|
|
268
|
+
_needs_resize :: ((fn(self: Self) -> bool)
|
|
269
|
+
{
|
|
270
|
+
threshold := ((self.capacity * MAX_LOAD_FACTOR_NUMERATOR) / MAX_LOAD_FACTOR_DENOMINATOR);
|
|
271
|
+
(self.size >= threshold)
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Resize and rehash the HashMap to a new capacity
|
|
277
|
+
*/
|
|
278
|
+
_resize :: (fn(self: Self, new_capacity: usize) -> Result(unit, HashMapError))(
|
|
279
|
+
{
|
|
280
|
+
result := Self._alloc_with_capacity(new_capacity);
|
|
281
|
+
match(result,
|
|
282
|
+
.Err(err) => .Err(err),
|
|
283
|
+
.Ok(new_map) => {
|
|
284
|
+
i := usize(0);
|
|
285
|
+
ctrl_ptr := self._ctrl_ptr();
|
|
286
|
+
data_ptr := self._data_ptr();
|
|
287
|
+
while(i < self.capacity, i = (i + usize(1)), {
|
|
288
|
+
ctrl_byte := (ctrl_ptr &+ i).*;
|
|
289
|
+
cond(
|
|
290
|
+
((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
|
|
291
|
+
bucket := (data_ptr &+ i).*;
|
|
292
|
+
hash := (bucket.key).hash();
|
|
293
|
+
h2 := h2_hash(hash);
|
|
294
|
+
new_index := new_map._find_insert_bucket(hash);
|
|
295
|
+
|
|
296
|
+
new_ctrl_ptr := new_map._ctrl_ptr();
|
|
297
|
+
new_data_ptr := new_map._data_ptr();
|
|
298
|
+
(new_ctrl_ptr &+ new_index).* = h2;
|
|
299
|
+
consume((new_data_ptr &+ new_index).* = bucket);
|
|
300
|
+
new_map.size = (new_map.size + usize(1));
|
|
301
|
+
},
|
|
302
|
+
true => ()
|
|
303
|
+
);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
match(self.ctrl,
|
|
307
|
+
.Some(ptr) => free(.Some(*(void)(ptr))),
|
|
308
|
+
.None => ()
|
|
309
|
+
);
|
|
310
|
+
match(self.data,
|
|
311
|
+
.Some(ptr) => free(.Some(*(void)(ptr))),
|
|
312
|
+
.None => ()
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
self.ctrl = new_map.ctrl;
|
|
316
|
+
self.data = new_map.data;
|
|
317
|
+
self.capacity = new_map.capacity;
|
|
318
|
+
|
|
319
|
+
new_map.ctrl = .None;
|
|
320
|
+
new_map.data = .None;
|
|
321
|
+
|
|
322
|
+
.Ok(())
|
|
323
|
+
}
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Insert or update a key-value pair
|
|
330
|
+
* Returns Ok(Some(old_value)) if key existed, Ok(None) if new key
|
|
331
|
+
*/
|
|
332
|
+
set :: ((fn(self: Self, key: K, value: V) -> Result(Option(V), HashMapError))
|
|
333
|
+
{
|
|
334
|
+
hash := key.hash();
|
|
335
|
+
bucket_opt := self._find_bucket(key, hash);
|
|
336
|
+
|
|
337
|
+
match(bucket_opt,
|
|
338
|
+
.Some(index) => {
|
|
339
|
+
data_ptr := self._data_ptr();
|
|
340
|
+
old_bucket := (data_ptr &+ index).*;
|
|
341
|
+
old_value := old_bucket.value;
|
|
342
|
+
new_bucket := Bucket(K, V)(key: key, value: value);
|
|
343
|
+
consume((data_ptr &+ index).* = new_bucket);
|
|
344
|
+
.Ok(.Some(old_value))
|
|
345
|
+
},
|
|
346
|
+
.None => {
|
|
347
|
+
resize_check := cond(
|
|
348
|
+
(self._needs_resize()) => {
|
|
349
|
+
new_capacity := (self.capacity * usize(2));
|
|
350
|
+
self._resize(new_capacity)
|
|
351
|
+
},
|
|
352
|
+
true => (Result(unit, HashMapError).Ok(()))
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
match(resize_check,
|
|
356
|
+
.Err(err) => .Err(err),
|
|
357
|
+
.Ok(_) => {
|
|
358
|
+
h2 := h2_hash(hash);
|
|
359
|
+
index := self._find_insert_bucket(hash);
|
|
360
|
+
|
|
361
|
+
ctrl_ptr := self._ctrl_ptr();
|
|
362
|
+
data_ptr := self._data_ptr();
|
|
363
|
+
(ctrl_ptr &+ index).* = h2;
|
|
364
|
+
new_bucket := Bucket(K, V)(key: key, value: value);
|
|
365
|
+
consume((data_ptr &+ index).* = new_bucket);
|
|
366
|
+
self.size = (self.size + usize(1));
|
|
367
|
+
|
|
368
|
+
.Ok(.None)
|
|
369
|
+
}
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
)
|
|
373
|
+
}
|
|
374
|
+
),
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Get a value by key
|
|
378
|
+
* Returns Some(value) if found, None otherwise
|
|
379
|
+
*/
|
|
380
|
+
get :: ((fn(self: Self, key: K) -> Option(V))
|
|
381
|
+
{
|
|
382
|
+
hash := key.hash();
|
|
383
|
+
bucket_opt := self._find_bucket(key, hash);
|
|
384
|
+
match(bucket_opt,
|
|
385
|
+
.Some(index) => {
|
|
386
|
+
data_ptr := self._data_ptr();
|
|
387
|
+
bucket := (data_ptr &+ index).*;
|
|
388
|
+
.Some(bucket.value)
|
|
389
|
+
},
|
|
390
|
+
.None => .None
|
|
391
|
+
)
|
|
392
|
+
}
|
|
393
|
+
),
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Check if a key exists in the map
|
|
397
|
+
*/
|
|
398
|
+
has :: ((fn(self: Self, key: K) -> bool)
|
|
399
|
+
{
|
|
400
|
+
hash := key.hash();
|
|
401
|
+
bucket_opt := self._find_bucket(key, hash);
|
|
402
|
+
match(bucket_opt,
|
|
403
|
+
.Some(_) => true,
|
|
404
|
+
.None => false
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
),
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Remove a key-value pair by key
|
|
411
|
+
* Returns Some(value) if the key was found and removed, None otherwise
|
|
412
|
+
*/
|
|
413
|
+
remove :: ((fn(self: Self, key: K) -> Option(V))
|
|
414
|
+
{
|
|
415
|
+
hash := key.hash();
|
|
416
|
+
bucket_opt := self._find_bucket(key, hash);
|
|
417
|
+
match(bucket_opt,
|
|
418
|
+
.Some(index) => {
|
|
419
|
+
data_ptr := self._data_ptr();
|
|
420
|
+
ctrl_ptr := self._ctrl_ptr();
|
|
421
|
+
bucket := (data_ptr &+ index).*;
|
|
422
|
+
value := bucket.value;
|
|
423
|
+
|
|
424
|
+
(ctrl_ptr &+ index).* = CTRL_DELETED;
|
|
425
|
+
self.size = (self.size - usize(1));
|
|
426
|
+
|
|
427
|
+
.Some(value)
|
|
428
|
+
},
|
|
429
|
+
.None => .None
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
),
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Get the number of key-value pairs in the map
|
|
436
|
+
*/
|
|
437
|
+
len :: ((fn(self: Self) -> usize)
|
|
438
|
+
self.size
|
|
439
|
+
),
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Check if the map is empty
|
|
443
|
+
*/
|
|
444
|
+
is_empty :: ((fn(self: Self) -> bool)
|
|
445
|
+
(self.size == usize(0))
|
|
446
|
+
),
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Clear all key-value pairs
|
|
450
|
+
* Resets all control bytes to EMPTY
|
|
451
|
+
*/
|
|
452
|
+
clear :: ((fn(self: Self) -> unit)
|
|
453
|
+
{
|
|
454
|
+
ctrl_ptr := self._ctrl_ptr();
|
|
455
|
+
i := usize(0);
|
|
456
|
+
while(i < self.capacity, i = (i + usize(1)), {
|
|
457
|
+
(ctrl_ptr &+ i).* = CTRL_EMPTY;
|
|
458
|
+
});
|
|
459
|
+
self.size = usize(0);
|
|
460
|
+
}
|
|
461
|
+
),
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* RAII destructor - automatically called when HashMap goes out of scope
|
|
465
|
+
*/
|
|
466
|
+
dispose :: (fn(self: Self) -> unit)({
|
|
467
|
+
match(self.ctrl,
|
|
468
|
+
.Some(ptr) => free(.Some(*(void)(ptr))),
|
|
469
|
+
.None => ()
|
|
470
|
+
);
|
|
471
|
+
match(self.data,
|
|
472
|
+
.Some(ptr) => free(.Some(*(void)(ptr))),
|
|
473
|
+
.None => ()
|
|
474
|
+
);
|
|
475
|
+
})
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
export
|
|
479
|
+
HashMap,
|
|
480
|
+
HashMapError,
|
|
481
|
+
Bucket
|
|
482
|
+
;
|