usearch 2.9.2 → 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.
- package/README.md +39 -38
- package/javascript/{types → dist/cjs}/usearch.d.ts +90 -115
- package/javascript/dist/cjs/usearch.js +531 -0
- package/javascript/dist/esm/usearch.d.ts +212 -0
- package/javascript/{usearch.js → dist/esm/usearch.js} +199 -153
- package/package.json +25 -23
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/prebuilds/win32-ia32/usearch.node +0 -0
- package/prebuilds/win32-x64/usearch.node +0 -0
- package/.clang-format +0 -10
- package/.clang-tidy +0 -60
- package/.cmake-format.py +0 -19
- package/.dockerignore +0 -93
- package/.gitattributes +0 -9
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
- package/.github/ISSUE_TEMPLATE/config.yml +0 -5
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -64
- package/.github/workflows/Dockerfile.libs +0 -36
- package/.github/workflows/prerelease.yml +0 -331
- package/.github/workflows/release.yml +0 -722
- package/.github/workflows/update_version.sh +0 -15
- package/.gitmodules +0 -9
- package/.releaserc +0 -90
- package/CITATION.cff +0 -11
- package/CMakeLists.txt +0 -324
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -361
- package/Cargo.toml +0 -19
- package/Dockerfile +0 -16
- package/VERSION +0 -1
- package/assets/unum.png +0 -0
- package/assets/usearch-approaches-transparent.png +0 -0
- package/assets/usearch-approaches-white.png +0 -0
- package/assets/usearch-neighbor-types.png +0 -0
- package/binding.gyp +0 -87
- package/build.gradle +0 -204
- package/build.rs +0 -18
- package/c/CMakeLists.txt +0 -25
- package/c/README.md +0 -34
- package/c/lib.cpp +0 -358
- package/c/test.c +0 -382
- package/c/usearch.h +0 -311
- package/cmake/clipp.cmake +0 -7
- package/cmake/config.cmake.in +0 -15
- package/cmake/emscripten.cmake +0 -8
- package/cmake/jemalloc.cmake +0 -62
- package/cmake/pkg-config.pc.in +0 -4
- package/cmake/usearchConfigVersion.cmake.in +0 -20
- package/conanfile.py +0 -26
- package/cpp/CMakeLists.txt +0 -14
- package/cpp/README.md +0 -161
- package/cpp/bench.cpp +0 -618
- package/cpp/test.cpp +0 -323
- package/fp16/CMakeLists.txt +0 -176
- package/fp16/LICENSE +0 -11
- package/fp16/README.md +0 -20
- package/fp16/bench/alt-element.cc +0 -89
- package/fp16/bench/from-alt-array.cc +0 -175
- package/fp16/bench/from-ieee-array.cc +0 -399
- package/fp16/bench/ieee-element.cc +0 -272
- package/fp16/bench/to-alt-array.cc +0 -91
- package/fp16/bench/to-ieee-array.cc +0 -303
- package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
- package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
- package/fp16/cmake/DownloadPSimd.cmake +0 -15
- package/fp16/configure.py +0 -65
- package/fp16/confu.yaml +0 -8
- package/fp16/include/fp16/__init__.py +0 -0
- package/fp16/include/fp16/avx.py +0 -50
- package/fp16/include/fp16/avx2.py +0 -53
- package/fp16/include/fp16/bitcasts.h +0 -92
- package/fp16/include/fp16/fp16.h +0 -451
- package/fp16/include/fp16/psimd.h +0 -131
- package/fp16/include/fp16.h +0 -11
- package/fp16/jni/Android.mk +0 -6
- package/fp16/jni/Application.mk +0 -4
- package/fp16/test/alt-from-fp32-value.cc +0 -498
- package/fp16/test/alt-to-fp32-bits.cc +0 -263
- package/fp16/test/alt-to-fp32-psimd.cc +0 -145
- package/fp16/test/alt-to-fp32-value.cc +0 -348
- package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
- package/fp16/test/bitcasts.cc +0 -56
- package/fp16/test/ieee-from-fp32-value.cc +0 -523
- package/fp16/test/ieee-to-fp32-bits.cc +0 -333
- package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
- package/fp16/test/ieee-to-fp32-value.cc +0 -420
- package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
- package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
- package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
- package/fp16/test/peachpy/stubs.py +0 -38
- package/fp16/test/tables.cc +0 -530
- package/fp16/test/tables.h +0 -13
- package/fp16/third-party/THHalf.h +0 -92
- package/fp16/third-party/eigen-half.h +0 -170
- package/fp16/third-party/float16-compressor.h +0 -80
- package/fp16/third-party/half.hpp +0 -2916
- package/fp16/third-party/npy-halffloat.h +0 -328
- package/include/usearch/index.hpp +0 -3836
- package/include/usearch/index_dense.hpp +0 -2004
- package/include/usearch/index_plugins.hpp +0 -2213
- package/javascript/lib.cpp +0 -341
- package/javascript/types/usearch.d.ts.map +0 -1
- package/javascript/usearch.test.js +0 -74
- package/package-ci.json +0 -10
- package/pyproject.toml +0 -51
- package/setup.py +0 -201
- package/simsimd/.releaserc +0 -86
- package/simsimd/CONTRIBUTING.md +0 -88
- package/simsimd/Cargo.lock +0 -709
- package/simsimd/Cargo.toml +0 -44
- package/simsimd/LICENSE +0 -201
- package/simsimd/README.md +0 -317
- package/simsimd/binding.gyp +0 -36
- package/simsimd/build.rs +0 -20
- package/simsimd/include/simsimd/binary.h +0 -245
- package/simsimd/include/simsimd/complex.h +0 -174
- package/simsimd/include/simsimd/probability.h +0 -548
- package/simsimd/include/simsimd/simsimd.h +0 -465
- package/simsimd/include/simsimd/spatial.h +0 -1267
- package/simsimd/include/simsimd/types.h +0 -208
- package/simsimd/javascript/bench.js +0 -127
- package/simsimd/javascript/fallback.ts +0 -193
- package/simsimd/javascript/lib.c +0 -102
- package/simsimd/javascript/node-gyp-build.d.ts +0 -1
- package/simsimd/javascript/simsimd.ts +0 -124
- package/simsimd/javascript/test.mjs +0 -153
- package/simsimd/javascript/tsconfig-base.json +0 -25
- package/simsimd/javascript/tsconfig-cjs.json +0 -8
- package/simsimd/javascript/tsconfig-esm.json +0 -8
- package/simsimd/package-lock.json +0 -1688
- package/simsimd/package.json +0 -61
- package/simsimd/rust/benches/cosine.rs +0 -27
- package/simsimd/rust/benches/native.rs +0 -30
- package/simsimd/rust/benches/sqeuclidean.rs +0 -27
- package/simsimd/rust/lib.c +0 -45
- package/simsimd/rust/lib.rs +0 -550
- package/sqlite/README.md +0 -178
- package/sqlite/lib.cpp +0 -325
- package/stringzilla/CONTRIBUTING.md +0 -446
- package/stringzilla/Cargo.lock +0 -25
- package/stringzilla/Cargo.toml +0 -26
- package/stringzilla/LICENSE +0 -201
- package/stringzilla/README.md +0 -1422
- package/stringzilla/VERSION +0 -1
- package/stringzilla/assets/cover-strinzilla.jpeg +0 -0
- package/stringzilla/assets/meme-stringzilla-v2.jpeg +0 -0
- package/stringzilla/assets/meme-stringzilla-v3.jpeg +0 -0
- package/stringzilla/binding.gyp +0 -16
- package/stringzilla/build.rs +0 -87
- package/stringzilla/c/lib.c +0 -337
- package/stringzilla/cli/README.md +0 -65
- package/stringzilla/cli/__init__.py +0 -0
- package/stringzilla/cli/split.py +0 -105
- package/stringzilla/cli/wc.py +0 -117
- package/stringzilla/include/stringzilla/experimental.h +0 -845
- package/stringzilla/include/stringzilla/module.modulemap +0 -9
- package/stringzilla/include/stringzilla/stringzilla.h +0 -5370
- package/stringzilla/include/stringzilla/stringzilla.hpp +0 -3838
- package/stringzilla/javascript/lib.c +0 -125
- package/stringzilla/javascript/stringzilla.js +0 -22
- package/stringzilla/package-ci.json +0 -10
- package/stringzilla/package.json +0 -32
- package/stringzilla/rust/lib.rs +0 -873
- package/stringzilla/swift/StringProtocol+StringZilla.swift +0 -280
- package/stringzilla/swift/Test.swift +0 -60
- package/tsconfig.json +0 -21
- package/wasmer.toml +0 -12
- package/winlibinstaller.bat +0 -42
- /package/{simsimd/javascript/dist-package-cjs.json → javascript/dist/cjs/package.json} +0 -0
- /package/{simsimd/javascript/dist-package-esm.json → javascript/dist/esm/package.json} +0 -0
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// StringProtocol+StringZilla.swift
|
|
3
|
-
//
|
|
4
|
-
// Created by Ash Vardanian on 18/1/24.
|
|
5
|
-
// Extension of StringProtocol to interface with StringZilla functionalities.
|
|
6
|
-
//
|
|
7
|
-
// Docs:
|
|
8
|
-
// - Accessing immutable UTF8-range:
|
|
9
|
-
// https://developer.apple.com/documentation/swift/string/utf8view
|
|
10
|
-
//
|
|
11
|
-
// More reading materials:
|
|
12
|
-
// - String’s ABI and UTF-8. Nov 2018
|
|
13
|
-
// https://forums.swift.org/t/string-s-abi-and-utf-8/17676
|
|
14
|
-
// - Stable pointer into a C string without copying it? Aug 2021
|
|
15
|
-
// https://forums.swift.org/t/stable-pointer-into-a-c-string-without-copying-it/51244/1
|
|
16
|
-
|
|
17
|
-
import StringZillaC
|
|
18
|
-
|
|
19
|
-
// We need to link the standard libraries.
|
|
20
|
-
#if os(Linux)
|
|
21
|
-
import Glibc
|
|
22
|
-
#else
|
|
23
|
-
import Darwin.C
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
/// Protocol defining a single-byte data type.
|
|
27
|
-
fileprivate protocol SingleByte {}
|
|
28
|
-
|
|
29
|
-
extension UInt8: SingleByte {}
|
|
30
|
-
extension Int8: SingleByte {} // This would match `CChar` as well.
|
|
31
|
-
|
|
32
|
-
@usableFromInline
|
|
33
|
-
enum StringZillaError: Error {
|
|
34
|
-
case contiguousStorageUnavailable
|
|
35
|
-
case memoryAllocationFailed
|
|
36
|
-
|
|
37
|
-
var localizedDescription: String {
|
|
38
|
-
switch self {
|
|
39
|
-
case .contiguousStorageUnavailable:
|
|
40
|
-
return "Contiguous storage for the sequence is unavailable."
|
|
41
|
-
case .memoryAllocationFailed:
|
|
42
|
-
return "Memory allocation failed."
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/// Protocol defining the interface for StringZilla-compatible byte-spans.
|
|
48
|
-
///
|
|
49
|
-
/// # Discussion:
|
|
50
|
-
/// The Swift documentation is extremely vague about the actual memory layout of a String
|
|
51
|
-
/// and the cost of obtaining the underlying UTF8 representation or any other raw pointers.
|
|
52
|
-
/// https://developer.apple.com/documentation/swift/stringprotocol/withcstring(_:)
|
|
53
|
-
/// https://developer.apple.com/documentation/swift/stringprotocol/withcstring(encodedas:_:)
|
|
54
|
-
/// https://developer.apple.com/documentation/swift/stringprotocol/data(using:allowlossyconversion:)
|
|
55
|
-
public protocol StringZillaViewable: Collection {
|
|
56
|
-
/// A type that represents a position in the collection.
|
|
57
|
-
///
|
|
58
|
-
/// Executes a closure with a pointer to the string's UTF8 C representation and its length.
|
|
59
|
-
///
|
|
60
|
-
/// - Parameters:
|
|
61
|
-
/// - body: A closure that takes a pointer to a C string and its length.
|
|
62
|
-
/// - Throws: Can throw an error.
|
|
63
|
-
/// - Returns: Returns a value of type R, which is the result of the closure.
|
|
64
|
-
func withStringZillaScope<R>(_ body: (sz_cptr_t, sz_size_t) throws -> R) rethrows -> R
|
|
65
|
-
|
|
66
|
-
/// Calculates the offset index for a given byte pointer relative to a start pointer.
|
|
67
|
-
///
|
|
68
|
-
/// - Parameters:
|
|
69
|
-
/// - bytePointer: A pointer to the byte for which the offset is calculated.
|
|
70
|
-
/// - startPointer: The starting pointer for the calculation, previously obtained from `szScope`.
|
|
71
|
-
/// - Returns: The calculated index offset.
|
|
72
|
-
func stringZillaByteOffset(forByte bytePointer: sz_cptr_t, after startPointer: sz_cptr_t) -> Index
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
extension String: StringZillaViewable {
|
|
76
|
-
public typealias Index = String.Index
|
|
77
|
-
|
|
78
|
-
@_transparent
|
|
79
|
-
public func withStringZillaScope<R>(_ body: (sz_cptr_t, sz_size_t) throws -> R) rethrows -> R {
|
|
80
|
-
let cLength = sz_size_t(utf8.count)
|
|
81
|
-
return try self.withCString { cString in
|
|
82
|
-
try body(cString, cLength)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@_transparent
|
|
87
|
-
public func stringZillaByteOffset(forByte bytePointer: sz_cptr_t, after startPointer: sz_cptr_t) -> Index {
|
|
88
|
-
self.utf8.index(self.utf8.startIndex, offsetBy: bytePointer - startPointer)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
extension Substring.UTF8View: StringZillaViewable {
|
|
93
|
-
public typealias Index = Substring.UTF8View.Index
|
|
94
|
-
|
|
95
|
-
/// Executes a closure with a pointer to the UTF8View's contiguous storage of single-byte elements (UTF-8 code units).
|
|
96
|
-
/// - Parameters:
|
|
97
|
-
/// - body: A closure that takes a pointer to the contiguous storage and its size.
|
|
98
|
-
/// - Throws: An error if the storage is not contiguous.
|
|
99
|
-
@_transparent
|
|
100
|
-
public func withStringZillaScope<R>(_ body: (sz_cptr_t, sz_size_t) throws -> R) rethrows -> R {
|
|
101
|
-
return try withContiguousStorageIfAvailable { bufferPointer -> R in
|
|
102
|
-
let cLength = sz_size_t(bufferPointer.count)
|
|
103
|
-
let cString = UnsafeRawPointer(bufferPointer.baseAddress!).assumingMemoryBound(to: CChar.self)
|
|
104
|
-
return try body(cString, cLength)
|
|
105
|
-
} ?? {
|
|
106
|
-
throw StringZillaError.contiguousStorageUnavailable
|
|
107
|
-
}()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/// Calculates the offset index for a given byte pointer relative to a start pointer.
|
|
111
|
-
/// - Parameters:
|
|
112
|
-
/// - bytePointer: A pointer to the byte for which the offset is calculated.
|
|
113
|
-
/// - startPointer: The starting pointer for the calculation, previously obtained from `szScope`.
|
|
114
|
-
/// - Returns: The calculated index offset.
|
|
115
|
-
@_transparent
|
|
116
|
-
public func stringZillaByteOffset(forByte bytePointer: sz_cptr_t, after startPointer: sz_cptr_t) -> Index {
|
|
117
|
-
return self.index(self.startIndex, offsetBy: bytePointer - startPointer)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
extension String.UTF8View: StringZillaViewable {
|
|
122
|
-
public typealias Index = String.UTF8View.Index
|
|
123
|
-
|
|
124
|
-
/// Executes a closure with a pointer to the UTF8View's contiguous storage of single-byte elements (UTF-8 code units).
|
|
125
|
-
/// - Parameters:
|
|
126
|
-
/// - body: A closure that takes a pointer to the contiguous storage and its size.
|
|
127
|
-
/// - Throws: An error if the storage is not contiguous.
|
|
128
|
-
public func withStringZillaScope<R>(_ body: (sz_cptr_t, sz_size_t) throws -> R) rethrows -> R {
|
|
129
|
-
return try withContiguousStorageIfAvailable { bufferPointer -> R in
|
|
130
|
-
let cLength = sz_size_t(bufferPointer.count)
|
|
131
|
-
let cString = UnsafeRawPointer(bufferPointer.baseAddress!).assumingMemoryBound(to: CChar.self)
|
|
132
|
-
return try body(cString, cLength)
|
|
133
|
-
} ?? {
|
|
134
|
-
throw StringZillaError.contiguousStorageUnavailable
|
|
135
|
-
}()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/// Calculates the offset index for a given byte pointer relative to a start pointer.
|
|
139
|
-
/// - Parameters:
|
|
140
|
-
/// - bytePointer: A pointer to the byte for which the offset is calculated.
|
|
141
|
-
/// - startPointer: The starting pointer for the calculation, previously obtained from `szScope`.
|
|
142
|
-
/// - Returns: The calculated index offset.
|
|
143
|
-
public func stringZillaByteOffset(forByte bytePointer: sz_cptr_t, after startPointer: sz_cptr_t) -> Index {
|
|
144
|
-
return self.index(self.startIndex, offsetBy: bytePointer - startPointer)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public extension StringZillaViewable {
|
|
149
|
-
|
|
150
|
-
/// Finds the first occurrence of the specified substring within the receiver.
|
|
151
|
-
/// - Parameter needle: The substring to search for.
|
|
152
|
-
/// - Returns: The index of the found occurrence, or `nil` if not found.
|
|
153
|
-
@_specialize(where Self == String, S == String)
|
|
154
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
155
|
-
func findFirst<S: StringZillaViewable>(substring needle: S) -> Index? {
|
|
156
|
-
var result: Index?
|
|
157
|
-
withStringZillaScope { hPointer, hLength in
|
|
158
|
-
needle.withStringZillaScope { nPointer, nLength in
|
|
159
|
-
if let matchPointer = sz_find(hPointer, hLength, nPointer, nLength) {
|
|
160
|
-
result = self.stringZillaByteOffset(forByte: matchPointer, after: hPointer)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/// Finds the last occurrence of the specified substring within the receiver.
|
|
168
|
-
/// - Parameter needle: The substring to search for.
|
|
169
|
-
/// - Returns: The index of the found occurrence, or `nil` if not found.
|
|
170
|
-
@_specialize(where Self == String, S == String)
|
|
171
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
172
|
-
func findLast<S: StringZillaViewable>(substring needle: S) -> Index? {
|
|
173
|
-
var result: Index?
|
|
174
|
-
withStringZillaScope { hPointer, hLength in
|
|
175
|
-
needle.withStringZillaScope { nPointer, nLength in
|
|
176
|
-
if let matchPointer = sz_rfind(hPointer, hLength, nPointer, nLength) {
|
|
177
|
-
result = self.stringZillaByteOffset(forByte: matchPointer, after: hPointer)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return result
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/// Finds the first occurrence of the specified character-set members within the receiver.
|
|
185
|
-
/// - Parameter characters: A string-like collection of characters to match.
|
|
186
|
-
/// - Returns: The index of the found occurrence, or `nil` if not found.
|
|
187
|
-
@_specialize(where Self == String, S == String)
|
|
188
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
189
|
-
func findFirst<S: StringZillaViewable>(characterFrom characters: S) -> Index? {
|
|
190
|
-
var result: Index?
|
|
191
|
-
withStringZillaScope { hPointer, hLength in
|
|
192
|
-
characters.withStringZillaScope { nPointer, nLength in
|
|
193
|
-
if let matchPointer = sz_find_char_from(hPointer, hLength, nPointer, nLength) {
|
|
194
|
-
result = self.stringZillaByteOffset(forByte: matchPointer, after: hPointer)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return result
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/// Finds the last occurrence of the specified character-set members within the receiver.
|
|
202
|
-
/// - Parameter characters: A string-like collection of characters to match.
|
|
203
|
-
/// - Returns: The index of the found occurrence, or `nil` if not found.
|
|
204
|
-
@_specialize(where Self == String, S == String)
|
|
205
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
206
|
-
func findLast<S: StringZillaViewable>(characterFrom characters: S) -> Index? {
|
|
207
|
-
var result: Index?
|
|
208
|
-
withStringZillaScope { hPointer, hLength in
|
|
209
|
-
characters.withStringZillaScope { nPointer, nLength in
|
|
210
|
-
if let matchPointer = sz_rfind_char_from(hPointer, hLength, nPointer, nLength) {
|
|
211
|
-
result = self.stringZillaByteOffset(forByte: matchPointer, after: hPointer)
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return result
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/// Finds the first occurrence of a character outside of the the given character-set within the receiver.
|
|
219
|
-
/// - Parameter characters: A string-like collection of characters to exclude.
|
|
220
|
-
/// - Returns: The index of the found occurrence, or `nil` if not found.
|
|
221
|
-
@_specialize(where Self == String, S == String)
|
|
222
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
223
|
-
func findFirst<S: StringZillaViewable>(characterNotFrom characters: S) -> Index? {
|
|
224
|
-
var result: Index?
|
|
225
|
-
withStringZillaScope { hPointer, hLength in
|
|
226
|
-
characters.withStringZillaScope { nPointer, nLength in
|
|
227
|
-
if let matchPointer = sz_find_char_not_from(hPointer, hLength, nPointer, nLength) {
|
|
228
|
-
result = self.stringZillaByteOffset(forByte: matchPointer, after: hPointer)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return result
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/// Finds the last occurrence of a character outside of the the given character-set within the receiver.
|
|
236
|
-
/// - Parameter characters: A string-like collection of characters to exclude.
|
|
237
|
-
/// - Returns: The index of the found occurrence, or `nil` if not found.
|
|
238
|
-
@_specialize(where Self == String, S == String)
|
|
239
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
240
|
-
func findLast<S: StringZillaViewable>(characterNotFrom characters: S) -> Index? {
|
|
241
|
-
var result: Index?
|
|
242
|
-
withStringZillaScope { hPointer, hLength in
|
|
243
|
-
characters.withStringZillaScope { nPointer, nLength in
|
|
244
|
-
if let matchPointer = sz_rfind_char_not_from(hPointer, hLength, nPointer, nLength) {
|
|
245
|
-
result = self.stringZillaByteOffset(forByte: matchPointer, after: hPointer)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return result
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/// Computes the Levenshtein edit distance between this and another string.
|
|
253
|
-
/// - Parameter other: A string-like collection of characters to exclude.
|
|
254
|
-
/// - Returns: The edit distance, as an unsigned integer.
|
|
255
|
-
/// - Throws: If a memory allocation error has happened.
|
|
256
|
-
@_specialize(where Self == String, S == String)
|
|
257
|
-
@_specialize(where Self == String.UTF8View, S == String.UTF8View)
|
|
258
|
-
func editDistance<S: StringZillaViewable>(from other: S, bound: UInt64 = 0) throws -> UInt64? {
|
|
259
|
-
var result: UInt64?
|
|
260
|
-
|
|
261
|
-
// Use a do-catch block to handle potential errors
|
|
262
|
-
do {
|
|
263
|
-
try withStringZillaScope { hPointer, hLength in
|
|
264
|
-
try other.withStringZillaScope { nPointer, nLength in
|
|
265
|
-
result = UInt64(sz_edit_distance(hPointer, hLength, nPointer, nLength, sz_size_t(bound), nil))
|
|
266
|
-
if result == SZ_SIZE_MAX {
|
|
267
|
-
result = nil
|
|
268
|
-
throw StringZillaError.memoryAllocationFailed
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
} catch {
|
|
273
|
-
// Handle or rethrow the error
|
|
274
|
-
throw error
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return result
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Test.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Ash Vardanian on 18/1/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import XCTest
|
|
9
|
-
@testable import StringZilla
|
|
10
|
-
|
|
11
|
-
class StringZillaTests: XCTestCase {
|
|
12
|
-
|
|
13
|
-
var testString: String!
|
|
14
|
-
|
|
15
|
-
override func setUp() {
|
|
16
|
-
super.setUp()
|
|
17
|
-
testString = "Hello, world! Welcome to StringZilla. 👋"
|
|
18
|
-
XCTAssertEqual(testString.count, 39)
|
|
19
|
-
XCTAssertEqual(testString.utf8.count, 42)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
func testFindFirstSubstring() {
|
|
23
|
-
let index = testString.findFirst(substring: "world")!
|
|
24
|
-
XCTAssertEqual(testString[index...], "world! Welcome to StringZilla. 👋")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
func testFindLastSubstring() {
|
|
28
|
-
let index = testString.findLast(substring: "o")!
|
|
29
|
-
XCTAssertEqual(testString[index...], "o StringZilla. 👋")
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
func testFindFirstCharacterFromSet() {
|
|
33
|
-
let index = testString.findFirst(characterFrom: "aeiou")!
|
|
34
|
-
XCTAssertEqual(testString[index...], "ello, world! Welcome to StringZilla. 👋")
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
func testFindLastCharacterFromSet() {
|
|
38
|
-
let index = testString.findLast(characterFrom: "aeiou")!
|
|
39
|
-
XCTAssertEqual(testString[index...], "a. 👋")
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func testFindFirstCharacterNotFromSet() {
|
|
43
|
-
let index = testString.findFirst(characterNotFrom: "aeiou")!
|
|
44
|
-
XCTAssertEqual(testString[index...], "Hello, world! Welcome to StringZilla. 👋")
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// TODO: This fails!
|
|
48
|
-
// func testFindLastCharacterNotFromSet() {
|
|
49
|
-
// let index = testString.findLast(characterNotFrom: "aeiou")!
|
|
50
|
-
// XCTAssertEqual(testString.distance(from: testString.startIndex, to: index), 38)
|
|
51
|
-
// XCTAssertEqual(testString[index...], "👋")
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
func testEditDistance() {
|
|
55
|
-
let otherString = "Hello, world!"
|
|
56
|
-
let distance = try? testString.editDistance(from: otherString) // Using try?
|
|
57
|
-
XCTAssertNotNil(distance)
|
|
58
|
-
XCTAssertEqual(distance, 29)
|
|
59
|
-
}
|
|
60
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Change this to match your project
|
|
3
|
-
"include": ["javascript/usearch.js"],
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
// Tells TypeScript to read JS files, as
|
|
6
|
-
// normally they are ignored as source files
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
// Generate d.ts files
|
|
9
|
-
"declaration": true,
|
|
10
|
-
// This compiler run should
|
|
11
|
-
// only output d.ts files
|
|
12
|
-
"emitDeclarationOnly": true,
|
|
13
|
-
// Types should go into this directory.
|
|
14
|
-
// Removing this would place the .d.ts files
|
|
15
|
-
// next to the .js files
|
|
16
|
-
"outDir": "javascript/types",
|
|
17
|
-
// go to js file when using IDE functions like
|
|
18
|
-
// "Go to Definition" in VSCode
|
|
19
|
-
"declarationMap": true
|
|
20
|
-
}
|
|
21
|
-
}
|
package/wasmer.toml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name="unum/usearch"
|
|
3
|
-
version="2.9.2"
|
|
4
|
-
description="Smaller & Faster Single-File Vector Search Engine from Unum"
|
|
5
|
-
license="Apache-2.0"
|
|
6
|
-
readme="README.md"
|
|
7
|
-
repository="https://github.com/unum-cloud/usearch"
|
|
8
|
-
homepage="https://unum-cloud.github.io/usearch/javascript"
|
|
9
|
-
|
|
10
|
-
[[module]]
|
|
11
|
-
name="index"
|
|
12
|
-
source="build/wasm/index.wasm"
|
package/winlibinstaller.bat
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
@echo off
|
|
2
|
-
|
|
3
|
-
rem Get latest release tag
|
|
4
|
-
set "repo_owner=unum-cloud"
|
|
5
|
-
set "repo_name=usearch"
|
|
6
|
-
|
|
7
|
-
rem Get the latest tag without quotes
|
|
8
|
-
for /f "delims=" %%i in ('curl -s https://api.github.com/repos/%repo_owner%/%repo_name%/releases/latest ^| findstr "tag_name"') do (
|
|
9
|
-
for /f "tokens=2 delims=:, " %%a in ("%%i") do (
|
|
10
|
-
set "latest_tag=%%~a"
|
|
11
|
-
)
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
rem Get Windows architecture
|
|
15
|
-
for /f "tokens=2 delims= " %%a in ('wmic OS get OSArchitecture ^| find "64"') do set "arch=x64"
|
|
16
|
-
if "%arch%"=="" set "arch=x86"
|
|
17
|
-
|
|
18
|
-
echo Split library version from release version!
|
|
19
|
-
timeout /t 1
|
|
20
|
-
rem Split the first 'v' from the version number.
|
|
21
|
-
for /f "tokens=1 delims=v" %%a in ('echo %latest_tag%') do (
|
|
22
|
-
set lib_version=%%a
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
echo Download usearch library archive!
|
|
26
|
-
rem Download the file.
|
|
27
|
-
timeout /t 2
|
|
28
|
-
curl -LO https://github.com/%repo_owner%/%repo_name%/releases/download/%latest_tag%/usearch_windows_%arch%_%lib_version%.tar
|
|
29
|
-
echo Download is complete!
|
|
30
|
-
|
|
31
|
-
echo Extract archive!
|
|
32
|
-
rem Extract archive.
|
|
33
|
-
timeout /t 1
|
|
34
|
-
tar -xf usearch_windows_%arch%_%lib_version%.tar
|
|
35
|
-
echo Extract is complete!
|
|
36
|
-
|
|
37
|
-
rem Remove the archive.
|
|
38
|
-
del usearch_windows_%arch%_%lib_version%.tar
|
|
39
|
-
|
|
40
|
-
echo Extraction complete and downloaded .tar file removed.
|
|
41
|
-
timeout /t 1
|
|
42
|
-
exit /b
|
|
File without changes
|
|
File without changes
|