@encharm/cws 4.5.2 → 4.6.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 +9 -0
- package/CLAUDE.md +81 -0
- package/README.md +10 -5
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node127.node +0 -0
- package/dist/bindings/cws_linux_arm64_node137.node +0 -0
- package/dist/bindings/cws_linux_arm64_node147.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node127.node +0 -0
- package/dist/bindings/cws_linux_x64_node137.node +0 -0
- package/dist/bindings/cws_linux_x64_node147.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node127.node +0 -0
- package/dist/bindings/cws_win32_x64_node137.node +0 -0
- package/dist/bindings/cws_win32_x64_node147.node +0 -0
- package/package.json +1 -1
- package/src/Addon.cpp +2 -1
- package/src/Addon.h +70 -14
- package/src/Hub.h +1 -0
- package/src/Networking.h +11 -0
- package/src/Socket.h +201 -6
- package/src/WebSocket.cpp +4 -1
- package/src/cSNode.cpp +2 -0
- package/src/cSNode.h +4 -0
- package/src/headers/24/tracing/agent.h +195 -0
- package/src/headers/24/tracing/trace_event.h +722 -0
- package/src/headers/26/acorn_version.h +6 -0
- package/src/headers/26/aliased_buffer-inl.h +264 -0
- package/src/headers/26/aliased_buffer.h +205 -0
- package/src/headers/26/aliased_struct-inl.h +143 -0
- package/src/headers/26/aliased_struct.h +248 -0
- package/src/headers/26/amaro_version.h +6 -0
- package/src/headers/26/async_context_frame.h +33 -0
- package/src/headers/26/async_wrap-inl.h +123 -0
- package/src/headers/26/async_wrap.h +254 -0
- package/src/headers/26/base_object-inl.h +333 -0
- package/src/headers/26/base_object.h +339 -0
- package/src/headers/26/base_object_types.h +76 -0
- package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
- package/src/headers/26/blob_serializer_deserializer.h +142 -0
- package/src/headers/26/builtin_info.h +57 -0
- package/src/headers/26/callback_queue-inl.h +97 -0
- package/src/headers/26/callback_queue.h +79 -0
- package/src/headers/26/cares_wrap.h +475 -0
- package/src/headers/26/cleanup_queue-inl.h +36 -0
- package/src/headers/26/cleanup_queue.h +79 -0
- package/src/headers/26/compile_cache.h +134 -0
- package/src/headers/26/connect_wrap.h +26 -0
- package/src/headers/26/connection_wrap.h +30 -0
- package/src/headers/26/cppgc_helpers-inl.h +69 -0
- package/src/headers/26/cppgc_helpers.h +162 -0
- package/src/headers/26/crypto/crypto_aes.h +107 -0
- package/src/headers/26/crypto/crypto_argon2.h +88 -0
- package/src/headers/26/crypto/crypto_bio.h +193 -0
- package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
- package/src/headers/26/crypto/crypto_cipher.h +291 -0
- package/src/headers/26/crypto/crypto_common.h +48 -0
- package/src/headers/26/crypto/crypto_context.h +219 -0
- package/src/headers/26/crypto/crypto_dh.h +104 -0
- package/src/headers/26/crypto/crypto_dsa.h +50 -0
- package/src/headers/26/crypto/crypto_ec.h +102 -0
- package/src/headers/26/crypto/crypto_hash.h +157 -0
- package/src/headers/26/crypto/crypto_hkdf.h +62 -0
- package/src/headers/26/crypto/crypto_hmac.h +92 -0
- package/src/headers/26/crypto/crypto_kem.h +131 -0
- package/src/headers/26/crypto/crypto_keygen.h +382 -0
- package/src/headers/26/crypto/crypto_keys.h +366 -0
- package/src/headers/26/crypto/crypto_kmac.h +79 -0
- package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
- package/src/headers/26/crypto/crypto_pqc.h +39 -0
- package/src/headers/26/crypto/crypto_random.h +127 -0
- package/src/headers/26/crypto/crypto_rsa.h +108 -0
- package/src/headers/26/crypto/crypto_scrypt.h +85 -0
- package/src/headers/26/crypto/crypto_sig.h +159 -0
- package/src/headers/26/crypto/crypto_spkac.h +21 -0
- package/src/headers/26/crypto/crypto_timing.h +20 -0
- package/src/headers/26/crypto/crypto_tls.h +342 -0
- package/src/headers/26/crypto/crypto_turboshake.h +105 -0
- package/src/headers/26/crypto/crypto_util.h +775 -0
- package/src/headers/26/crypto/crypto_x509.h +140 -0
- package/src/headers/26/dataqueue/queue.h +311 -0
- package/src/headers/26/debug_utils-inl.h +291 -0
- package/src/headers/26/debug_utils.h +200 -0
- package/src/headers/26/diagnosticfilename-inl.h +33 -0
- package/src/headers/26/embedded_data.h +17 -0
- package/src/headers/26/encoding_binding.h +59 -0
- package/src/headers/26/env-inl.h +956 -0
- package/src/headers/26/env.h +1294 -0
- package/src/headers/26/env_properties.h +562 -0
- package/src/headers/26/ffi/data.h +30 -0
- package/src/headers/26/ffi/fast.h +96 -0
- package/src/headers/26/ffi/jit_memory.h +26 -0
- package/src/headers/26/ffi/types.h +99 -0
- package/src/headers/26/handle_wrap.h +123 -0
- package/src/headers/26/histogram-inl.h +211 -0
- package/src/headers/26/histogram.h +474 -0
- package/src/headers/26/inspector/dom_storage_agent.h +68 -0
- package/src/headers/26/inspector/inspector_object_utils.h +38 -0
- package/src/headers/26/inspector/io_agent.h +30 -0
- package/src/headers/26/inspector/main_thread_interface.h +116 -0
- package/src/headers/26/inspector/network_agent.h +110 -0
- package/src/headers/26/inspector/network_inspector.h +45 -0
- package/src/headers/26/inspector/network_requests_buffer.h +195 -0
- package/src/headers/26/inspector/network_resource_manager.h +29 -0
- package/src/headers/26/inspector/node_json.h +24 -0
- package/src/headers/26/inspector/node_string.h +101 -0
- package/src/headers/26/inspector/notification_emitter.h +38 -0
- package/src/headers/26/inspector/protocol_helper.h +27 -0
- package/src/headers/26/inspector/runtime_agent.h +41 -0
- package/src/headers/26/inspector/storage_agent.h +33 -0
- package/src/headers/26/inspector/target_agent.h +59 -0
- package/src/headers/26/inspector/target_manager.h +70 -0
- package/src/headers/26/inspector/tracing_agent.h +43 -0
- package/src/headers/26/inspector/worker_agent.h +40 -0
- package/src/headers/26/inspector/worker_inspector.h +124 -0
- package/src/headers/26/inspector_agent.h +168 -0
- package/src/headers/26/inspector_io.h +78 -0
- package/src/headers/26/inspector_profiler.h +149 -0
- package/src/headers/26/inspector_socket.h +60 -0
- package/src/headers/26/inspector_socket_server.h +110 -0
- package/src/headers/26/js_native_api.h +634 -0
- package/src/headers/26/js_native_api_types.h +244 -0
- package/src/headers/26/js_native_api_v8.h +485 -0
- package/src/headers/26/js_native_api_v8_internals.h +45 -0
- package/src/headers/26/js_stream.h +57 -0
- package/src/headers/26/json_utils.h +172 -0
- package/src/headers/26/large_pages/node_large_page.h +34 -0
- package/src/headers/26/lru_cache-inl.h +69 -0
- package/src/headers/26/memory_tracker-inl.h +461 -0
- package/src/headers/26/memory_tracker.h +341 -0
- package/src/headers/26/module_wrap.h +231 -0
- package/src/headers/26/ncrypto.h +2008 -0
- package/src/headers/26/node.h +1693 -0
- package/src/headers/26/node_api.h +265 -0
- package/src/headers/26/node_api_internals.h +48 -0
- package/src/headers/26/node_api_types.h +58 -0
- package/src/headers/26/node_binding.h +170 -0
- package/src/headers/26/node_blob.h +160 -0
- package/src/headers/26/node_bob-inl.h +36 -0
- package/src/headers/26/node_bob.h +107 -0
- package/src/headers/26/node_buffer.h +92 -0
- package/src/headers/26/node_builtins.h +239 -0
- package/src/headers/26/node_concepts.h +46 -0
- package/src/headers/26/node_config_file.h +77 -0
- package/src/headers/26/node_constants.h +82 -0
- package/src/headers/26/node_context_data.h +171 -0
- package/src/headers/26/node_contextify.h +261 -0
- package/src/headers/26/node_crypto.h +66 -0
- package/src/headers/26/node_debug.h +30 -0
- package/src/headers/26/node_diagnostics_channel.h +121 -0
- package/src/headers/26/node_dir.h +52 -0
- package/src/headers/26/node_dotenv.h +45 -0
- package/src/headers/26/node_errors.h +378 -0
- package/src/headers/26/node_exit_code.h +54 -0
- package/src/headers/26/node_external_reference.h +171 -0
- package/src/headers/26/node_ffi.h +212 -0
- package/src/headers/26/node_file-inl.h +421 -0
- package/src/headers/26/node_file.h +561 -0
- package/src/headers/26/node_file_utils.h +39 -0
- package/src/headers/26/node_hash.h +212 -0
- package/src/headers/26/node_http2.h +1202 -0
- package/src/headers/26/node_http2_state.h +159 -0
- package/src/headers/26/node_http_common-inl.h +199 -0
- package/src/headers/26/node_http_common.h +535 -0
- package/src/headers/26/node_i18n.h +132 -0
- package/src/headers/26/node_internals.h +485 -0
- package/src/headers/26/node_locks.h +184 -0
- package/src/headers/26/node_main_instance.h +67 -0
- package/src/headers/26/node_mem-inl.h +113 -0
- package/src/headers/26/node_mem.h +45 -0
- package/src/headers/26/node_messaging.h +389 -0
- package/src/headers/26/node_metadata.h +172 -0
- package/src/headers/26/node_modules.h +102 -0
- package/src/headers/26/node_mutex.h +323 -0
- package/src/headers/26/node_object_wrap.h +145 -0
- package/src/headers/26/node_options-inl.h +524 -0
- package/src/headers/26/node_options.h +710 -0
- package/src/headers/26/node_perf.h +167 -0
- package/src/headers/26/node_perf_common.h +103 -0
- package/src/headers/26/node_platform.h +290 -0
- package/src/headers/26/node_process-inl.h +26 -0
- package/src/headers/26/node_process.h +112 -0
- package/src/headers/26/node_profiling.h +38 -0
- package/src/headers/26/node_realm-inl.h +156 -0
- package/src/headers/26/node_realm.h +236 -0
- package/src/headers/26/node_report.h +43 -0
- package/src/headers/26/node_revert.h +82 -0
- package/src/headers/26/node_root_certs.h +2937 -0
- package/src/headers/26/node_sea.h +101 -0
- package/src/headers/26/node_shadow_realm.h +46 -0
- package/src/headers/26/node_snapshot_builder.h +57 -0
- package/src/headers/26/node_snapshotable.h +167 -0
- package/src/headers/26/node_sockaddr-inl.h +248 -0
- package/src/headers/26/node_sockaddr.h +459 -0
- package/src/headers/26/node_sqlite.h +607 -0
- package/src/headers/26/node_stat_watcher.h +73 -0
- package/src/headers/26/node_task_runner.h +92 -0
- package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/26/node_threadsafe_cow.h +105 -0
- package/src/headers/26/node_union_bytes.h +81 -0
- package/src/headers/26/node_url.h +101 -0
- package/src/headers/26/node_url_pattern.h +118 -0
- package/src/headers/26/node_v8.h +78 -0
- package/src/headers/26/node_v8_embedder.h +26 -0
- package/src/headers/26/node_v8_platform-inl.h +96 -0
- package/src/headers/26/node_version.h +116 -0
- package/src/headers/26/node_wasi.h +184 -0
- package/src/headers/26/node_wasm_web_api.h +55 -0
- package/src/headers/26/node_watchdog.h +164 -0
- package/src/headers/26/node_webstorage.h +62 -0
- package/src/headers/26/node_worker.h +162 -0
- package/src/headers/26/path.h +36 -0
- package/src/headers/26/permission/boolean_permission.h +50 -0
- package/src/headers/26/permission/fs_permission.h +192 -0
- package/src/headers/26/permission/permission.h +155 -0
- package/src/headers/26/permission/permission_base.h +79 -0
- package/src/headers/26/pipe_wrap.h +80 -0
- package/src/headers/26/quic/application.h +279 -0
- package/src/headers/26/quic/arena.h +373 -0
- package/src/headers/26/quic/bindingdata.h +440 -0
- package/src/headers/26/quic/cid.h +127 -0
- package/src/headers/26/quic/data.h +358 -0
- package/src/headers/26/quic/defs.h +417 -0
- package/src/headers/26/quic/endpoint.h +519 -0
- package/src/headers/26/quic/guard.h +5 -0
- package/src/headers/26/quic/http3.h +25 -0
- package/src/headers/26/quic/packet.h +166 -0
- package/src/headers/26/quic/preferredaddress.h +72 -0
- package/src/headers/26/quic/session.h +770 -0
- package/src/headers/26/quic/session_manager.h +107 -0
- package/src/headers/26/quic/sessionticket.h +110 -0
- package/src/headers/26/quic/streams.h +518 -0
- package/src/headers/26/quic/tlscontext.h +353 -0
- package/src/headers/26/quic/tokens.h +263 -0
- package/src/headers/26/quic/transportparams.h +184 -0
- package/src/headers/26/req_wrap-inl.h +175 -0
- package/src/headers/26/req_wrap.h +79 -0
- package/src/headers/26/spawn_sync.h +243 -0
- package/src/headers/26/stream_base-inl.h +170 -0
- package/src/headers/26/stream_base.h +487 -0
- package/src/headers/26/stream_pipe.h +76 -0
- package/src/headers/26/stream_wrap.h +137 -0
- package/src/headers/26/string_bytes.h +114 -0
- package/src/headers/26/string_decoder-inl.h +31 -0
- package/src/headers/26/string_decoder.h +49 -0
- package/src/headers/26/tcp_wrap.h +138 -0
- package/src/headers/26/threadpoolwork-inl.h +70 -0
- package/src/headers/26/timer_wrap-inl.h +32 -0
- package/src/headers/26/timer_wrap.h +87 -0
- package/src/headers/26/timers.h +70 -0
- package/src/headers/26/tracing/agent.h +125 -0
- package/src/headers/26/tracing/agent_legacy.h +146 -0
- package/src/headers/26/tracing/agent_perfetto.h +145 -0
- package/src/headers/26/tracing/node_trace_buffer.h +91 -0
- package/src/headers/26/tracing/node_trace_writer.h +79 -0
- package/src/headers/26/tracing/trace_event.h +27 -0
- package/src/headers/26/tracing/trace_event_helper.h +40 -0
- package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
- package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
- package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
- package/src/headers/26/tracing/traced_value.h +167 -0
- package/src/headers/26/tty_wrap.h +65 -0
- package/src/headers/26/udp_wrap.h +231 -0
- package/src/headers/26/undici_version.h +6 -0
- package/src/headers/26/util-inl.h +788 -0
- package/src/headers/26/util.h +1207 -0
- package/src/headers/26/v8-cpp-heap-external.h +56 -0
- package/src/headers/26/v8-external-memory-accounter.h +60 -0
- package/src/headers/26/v8-fast-api-calls.h +784 -0
- package/src/headers/26/v8-inspector-protocol.h +13 -0
- package/src/headers/26/v8-inspector.h +458 -0
- package/src/headers/26/v8-metrics.h +273 -0
- package/src/headers/26/v8-trace-categories.h +28 -0
- package/src/headers/26/v8-unwinder-state.h +30 -0
- package/src/headers/26/v8-util.h +549 -0
- package/src/headers/26/v8-value-serializer-version.h +24 -0
- package/src/headers/26/v8-version-string.h +38 -0
- package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
- package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
- package/src/headers/26/zlib_version.h +6 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
4
|
+
|
|
5
|
+
// Fast, high-quality hash function for byte sequences.
|
|
6
|
+
//
|
|
7
|
+
// Provides HashBytes() for use in hash tables. Uses native-width integer
|
|
8
|
+
// loads and a 128-bit multiply-and-fold mixer for excellent avalanche
|
|
9
|
+
// properties on short byte sequences (network identifiers, addresses,
|
|
10
|
+
// tokens).
|
|
11
|
+
//
|
|
12
|
+
// Based on rapidhash V3 by Nicolas De Carli, which evolved from wyhash
|
|
13
|
+
// by Wang Yi. Both use the same core mixing primitive (MUM: multiply,
|
|
14
|
+
// then XOR the high and low halves of the 128-bit result).
|
|
15
|
+
//
|
|
16
|
+
// rapidhash: https://github.com/Nicoshev/rapidhash
|
|
17
|
+
// Copyright (C) 2025 Nicolas De Carli — MIT License
|
|
18
|
+
// wyhash: https://github.com/wangyi-fudan/wyhash
|
|
19
|
+
// Wang Yi — public domain (The Unlicense)
|
|
20
|
+
//
|
|
21
|
+
// The implementation here uses rapidhash's read strategy (native-width
|
|
22
|
+
// overlapping reads, optimized for short inputs) and secret constants.
|
|
23
|
+
// The core mixing function (rapid_mum/rapid_mix) is identical to
|
|
24
|
+
// wyhash's wymum/wymix.
|
|
25
|
+
|
|
26
|
+
#include <cstddef>
|
|
27
|
+
#include <cstdint>
|
|
28
|
+
#include <cstring>
|
|
29
|
+
|
|
30
|
+
#if defined(_MSC_VER)
|
|
31
|
+
#include <intrin.h>
|
|
32
|
+
#if defined(_M_X64) && !defined(_M_ARM64EC)
|
|
33
|
+
#pragma intrinsic(_umul128)
|
|
34
|
+
#endif
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
namespace node {
|
|
38
|
+
|
|
39
|
+
namespace hash_detail {
|
|
40
|
+
|
|
41
|
+
// 128-bit multiply, then XOR the high and low halves.
|
|
42
|
+
// This is the core mixing function ("rapid_mum" / "wymum").
|
|
43
|
+
// On 64-bit platforms with __int128, this compiles to a single
|
|
44
|
+
// mul instruction + shift + xor.
|
|
45
|
+
inline uint64_t RapidMix(uint64_t a, uint64_t b) {
|
|
46
|
+
#ifdef __SIZEOF_INT128__
|
|
47
|
+
__uint128_t r = static_cast<__uint128_t>(a) * b;
|
|
48
|
+
a = static_cast<uint64_t>(r);
|
|
49
|
+
b = static_cast<uint64_t>(r >> 64);
|
|
50
|
+
#elif defined(_MSC_VER) && (defined(_WIN64) || defined(_M_HYBRID_CHPE_ARM64))
|
|
51
|
+
#if defined(_M_X64)
|
|
52
|
+
a = _umul128(a, b, &b);
|
|
53
|
+
#else
|
|
54
|
+
uint64_t hi = __umulh(a, b);
|
|
55
|
+
a = a * b;
|
|
56
|
+
b = hi;
|
|
57
|
+
#endif
|
|
58
|
+
#else
|
|
59
|
+
// Portable 64x64 -> 128-bit multiply fallback for 32-bit platforms.
|
|
60
|
+
uint64_t ha = a >> 32, hb = b >> 32;
|
|
61
|
+
uint64_t la = static_cast<uint32_t>(a), lb = static_cast<uint32_t>(b);
|
|
62
|
+
uint64_t rh = ha * hb, rm0 = ha * lb, rm1 = hb * la, rl = la * lb;
|
|
63
|
+
uint64_t t = rl + (rm0 << 32);
|
|
64
|
+
uint64_t lo = t + (rm1 << 32);
|
|
65
|
+
uint64_t hi = rh + (rm0 >> 32) + (rm1 >> 32) + (t < rl) + (lo < t);
|
|
66
|
+
a = lo;
|
|
67
|
+
b = hi;
|
|
68
|
+
#endif
|
|
69
|
+
return a ^ b;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Inline 128-bit multiply WITHOUT the final XOR (used in the
|
|
73
|
+
// penultimate mixing step where a and b are updated separately).
|
|
74
|
+
inline void RapidMum(uint64_t* a, uint64_t* b) {
|
|
75
|
+
#ifdef __SIZEOF_INT128__
|
|
76
|
+
__uint128_t r = static_cast<__uint128_t>(*a) * (*b);
|
|
77
|
+
*a = static_cast<uint64_t>(r);
|
|
78
|
+
*b = static_cast<uint64_t>(r >> 64);
|
|
79
|
+
#elif defined(_MSC_VER) && (defined(_WIN64) || defined(_M_HYBRID_CHPE_ARM64))
|
|
80
|
+
#if defined(_M_X64)
|
|
81
|
+
*a = _umul128(*a, *b, b);
|
|
82
|
+
#else
|
|
83
|
+
uint64_t hi = __umulh(*a, *b);
|
|
84
|
+
*a = (*a) * (*b);
|
|
85
|
+
*b = hi;
|
|
86
|
+
#endif
|
|
87
|
+
#else
|
|
88
|
+
uint64_t ha = *a >> 32, hb = *b >> 32;
|
|
89
|
+
uint64_t la = static_cast<uint32_t>(*a), lb = static_cast<uint32_t>(*b);
|
|
90
|
+
uint64_t rh = ha * hb, rm0 = ha * lb, rm1 = hb * la, rl = la * lb;
|
|
91
|
+
uint64_t t = rl + (rm0 << 32);
|
|
92
|
+
*a = t + (rm1 << 32);
|
|
93
|
+
*b = rh + (rm0 >> 32) + (rm1 >> 32) + (t < rl) + (*a < t);
|
|
94
|
+
#endif
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Read functions. The compiler optimizes small fixed-size memcpy calls
|
|
98
|
+
// to single load instructions — no actual byte-by-byte copy occurs.
|
|
99
|
+
inline uint64_t RapidRead64(const uint8_t* p) {
|
|
100
|
+
uint64_t v;
|
|
101
|
+
memcpy(&v, p, sizeof(uint64_t));
|
|
102
|
+
return v;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
inline uint64_t RapidRead32(const uint8_t* p) {
|
|
106
|
+
uint32_t v;
|
|
107
|
+
memcpy(&v, p, sizeof(uint32_t));
|
|
108
|
+
return v;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Default rapidhash secret parameters.
|
|
112
|
+
constexpr uint64_t kSecret[8] = {0x2d358dccaa6c78a5ULL,
|
|
113
|
+
0x8bb84b93962eacc9ULL,
|
|
114
|
+
0x4b33a62ed433d4a3ULL,
|
|
115
|
+
0x4d5a2da51de1aa47ULL,
|
|
116
|
+
0xa0761d6478bd642fULL,
|
|
117
|
+
0xe7037ed1a0b428dbULL,
|
|
118
|
+
0x90ed1765281c388cULL,
|
|
119
|
+
0xaaaaaaaaaaaaaaaaULL};
|
|
120
|
+
|
|
121
|
+
} // namespace hash_detail
|
|
122
|
+
|
|
123
|
+
// Hash a contiguous byte range. Optimized for short inputs (≤48 bytes)
|
|
124
|
+
// which is the common case for network identifiers and addresses. For
|
|
125
|
+
// inputs >48 bytes, falls through to a loop processing 48-byte chunks.
|
|
126
|
+
inline size_t HashBytes(const void* data, size_t len) {
|
|
127
|
+
const uint8_t* p = static_cast<const uint8_t*>(data);
|
|
128
|
+
|
|
129
|
+
// Seed initialization.
|
|
130
|
+
uint64_t seed = hash_detail::RapidMix(0 ^ hash_detail::kSecret[2],
|
|
131
|
+
hash_detail::kSecret[1]);
|
|
132
|
+
uint64_t a = 0;
|
|
133
|
+
uint64_t b = 0;
|
|
134
|
+
size_t i = len;
|
|
135
|
+
|
|
136
|
+
if (len <= 16) {
|
|
137
|
+
if (len >= 4) {
|
|
138
|
+
// Mix length into seed for better distribution of
|
|
139
|
+
// different-length inputs with shared prefixes.
|
|
140
|
+
seed ^= len;
|
|
141
|
+
if (len >= 8) {
|
|
142
|
+
// 8-16 bytes: two native 64-bit reads (overlapping from end).
|
|
143
|
+
a = hash_detail::RapidRead64(p);
|
|
144
|
+
b = hash_detail::RapidRead64(p + len - 8);
|
|
145
|
+
} else {
|
|
146
|
+
// 4-7 bytes: two 32-bit reads (overlapping from end).
|
|
147
|
+
a = hash_detail::RapidRead32(p);
|
|
148
|
+
b = hash_detail::RapidRead32(p + len - 4);
|
|
149
|
+
}
|
|
150
|
+
} else if (len > 0) {
|
|
151
|
+
// 1-3 bytes: spread bytes across two values for mixing.
|
|
152
|
+
a = (static_cast<uint64_t>(p[0]) << 45) | p[len - 1];
|
|
153
|
+
b = p[len >> 1];
|
|
154
|
+
} else {
|
|
155
|
+
a = b = 0;
|
|
156
|
+
}
|
|
157
|
+
} else if (len <= 48) {
|
|
158
|
+
// 17-48 bytes: process in 16-byte chunks, then read the tail.
|
|
159
|
+
seed = hash_detail::RapidMix(
|
|
160
|
+
hash_detail::RapidRead64(p) ^ hash_detail::kSecret[2],
|
|
161
|
+
hash_detail::RapidRead64(p + 8) ^ seed);
|
|
162
|
+
if (len > 32) {
|
|
163
|
+
seed = hash_detail::RapidMix(
|
|
164
|
+
hash_detail::RapidRead64(p + 16) ^ hash_detail::kSecret[2],
|
|
165
|
+
hash_detail::RapidRead64(p + 24) ^ seed);
|
|
166
|
+
}
|
|
167
|
+
a = hash_detail::RapidRead64(p + len - 16) ^ len;
|
|
168
|
+
b = hash_detail::RapidRead64(p + len - 8);
|
|
169
|
+
} else {
|
|
170
|
+
// >48 bytes: process 48-byte chunks with three parallel mix lanes.
|
|
171
|
+
uint64_t see1 = seed;
|
|
172
|
+
uint64_t see2 = seed;
|
|
173
|
+
do {
|
|
174
|
+
seed = hash_detail::RapidMix(
|
|
175
|
+
hash_detail::RapidRead64(p) ^ hash_detail::kSecret[0],
|
|
176
|
+
hash_detail::RapidRead64(p + 8) ^ seed);
|
|
177
|
+
see1 = hash_detail::RapidMix(
|
|
178
|
+
hash_detail::RapidRead64(p + 16) ^ hash_detail::kSecret[1],
|
|
179
|
+
hash_detail::RapidRead64(p + 24) ^ see1);
|
|
180
|
+
see2 = hash_detail::RapidMix(
|
|
181
|
+
hash_detail::RapidRead64(p + 32) ^ hash_detail::kSecret[2],
|
|
182
|
+
hash_detail::RapidRead64(p + 40) ^ see2);
|
|
183
|
+
p += 48;
|
|
184
|
+
i -= 48;
|
|
185
|
+
} while (i > 48);
|
|
186
|
+
seed ^= see1 ^ see2;
|
|
187
|
+
// Process remaining 17-48 bytes.
|
|
188
|
+
if (i > 16) {
|
|
189
|
+
seed = hash_detail::RapidMix(
|
|
190
|
+
hash_detail::RapidRead64(p) ^ hash_detail::kSecret[2],
|
|
191
|
+
hash_detail::RapidRead64(p + 8) ^ seed);
|
|
192
|
+
if (i > 32) {
|
|
193
|
+
seed = hash_detail::RapidMix(
|
|
194
|
+
hash_detail::RapidRead64(p + 16) ^ hash_detail::kSecret[2],
|
|
195
|
+
hash_detail::RapidRead64(p + 24) ^ seed);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
a = hash_detail::RapidRead64(p + i - 16) ^ i;
|
|
199
|
+
b = hash_detail::RapidRead64(p + i - 8);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Final mix.
|
|
203
|
+
a ^= hash_detail::kSecret[1];
|
|
204
|
+
b ^= seed;
|
|
205
|
+
hash_detail::RapidMum(&a, &b);
|
|
206
|
+
return static_cast<size_t>(hash_detail::RapidMix(
|
|
207
|
+
a ^ hash_detail::kSecret[7], b ^ hash_detail::kSecret[1] ^ len));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
} // namespace node
|
|
211
|
+
|
|
212
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|