usearch 2.9.1 → 2.10.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.
Files changed (169) hide show
  1. package/README.md +50 -52
  2. package/javascript/{types → dist/cjs}/usearch.d.ts +90 -115
  3. package/javascript/dist/cjs/usearch.js +531 -0
  4. package/javascript/dist/esm/usearch.d.ts +212 -0
  5. package/javascript/{usearch.js → dist/esm/usearch.js} +202 -153
  6. package/package.json +25 -23
  7. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  8. package/prebuilds/linux-arm64/usearch.node +0 -0
  9. package/prebuilds/linux-x64/usearch.node +0 -0
  10. package/prebuilds/win32-ia32/usearch.node +0 -0
  11. package/prebuilds/win32-x64/usearch.node +0 -0
  12. package/.clang-format +0 -10
  13. package/.clang-tidy +0 -60
  14. package/.cmake-format.py +0 -19
  15. package/.dockerignore +0 -93
  16. package/.gitattributes +0 -9
  17. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  18. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  19. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -64
  20. package/.github/workflows/Dockerfile.libs +0 -36
  21. package/.github/workflows/prerelease.yml +0 -331
  22. package/.github/workflows/release.yml +0 -722
  23. package/.github/workflows/update_version.sh +0 -15
  24. package/.gitmodules +0 -9
  25. package/.releaserc +0 -90
  26. package/CITATION.cff +0 -11
  27. package/CMakeLists.txt +0 -324
  28. package/CODE_OF_CONDUCT.md +0 -128
  29. package/CONTRIBUTING.md +0 -353
  30. package/Cargo.toml +0 -19
  31. package/Dockerfile +0 -16
  32. package/VERSION +0 -1
  33. package/assets/unum.png +0 -0
  34. package/assets/usearch-approaches-transparent.png +0 -0
  35. package/assets/usearch-approaches-white.png +0 -0
  36. package/assets/usearch-neighbor-types.png +0 -0
  37. package/binding.gyp +0 -87
  38. package/build.gradle +0 -204
  39. package/build.rs +0 -18
  40. package/c/CMakeLists.txt +0 -25
  41. package/c/README.md +0 -34
  42. package/c/lib.cpp +0 -358
  43. package/c/test.c +0 -374
  44. package/c/usearch.h +0 -311
  45. package/cmake/clipp.cmake +0 -7
  46. package/cmake/config.cmake.in +0 -15
  47. package/cmake/emscripten.cmake +0 -8
  48. package/cmake/jemalloc.cmake +0 -62
  49. package/cmake/pkg-config.pc.in +0 -4
  50. package/cmake/usearchConfigVersion.cmake.in +0 -20
  51. package/conanfile.py +0 -26
  52. package/cpp/CMakeLists.txt +0 -14
  53. package/cpp/README.md +0 -161
  54. package/cpp/bench.cpp +0 -618
  55. package/cpp/test.cpp +0 -323
  56. package/fp16/CMakeLists.txt +0 -176
  57. package/fp16/LICENSE +0 -11
  58. package/fp16/README.md +0 -20
  59. package/fp16/bench/alt-element.cc +0 -89
  60. package/fp16/bench/from-alt-array.cc +0 -175
  61. package/fp16/bench/from-ieee-array.cc +0 -399
  62. package/fp16/bench/ieee-element.cc +0 -272
  63. package/fp16/bench/to-alt-array.cc +0 -91
  64. package/fp16/bench/to-ieee-array.cc +0 -303
  65. package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
  66. package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
  67. package/fp16/cmake/DownloadPSimd.cmake +0 -15
  68. package/fp16/configure.py +0 -65
  69. package/fp16/confu.yaml +0 -8
  70. package/fp16/include/fp16/__init__.py +0 -0
  71. package/fp16/include/fp16/avx.py +0 -50
  72. package/fp16/include/fp16/avx2.py +0 -53
  73. package/fp16/include/fp16/bitcasts.h +0 -92
  74. package/fp16/include/fp16/fp16.h +0 -451
  75. package/fp16/include/fp16/psimd.h +0 -131
  76. package/fp16/include/fp16.h +0 -11
  77. package/fp16/jni/Android.mk +0 -6
  78. package/fp16/jni/Application.mk +0 -4
  79. package/fp16/test/alt-from-fp32-value.cc +0 -498
  80. package/fp16/test/alt-to-fp32-bits.cc +0 -263
  81. package/fp16/test/alt-to-fp32-psimd.cc +0 -145
  82. package/fp16/test/alt-to-fp32-value.cc +0 -348
  83. package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
  84. package/fp16/test/bitcasts.cc +0 -56
  85. package/fp16/test/ieee-from-fp32-value.cc +0 -523
  86. package/fp16/test/ieee-to-fp32-bits.cc +0 -333
  87. package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
  88. package/fp16/test/ieee-to-fp32-value.cc +0 -420
  89. package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
  90. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
  91. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
  92. package/fp16/test/peachpy/stubs.py +0 -38
  93. package/fp16/test/tables.cc +0 -530
  94. package/fp16/test/tables.h +0 -13
  95. package/fp16/third-party/THHalf.h +0 -92
  96. package/fp16/third-party/eigen-half.h +0 -170
  97. package/fp16/third-party/float16-compressor.h +0 -80
  98. package/fp16/third-party/half.hpp +0 -2916
  99. package/fp16/third-party/npy-halffloat.h +0 -328
  100. package/include/usearch/index.hpp +0 -3836
  101. package/include/usearch/index_dense.hpp +0 -2004
  102. package/include/usearch/index_plugins.hpp +0 -2203
  103. package/javascript/lib.cpp +0 -341
  104. package/javascript/types/usearch.d.ts.map +0 -1
  105. package/javascript/usearch.test.js +0 -74
  106. package/package-ci.json +0 -10
  107. package/pyproject.toml +0 -51
  108. package/setup.py +0 -201
  109. package/simsimd/.releaserc +0 -86
  110. package/simsimd/Cargo.lock +0 -708
  111. package/simsimd/Cargo.toml +0 -36
  112. package/simsimd/LICENSE +0 -201
  113. package/simsimd/README.md +0 -275
  114. package/simsimd/binding.gyp +0 -36
  115. package/simsimd/build.rs +0 -20
  116. package/simsimd/include/simsimd/binary.h +0 -201
  117. package/simsimd/include/simsimd/probability.h +0 -548
  118. package/simsimd/include/simsimd/simsimd.h +0 -456
  119. package/simsimd/include/simsimd/spatial.h +0 -1175
  120. package/simsimd/include/simsimd/types.h +0 -207
  121. package/simsimd/javascript/bench.js +0 -127
  122. package/simsimd/javascript/fallback.ts +0 -193
  123. package/simsimd/javascript/lib.c +0 -102
  124. package/simsimd/javascript/node-gyp-build.d.ts +0 -1
  125. package/simsimd/javascript/simsimd.ts +0 -124
  126. package/simsimd/javascript/test.mjs +0 -153
  127. package/simsimd/javascript/tsconfig-base.json +0 -25
  128. package/simsimd/javascript/tsconfig-cjs.json +0 -8
  129. package/simsimd/javascript/tsconfig-esm.json +0 -8
  130. package/simsimd/package-lock.json +0 -1688
  131. package/simsimd/package.json +0 -61
  132. package/simsimd/rust/benches/cosine.rs +0 -27
  133. package/simsimd/rust/benches/native.rs +0 -27
  134. package/simsimd/rust/benches/sqeuclidean.rs +0 -27
  135. package/simsimd/rust/lib.c +0 -68
  136. package/simsimd/rust/lib.rs +0 -232
  137. package/sqlite/README.md +0 -178
  138. package/sqlite/lib.cpp +0 -325
  139. package/stringzilla/CONTRIBUTING.md +0 -429
  140. package/stringzilla/Cargo.lock +0 -25
  141. package/stringzilla/Cargo.toml +0 -26
  142. package/stringzilla/LICENSE +0 -201
  143. package/stringzilla/README.md +0 -1281
  144. package/stringzilla/VERSION +0 -1
  145. package/stringzilla/assets/cover-strinzilla.jpeg +0 -0
  146. package/stringzilla/assets/meme-stringzilla-v2.jpeg +0 -0
  147. package/stringzilla/assets/meme-stringzilla-v3.jpeg +0 -0
  148. package/stringzilla/binding.gyp +0 -16
  149. package/stringzilla/build.rs +0 -14
  150. package/stringzilla/c/lib.c +0 -304
  151. package/stringzilla/cli/README.md +0 -48
  152. package/stringzilla/cli/split.py +0 -72
  153. package/stringzilla/cli/wc.py +0 -37
  154. package/stringzilla/include/stringzilla/experimental.h +0 -724
  155. package/stringzilla/include/stringzilla/module.modulemap +0 -9
  156. package/stringzilla/include/stringzilla/stringzilla.h +0 -5240
  157. package/stringzilla/include/stringzilla/stringzilla.hpp +0 -3830
  158. package/stringzilla/javascript/lib.c +0 -125
  159. package/stringzilla/javascript/stringzilla.js +0 -22
  160. package/stringzilla/package-ci.json +0 -10
  161. package/stringzilla/package.json +0 -32
  162. package/stringzilla/rust/lib.rs +0 -362
  163. package/stringzilla/swift/StringProtocol+StringZilla.swift +0 -280
  164. package/stringzilla/swift/Test.swift +0 -60
  165. package/tsconfig.json +0 -21
  166. package/wasmer.toml +0 -12
  167. package/winlibinstaller.bat +0 -42
  168. /package/{simsimd/javascript/dist-package-cjs.json → javascript/dist/cjs/package.json} +0 -0
  169. /package/{simsimd/javascript/dist-package-esm.json → javascript/dist/esm/package.json} +0 -0
@@ -1,429 +0,0 @@
1
- # Contributing to StringZilla
2
-
3
- Thank you for coming here! It's always nice to have third-party contributors 🤗
4
- Depending on the type of contribution, you may need to follow different steps.
5
-
6
- ---
7
-
8
- ## Project Structure
9
-
10
- The project is split into the following parts:
11
-
12
- - `include/stringzilla/stringzilla.h` - single-header C implementation.
13
- - `include/stringzilla/stringzilla.hpp` - single-header C++ wrapper.
14
- - `python/*` - Python bindings.
15
- - `javascript/*` - JavaScript bindings.
16
- - `scripts/*` - Scripts for benchmarking and testing.
17
-
18
- For minimal test coverage, check the following scripts:
19
-
20
- - `test.cpp` - tests C++ API (not underlying C) against STL.
21
- - `test.py` - tests Python API against native strings.
22
- - `test.js`.
23
-
24
- At the C++ level all benchmarks also validate the results against the STL baseline, serving as tests on real-world data.
25
- They have the broadest coverage of the library, and are the most important to keep up-to-date:
26
-
27
- - `bench_token.cpp` - token-level ops, like hashing, ordering, equality checks.
28
- - `bench_search.cpp` - bidirectional substring search, both exact and fuzzy.
29
- - `bench_similarity.cpp` - benchmark all edit distance backends.
30
- - `bench_sort.cpp` - sorting, partitioning, merging.
31
- - `bench_container.cpp` - STL containers with different string keys.
32
-
33
- The role of Python benchmarks is less to provide absolute number, but to compare against popular tools in the Python ecosystem.
34
-
35
- - `bench_search.(py|ipynb)` - compares against native Python `str`.
36
- - `bench_sort.(py|ipynb)` - compares against `pandas`.
37
- - `bench_similarity.(ipynb)` - compares against `jellyfish`, `editdistance`, etc.
38
-
39
- ## Benchmarking Datasets
40
-
41
- It's not always easy to find good datasets for benchmarking strings workloads.
42
- I use several ASCII and UTF8 international datasets.
43
- You can download them using the following commands:
44
-
45
- ```sh
46
- # English Leipzig Corpora Collection
47
- # 124 MB, 1'000'000 lines of ASCII, 8'388'608 tokens of mean length 5
48
- wget --no-clobber -O leipzig1M.txt https://introcs.cs.princeton.edu/python/42sort/leipzig1m.txt
49
-
50
- # Hutter Prize "enwik9" dataset for compression
51
- # 1 GB (0.3 GB compressed), 13'147'025 lines of ASCII, 67'108'864 tokens of mean length 6
52
- wget --no-clobber -O enwik9.zip http://mattmahoney.net/dc/enwik9.zip
53
- unzip enwik9.zip && rm enwik9.zip && mv enwik9 enwik9.txt
54
-
55
- # XL Sum dataset for multilingual extractive summarization
56
- # 4.7 GB (1.7 GB compressed), 1'004'598 lines of UTF8, 268'435'456 tokens of mean length 8
57
- wget --no-clobber -O xlsum.csv.gz https://github.com/ashvardanian/xl-sum/releases/download/v1.0.0/xlsum.csv.gz
58
- gzip -d xlsum.csv.gz
59
- ```
60
-
61
- ## IDE Integrations
62
-
63
- The project was originally developed in VS Code, and contains a set of configuration files for that IDE under `.vscode/`.
64
-
65
- - `tasks.json` - build tasks for CMake.
66
- - `launch.json` - debugger launchers for CMake.
67
- - `extensions.json` - recommended extensions for VS Code, including:
68
- - `ms-vscode.cpptools-themes` - C++ language support.
69
- - `ms-vscode.cmake-tools`, `cheshirekow.cmake-format` - CMake integration.
70
- - `ms-python.python`, `ms-python.black-formatter` - Python language support.
71
- - `yzhang.markdown-all-in-one` - formatting Markdown.
72
- - `aaron-bond.better-comments` - color-coded comments.
73
-
74
- ## Code Styling
75
-
76
- The project uses `.clang-format` to enforce a consistent code style.
77
- Modern IDEs, like VS Code, can be configured to automatically format the code on save.
78
-
79
- - East const over const West. Write `char const*` instead of `const char*`.
80
- - For color-coded comments start the line with `!` for warnings or `?` for questions.
81
- - Sort the includes: standard libraries, third-party libraries, and only then internal project headers.
82
-
83
- For C++ code:
84
-
85
- - Explicitly use `std::` or `sz::` namespaces over global `memcpy`, `uint64_t`, etc.
86
- - Explicitly mark `noexcept` or `noexcept(false)` for all library interfaces.
87
- - Document all possible exceptions of an interface using `@throw` in Doxygen.
88
- - Avoid C-style variadic arguments in favor of templates.
89
- - Avoid C-style casts in favor of `static_cast`, `reinterpret_cast`, and `const_cast`, except for places where a C function is called.
90
- - Use lower-case names for everything, except settings/conditions macros. Function-like macros, that take arguments, should be lowercase as well.
91
- - In templates prefer `typename` over `class`.
92
- - Prepend "private" symbols with `_` underscore.
93
-
94
- For Python code:
95
-
96
- - Use lower-case names for functions and variables.
97
-
98
- ## Contributing in C++ and C
99
-
100
- The primary C implementation and the C++ wrapper are built with CMake.
101
- Assuming the extensive use of new SIMD intrinsics and recent C++ language features, using a recent compiler is recommended.
102
- We prefer GCC 12, which is available from default Ubuntu repositories with Ubuntu 22.04 LTS onwards.
103
- If this is your first experience with CMake, use the following commands to get started:
104
-
105
- ```bash
106
- sudo apt-get update && sudo apt-get install cmake build-essential libjemalloc-dev g++-12 gcc-12 # Ubuntu
107
- brew install libomp llvm # MacOS
108
- ```
109
-
110
- ### Testing
111
-
112
- Using modern syntax, this is how you build and run the test suite:
113
-
114
- ```bash
115
- cmake -DSTRINGZILLA_BUILD_TEST=1 -B build_debug
116
- cmake --build ./build_debug --config Debug # Which will produce the following targets:
117
- ./build_debug/stringzilla_test_cpp20 # Unit test for the entire library compiled for current hardware
118
- ./build_debug/stringzilla_test_cpp20_x86_serial # x86 variant compiled for IvyBridge - last arch. before AVX2
119
- ./build_debug/stringzilla_test_cpp20_arm_serial # Arm variant compiled without Neon
120
- ```
121
-
122
- To use CppCheck for static analysis make sure to export the compilation commands.
123
- Overall, CppCheck and Clang-Tidy are extremely noisy and not suitable for CI, but may be useful for local development.
124
-
125
- ```bash
126
- sudo apt install cppcheck clang-tidy-11
127
-
128
- cmake -B build_artifacts \
129
- -DCMAKE_BUILD_TYPE=RelWithDebInfo \
130
- -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
131
- -DSTRINGZILLA_BUILD_BENCHMARK=1 \
132
- -DSTRINGZILLA_BUILD_TEST=1
133
-
134
- cppcheck --project=build_artifacts/compile_commands.json --enable=all
135
-
136
- clang-tidy-11 -p build_artifacts
137
- ```
138
-
139
- ### Benchmarking
140
-
141
- For benchmarks, you can use the following commands:
142
-
143
- ```bash
144
- cmake -DSTRINGZILLA_BUILD_BENCHMARK=1 -B build_release
145
- cmake --build ./build_release --config Release # Which will produce the following targets:
146
- ./build_release/stringzilla_bench_search <path> # for substring search
147
- ./build_release/stringzilla_bench_token <path> # for hashing, equality comparisons, etc.
148
- ./build_release/stringzilla_bench_similarity <path> # for edit distances and alignment scores
149
- ./build_release/stringzilla_bench_sort <path> # for sorting arrays of strings
150
- ./build_release/stringzilla_bench_container <path> # for STL containers with string keys
151
- ```
152
-
153
- ### Benchmarking Hardware-Specific Optimizations
154
-
155
- Running on modern hardware, you may want to compile the code for older generations to compare the relative performance.
156
- The assumption would be that newer ISA extensions would provide better performance.
157
- On x86_64, you can use the following commands to compile for Sandy Bridge, Haswell, and Sapphire Rapids:
158
-
159
- ```bash
160
- cmake -DCMAKE_BUILD_TYPE=Release -DSTRINGZILLA_BUILD_BENCHMARK=1 \
161
- -DSTRINGZILLA_TARGET_ARCH="ivybridge" -B build_release/ivybridge && \
162
- cmake --build build_release/ivybridge --config Release
163
- cmake -DCMAKE_BUILD_TYPE=Release -DSTRINGZILLA_BUILD_BENCHMARK=1 \
164
- -DSTRINGZILLA_TARGET_ARCH="haswell" -B build_release/haswell && \
165
- cmake --build build_release/haswell --config Release
166
- cmake -DCMAKE_BUILD_TYPE=Release -DSTRINGZILLA_BUILD_BENCHMARK=1 \
167
- -DSTRINGZILLA_TARGET_ARCH="sapphirerapids" -B build_release/sapphirerapids && \
168
- cmake --build build_release/sapphirerapids --config Release
169
- ```
170
-
171
- ### Benchmarking Compiler-Specific Optimizations
172
-
173
- Alternatively, you may want to compare the performance of the code compiled with different compilers.
174
- On x86_64, you may want to compare GCC, Clang, and ICX.
175
-
176
- ```bash
177
- cmake -DCMAKE_BUILD_TYPE=Release -DSTRINGZILLA_BUILD_BENCHMARK=1 -DSTRINGZILLA_BUILD_SHARED=1 \
178
- -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_C_COMPILER=gcc-12 \
179
- -B build_release/gcc && cmake --build build_release/gcc --config Release
180
- cmake -DCMAKE_BUILD_TYPE=Release -DSTRINGZILLA_BUILD_BENCHMARK=1 -DSTRINGZILLA_BUILD_SHARED=1 \
181
- -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang-14 \
182
- -B build_release/clang && cmake --build build_release/clang --config Release
183
- ```
184
-
185
- ### Profiling
186
-
187
- To simplify tracing and profiling, build with symbols using the `RelWithDebInfo` configuration.
188
- Here is an example for profiling one target - `stringzilla_bench_token`.
189
-
190
- ```bash
191
- cmake -DSTRINGZILLA_BUILD_BENCHMARK=1 \
192
- -DSTRINGZILLA_BUILD_TEST=1 \
193
- -DSTRINGZILLA_BUILD_SHARED=1 \
194
- -DCMAKE_BUILD_TYPE=RelWithDebInfo \
195
- -B build_profile
196
- cmake --build ./build_profile --config Release --target stringzilla_bench_token
197
-
198
- # Check that the debugging symbols are there with your favorite tool
199
- readelf --sections ./build_profile/stringzilla_bench_token | grep debug
200
- objdump -h ./build_profile/stringzilla_bench_token | grep debug
201
-
202
- # Profile
203
- sudo perf record -g ./build_profile/stringzilla_bench_token ./leipzig1M.txt
204
- sudo perf report
205
- ```
206
-
207
- ### Testing in Docker
208
-
209
- It might be a good idea to check the compatibility against the most popular Linux distributions.
210
- Docker is the goto-choice for that.
211
-
212
- #### Alpine
213
-
214
- Alpine is one of the most popular Linux distributions for containers, due to it's size.
215
- The base image is only ~3 MB, and it's based on musl libc, which is different from glibc.
216
-
217
- ```bash
218
- sudo docker run -it --rm -v "$(pwd)":/workspace/StringZilla alpine:latest /bin/ash
219
- cd /workspace/StringZilla
220
- apk add --update make cmake g++ gcc
221
- cmake -DSTRINGZILLA_BUILD_TEST=1 -B build_debug
222
- cmake --build ./build_debug --config Debug
223
- ./build_debug/stringzilla_test_cpp20
224
- ```
225
-
226
- #### Intel Clear Linux
227
-
228
- Clear Linux is a distribution optimized for Intel hardware, and is known for its performance.
229
- It has rolling releases, and is based on glibc.
230
- It might be a good choice for compiling with Intel oneAPI compilers.
231
-
232
- ```bash
233
- sudo docker run -it --rm -v "$(pwd)":/workspace/StringZilla clearlinux:latest /bin/bash
234
- cd /workspace/StringZilla
235
- swupd update
236
- swupd bundle-add c-basic dev-utils
237
- cmake -DSTRINGZILLA_BUILD_TEST=1 -B build_debug
238
- cmake --build ./build_debug --config Debug
239
- ./build_debug/stringzilla_test_cpp20
240
- ```
241
-
242
- For benchmarks:
243
-
244
- ```bash
245
- cmake -DSTRINGZILLA_BUILD_TEST=1 -DSTRINGZILLA_BUILD_BENCHMARK=1 -B build_release
246
- cmake --build ./build_release --config Release
247
- ```
248
-
249
- #### Amazon Linux
250
-
251
- For CentOS-based __Amazon Linux 2023__:
252
-
253
- ```bash
254
- sudo docker run -it --rm -v "$(pwd)":/workspace/StringZilla amazonlinux:2023 bash
255
- cd /workspace/StringZilla
256
- yum install -y make cmake3 gcc g++
257
- cmake3 -DSTRINGZILLA_BUILD_TEST=1 -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DSTRINGZILLA_TARGET_ARCH="ivybridge" -B build_debug
258
- cmake3 --build ./build_debug --config Debug --target stringzilla_test_cpp11
259
- build_debug/stringzilla_test_cpp11
260
- ```
261
-
262
- The CentOS-based __Amazon Linux 2__ is still used in older AWS Lambda functions.
263
- Sadly, the newest GCC version it supports is 10, and it can't handle AVX-512 instructions.
264
-
265
- ```bash
266
- sudo docker run -it --rm -v "$(pwd)":/workspace/StringZilla amazonlinux:2 bash
267
- cd /workspace/StringZilla
268
- yum install -y make cmake3 gcc10 gcc10-c++
269
- cmake3 -DSTRINGZILLA_BUILD_TEST=1 -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DSTRINGZILLA_TARGET_ARCH="ivybridge" -B build_debug
270
- cmake3 --build ./build_debug --config Debug --target stringzilla_test_cpp11
271
- build_debug/stringzilla_test_cpp11
272
- ```
273
-
274
- > [!CAUTION]
275
- >
276
- > Even with GCC 10 the tests compilation will fail, as the STL implementation of the `insert` function doesn't conform to standard.
277
- > The `s.insert(s.begin() + 1, {'a', 'b', 'c'}) == (s.begin() + 1)` expression is illformed, as the `std::string::insert` return `void`.
278
-
279
- ---
280
-
281
- Don't forget to clean up Docker afterwards.
282
-
283
- ```bash
284
- docker system prune -a --volumes
285
- ```
286
-
287
- ## Contributing in Python
288
-
289
- Python bindings are implemented using pure CPython, so you wouldn't need to install SWIG, PyBind11, or any other third-party library.
290
-
291
- ```bash
292
- pip install -e . # To build locally from source
293
- ```
294
-
295
- ### Testing
296
-
297
- For testing we use PyTest, which may not be installed on your system.
298
-
299
- ```bash
300
- pip install pytest # To install PyTest
301
- pytest scripts/test.py -s -x # Runs tests printing logs and stops on the first failure
302
- ```
303
-
304
- On a related note, StringZilla for Python seems to cover more OS and hardware combinations, than NumPy.
305
- That's why NumPy isn't a required dependency.
306
- Still, many tests may use NumPy, so consider installing it on mainstream platforms.
307
-
308
- ```bash
309
- pip install numpy
310
- ```
311
-
312
- Before you ship, please make sure the `cibuilwheel` packaging works and tests pass on other platforms.
313
- Don't forget to use the right [CLI arguments][cibuildwheel-cli] to avoid overloading your Docker runtime.
314
-
315
- ```bash
316
- cibuildwheel
317
- cibuildwheel --platform linux # works on any OS and builds all Linux backends
318
- cibuildwheel --platform linux --archs x86_64 # 64-bit x86, the most common on desktop and servers
319
- cibuildwheel --platform linux --archs aarch64 # 64-bit Arm for mobile devices, Apple M-series, and AWS Graviton
320
- cibuildwheel --platform linux --archs i686 # 32-bit Linux
321
- cibuildwheel --platform linux --archs s390x # emulating big-endian IBM Z
322
- cibuildwheel --platform macos # works only on MacOS
323
- cibuildwheel --platform windows # works only on Windows
324
- ```
325
-
326
- You may need root previligies for multi-architecture builds:
327
-
328
- ```bash
329
- sudo $(which cibuildwheel) --platform linux
330
- ```
331
-
332
- On Windows and MacOS, to avoid frequent path resolution issues, you may want to use:
333
-
334
- ```bash
335
- python -m cibuildwheel --platform windows
336
- ```
337
-
338
- [cibuildwheel-cli]: https://cibuildwheel.readthedocs.io/en/stable/options/#command-line
339
-
340
- ### Benchmarking
341
-
342
- For high-performance low-latency benchmarking, stick to C/C++ native benchmarks, as the CPython is likely to cause bottlenecks.
343
- For benchmarking, the following scripts are provided.
344
-
345
- ```sh
346
- python scripts/bench_search.py --haystack_path "your file" --needle "your pattern" # real data
347
- python scripts/bench_search.py --haystack_pattern "abcd" --haystack_length 1e9 --needle "abce" # synthetic data
348
- python scripts/similarity_bench.py --text_path "your file" # edit ditance computations
349
- ```
350
-
351
- Alternatively, you can explore the Jupyter notebooks in `scripts/` directory.
352
-
353
- ## Contributing in JavaScript
354
-
355
- ```bash
356
- npm ci && npm test
357
- ```
358
-
359
- ## Contributing in Swift
360
-
361
- ```bash
362
- swift build && swift test
363
- ```
364
-
365
- Running Swift on Linux requires a couple of extra steps, as the Swift compiler is not available in the default repositories.
366
- Please get the most recent Swift tarball from the [official website](https://www.swift.org/install/).
367
- At the time of writing, for 64-bit Arm CPU running Ubuntu 22.04, the following commands would work:
368
-
369
- ```bash
370
- wget https://download.swift.org/swift-5.9.2-release/ubuntu2204-aarch64/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-ubuntu22.04-aarch64.tar.gz
371
- tar xzf swift-5.9.2-RELEASE-ubuntu22.04-aarch64.tar.gz
372
- sudo mv swift-5.9.2-RELEASE-ubuntu22.04-aarch64 /usr/share/swift
373
- echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bashrc
374
- source ~/.bashrc
375
- ```
376
-
377
- Alternatively, on Linux, the official Swift Docker image can be used for builds and tests:
378
-
379
- ```bash
380
- sudo docker run --rm -v "$PWD:/workspace" -w /workspace swift:5.9 /bin/bash -cl "swift build -c release --static-swift-stdlib && swift test -c release --enable-test-discovery"
381
- ```
382
-
383
- ## Contributing in Rust
384
-
385
- ```bash
386
- cargo test
387
- ```
388
-
389
- ## General Performance Observations
390
-
391
- ### Unaligned Loads
392
-
393
- One common surface of attack for performance optimizations is minimizing unaligned loads.
394
- Such solutions are beautiful from the algorithmic perspective, but often lead to worse performance.
395
- It's often cheaper to issue two interleaving wide-register loads, than try minimizing those loads at the cost of juggling registers.
396
-
397
- ### Register Pressure
398
-
399
- Byte-level comparisons are simpler and often faster, than n-gram comparisons with subsequent interleaving.
400
- In the following example we search for 4-byte needles in a haystack, loading at different offsets, and comparing then as arrays of 32-bit integers.
401
-
402
- ```c
403
- h0_vec.zmm = _mm512_loadu_epi8(h);
404
- h1_vec.zmm = _mm512_loadu_epi8(h + 1);
405
- h2_vec.zmm = _mm512_loadu_epi8(h + 2);
406
- h3_vec.zmm = _mm512_loadu_epi8(h + 3);
407
- matches0 = _mm512_cmpeq_epi32_mask(h0_vec.zmm, n_vec.zmm);
408
- matches1 = _mm512_cmpeq_epi32_mask(h1_vec.zmm, n_vec.zmm);
409
- matches2 = _mm512_cmpeq_epi32_mask(h2_vec.zmm, n_vec.zmm);
410
- matches3 = _mm512_cmpeq_epi32_mask(h3_vec.zmm, n_vec.zmm);
411
- if (matches0 | matches1 | matches2 | matches3)
412
- return h + sz_u64_ctz(_pdep_u64(matches0, 0x1111111111111111) | //
413
- _pdep_u64(matches1, 0x2222222222222222) | //
414
- _pdep_u64(matches2, 0x4444444444444444) | //
415
- _pdep_u64(matches3, 0x8888888888888888));
416
- ```
417
-
418
- A simpler solution would be to compare byte-by-byte, but in that case we would need to populate multiple registers, broadcasting different letters of the needle into them.
419
- That may not be noticeable on a micro-benchmark, but it would be noticeable on real-world workloads, where the CPU will speculatively interleave those search operations with something else happening in that context.
420
-
421
- ## Working on Alternative Hardware Backends
422
-
423
- ## Working on Faster Edit Distances
424
-
425
- ## Working on Random String Generators
426
-
427
- ## Working on Sequence Processing and Sorting
428
-
429
-
@@ -1,25 +0,0 @@
1
- # This file is automatically @generated by Cargo.
2
- # It is not intended for manual editing.
3
- version = 3
4
-
5
- [[package]]
6
- name = "cc"
7
- version = "1.0.83"
8
- source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
10
- dependencies = [
11
- "libc",
12
- ]
13
-
14
- [[package]]
15
- name = "libc"
16
- version = "0.2.152"
17
- source = "registry+https://github.com/rust-lang/crates.io-index"
18
- checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
19
-
20
- [[package]]
21
- name = "stringzilla"
22
- version = "3.0.0"
23
- dependencies = [
24
- "cc",
25
- ]
@@ -1,26 +0,0 @@
1
- [package]
2
- name = "stringzilla"
3
- version = "3.2.0"
4
- authors = ["Ash Vardanian <1983160+ashvardanian@users.noreply.github.com>"]
5
- description = "Faster SIMD-accelerated string search, sorting, fingerprints, and edit distances"
6
- edition = "2021"
7
- license = "Apache-2.0"
8
- publish = true
9
- repository = "https://github.com/ashvardanian/stringzilla"
10
- documentation = "https://docs.rs/stringzilla"
11
- homepage = "https://ashvardanian.com/posts/stringzilla/"
12
- keywords = ["simd", "search", "retrieval", "hash", "sort"]
13
- categories = [
14
- "text-processing",
15
- "hardware-support",
16
- "no-std",
17
- "wasm",
18
- "external-ffi-bindings",
19
- ]
20
-
21
- [lib]
22
- name = "stringzilla"
23
- path = "rust/lib.rs"
24
-
25
- [build-dependencies]
26
- cc = "1.0"
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.