react-native-xxhash 0.1.5 → 0.1.7

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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # react-native-xxhash
2
2
 
3
- A React Native library for hashing strings using the fast and deterministic xxHash algorithm. This library provides support for both 64-bit and 128-bit hashing.
3
+ A React Native library for hashing strings using the fast and deterministic xxHash algorithm, written in C++ with JSI for high performance. This library provides support for both 64-bit and 128-bit hashing.
4
+
4
5
 
5
6
  ## Features
6
7
 
@@ -8,16 +8,16 @@ void xxhash::install(jsi::Runtime* rt_ptr) {
8
8
  [](jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args,
9
9
  size_t count) {
10
10
  const jsi::Value& arg = args[0];
11
-
11
+
12
12
  if (!arg.isString()) [[unlikely]] {
13
13
  throw jsi::JSError(rt, "Argument is not a 'string'");
14
14
  }
15
15
 
16
- std::stringstream ss;
16
+ char result[33];
17
17
 
18
- xxhash::make_hash<HashSize::BITS_128>(arg.asString(rt).utf8(rt), ss);
18
+ xxhash::make_hash_128(arg.asString(rt).utf8(rt), result);
19
19
 
20
- return jsi::String::createFromUtf8(rt, ss.str());
20
+ return jsi::String::createFromUtf8(rt, result);
21
21
  });
22
22
 
23
23
  jsi::Function hash64 = jsi::Function::createFromHostFunction(
@@ -30,11 +30,11 @@ void xxhash::install(jsi::Runtime* rt_ptr) {
30
30
  throw jsi::JSError(rt, "Argument is not a 'string'");
31
31
  }
32
32
 
33
- std::stringstream ss;
33
+ char result[17];
34
34
 
35
- xxhash::make_hash<HashSize::BITS_64>(arg.asString(rt).utf8(rt), ss);
35
+ xxhash::make_hash_64(arg.asString(rt).utf8(rt), result);
36
36
 
37
- return jsi::String::createFromUtf8(rt, ss.str());
37
+ return jsi::String::createFromUtf8(rt, result);
38
38
  });
39
39
 
40
40
  runtime.global().setProperty(runtime, "__xxhash128", std::move(hash128));
@@ -2,42 +2,26 @@
2
2
  #ifndef XXHASH_H
3
3
  #define XXHASH_H
4
4
  #include <jsi/jsi.h>
5
- #include "xxhash.h"
6
5
  #include <iomanip>
7
6
  #include <sstream>
7
+ #include "xxhash.h"
8
8
 
9
9
  using namespace facebook;
10
10
 
11
11
  namespace xxhash {
12
- enum class HashSize {
13
- BITS_64,
14
- BITS_128,
15
- };
16
-
17
- template <HashSize T>
18
- inline void make_hash(const std::string_view str, std::stringstream& ss) noexcept;
19
-
20
- template <>
21
- inline void make_hash<HashSize::BITS_64>(const std::string_view str,
22
- std::stringstream& ss) noexcept {
23
- XXH64_hash_t hash = XXH3_64bits(str.data(), str.size());
24
-
25
- ss << std::hex << std::setfill('0') << std::setw(16) << hash;
26
- };
27
-
28
- template <>
29
- inline void make_hash<HashSize::BITS_128>(const std::string_view str,
30
- std::stringstream& ss) noexcept {
31
- XXH128_hash_t hash = XXH3_128bits(str.data(), str.size());
32
-
33
- ss << std::hex << std::setfill('0') << std::setw(16) << hash.high64
34
- << std::setw(16) << hash.low64;
35
- };
36
-
37
- void install(jsi::Runtime* rt);
38
- }
39
12
 
13
+ inline void make_hash_64(const std::string_view str, char result[17]) noexcept {
14
+ XXH64_hash_t hash = XXH3_64bits(str.data(), str.size());
15
+ std::snprintf(result, 17, "%016llx", hash);
16
+ };
40
17
 
18
+ inline void make_hash_128(const std::string_view str,
19
+ char result[33]) noexcept {
20
+ XXH128_hash_t hash = XXH3_128bits(str.data(), str.size());
21
+ std::snprintf(result, 33, "%016llx%016llx", hash.high64, hash.low64);
22
+ };
41
23
 
24
+ void install(jsi::Runtime* rt);
25
+ } // namespace xxhash
42
26
 
43
27
  #endif /* XXHASH_H */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-xxhash",
3
- "version": "0.1.5",
4
- "description": "Fast xxHash implementation for React Native",
3
+ "version": "0.1.7",
4
+ "description": "💪 A high-performance React Native library for generating xxHash hashes using C++ and JSI",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
7
7
  "types": "lib/typescript/index.d.ts",
@@ -41,7 +41,25 @@
41
41
  "android",
42
42
  "xxhash",
43
43
  "hash",
44
- "fast"
44
+ "fast",
45
+ "xxhash3",
46
+ "react-native-xxhash",
47
+ "react-native-xxhash3",
48
+ "xxhash3-react-native",
49
+ "react-native-hash",
50
+ "hash-react-native",
51
+ "hash-xxhash",
52
+ "jsi",
53
+ "cpp",
54
+ "react-native-jsi",
55
+ "fast-hash",
56
+ "quick-hash",
57
+ "react-native-quick-hash",
58
+ "react-native-fast-hash",
59
+ "react-native-xxhash-jsi",
60
+ "react-native-xxhash-cpp",
61
+ "react-native-xxhash3-jsi",
62
+ "react-native-xxhash3-cpp"
45
63
  ],
46
64
  "repository": {
47
65
  "type": "git",