koffi 1.3.10 → 2.0.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/CMakeLists.txt +7 -2
- package/ChangeLog.md +52 -14
- package/README.md +6 -0
- package/build/qemu/2.0.0/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.0.0/koffi_win32_x64.tar.gz +0 -0
- package/doc/benchmarks.md +2 -2
- package/doc/changes.md +156 -1
- package/doc/contribute.md +0 -1
- package/doc/dist/doctrees/changes.doctree +0 -0
- package/doc/dist/doctrees/environment.pickle +0 -0
- package/doc/dist/doctrees/functions.doctree +0 -0
- package/doc/dist/doctrees/types.doctree +0 -0
- package/doc/dist/html/_sources/changes.md.txt +156 -1
- package/doc/dist/html/_sources/functions.md.txt +8 -4
- package/doc/dist/html/_sources/types.md.txt +9 -0
- package/doc/dist/html/benchmarks.html +1 -1
- package/doc/dist/html/changes.html +226 -14
- package/doc/dist/html/contribute.html +1 -1
- package/doc/dist/html/functions.html +15 -12
- package/doc/dist/html/genindex.html +1 -1
- package/doc/dist/html/index.html +6 -16
- package/doc/dist/html/memory.html +3 -3
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +1 -1
- package/doc/dist/html/search.html +1 -1
- package/doc/dist/html/searchindex.js +1 -1
- package/doc/dist/html/start.html +1 -1
- package/doc/dist/html/types.html +11 -3
- package/doc/functions.md +137 -13
- package/doc/types.md +35 -10
- package/package.json +9 -7
- package/qemu/registry/machines.json +5 -5
- package/qemu/registry/sha256sum.txt +16 -16
- package/src/abi_arm32.cc +90 -18
- package/src/abi_arm32_fwd.S +121 -57
- package/src/abi_arm64.cc +90 -18
- package/src/abi_arm64_fwd.S +96 -0
- package/src/abi_arm64_fwd.asm +128 -0
- package/src/abi_riscv64.cc +88 -18
- package/src/abi_riscv64_fwd.S +96 -0
- package/src/abi_x64_sysv.cc +93 -21
- package/src/abi_x64_sysv_fwd.S +96 -0
- package/src/abi_x64_win.cc +88 -18
- package/src/abi_x64_win_fwd.asm +128 -0
- package/src/abi_x86.cc +93 -18
- package/src/abi_x86_fwd.S +96 -0
- package/src/abi_x86_fwd.asm +128 -0
- package/src/call.cc +97 -63
- package/src/call.hh +2 -1
- package/src/ffi.cc +452 -140
- package/src/ffi.hh +23 -9
- package/src/parser.cc +20 -42
- package/src/util.cc +117 -27
- package/src/util.hh +3 -2
- package/test/callbacks.js +54 -8
- package/test/misc.c +30 -15
- package/test/raylib.js +1 -1
- package/test/sqlite.js +24 -16
- package/test/sync.js +43 -33
- package/vendor/libcc/libcc.cc +18 -5
- package/vendor/libcc/libcc.hh +70 -23
- package/build/qemu/1.3.10/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.3.10/koffi_win32_x64.tar.gz +0 -0
package/test/sync.js
CHANGED
|
@@ -64,7 +64,7 @@ const BFG = koffi.struct('BFG', {
|
|
|
64
64
|
a: 'int8_t',
|
|
65
65
|
b: 'int64_t',
|
|
66
66
|
c: 'char',
|
|
67
|
-
d: '
|
|
67
|
+
d: 'const char *',
|
|
68
68
|
e: 'short',
|
|
69
69
|
inner: koffi.struct({
|
|
70
70
|
f: 'float',
|
|
@@ -75,13 +75,14 @@ const PackedBFG = koffi.pack('PackedBFG', {
|
|
|
75
75
|
a: 'int8_t',
|
|
76
76
|
b: 'int64_t',
|
|
77
77
|
c: 'char',
|
|
78
|
-
d: '
|
|
78
|
+
d: 'char *',
|
|
79
79
|
e: 'short',
|
|
80
80
|
inner: koffi.pack({
|
|
81
81
|
f: 'float',
|
|
82
82
|
g: 'double'
|
|
83
83
|
})
|
|
84
84
|
});
|
|
85
|
+
const AliasBFG = koffi.alias('AliasBFG', PackedBFG);
|
|
85
86
|
|
|
86
87
|
const FixedString = koffi.struct('FixedString', {
|
|
87
88
|
buf: koffi.array('int8', 64)
|
|
@@ -106,9 +107,12 @@ const IntContainer = koffi.struct('IntContainer', {
|
|
|
106
107
|
len: 'int'
|
|
107
108
|
});
|
|
108
109
|
|
|
110
|
+
const StrFree = koffi.disposable('str_free', koffi.types.str, koffi.free);
|
|
111
|
+
const Str16Free = koffi.disposable('str16_free', 'str16');
|
|
112
|
+
|
|
109
113
|
const StrStruct = koffi.struct('StrStruct', {
|
|
110
114
|
str: 'str',
|
|
111
|
-
str16:
|
|
115
|
+
str16: koffi.types.string16
|
|
112
116
|
});
|
|
113
117
|
|
|
114
118
|
main();
|
|
@@ -130,7 +134,7 @@ async function test() {
|
|
|
130
134
|
const GetMinusOne1 = lib.func('int8_t GetMinusOne1(void)');
|
|
131
135
|
const GetMinusOne2 = lib.func('int16_t GetMinusOne2(void)');
|
|
132
136
|
const GetMinusOne4 = lib.func('int32_t GetMinusOne4(void)');
|
|
133
|
-
const GetMinusOne8 = lib.func('int64_t GetMinusOne8(void)');
|
|
137
|
+
const GetMinusOne8 = lib.func('int64_t GetMinusOne8(void *dummy)');
|
|
134
138
|
const FillPack1 = lib.func('FillPack1', 'void', ['int', koffi.out(koffi.pointer(Pack1))]);
|
|
135
139
|
const RetPack1 = lib.func('RetPack1', Pack1, ['int']);
|
|
136
140
|
const AddPack1 = lib.fastcall('AddPack1', 'void', ['int', koffi.inout(koffi.pointer(Pack1))]);
|
|
@@ -155,12 +159,12 @@ async function test() {
|
|
|
155
159
|
const ConcatenateToStr4 = lib.func('ConcatenateToStr4', 'str', [...Array(8).fill('int32_t'), koffi.pointer(koffi.struct('IJK4', {i: 'int32_t', j: 'int32_t', k: 'int32_t'})), 'int32_t']);
|
|
156
160
|
const ConcatenateToStr8 = lib.func('ConcatenateToStr8', 'str', [...Array(8).fill('int64_t'), koffi.struct('IJK8', {i: 'int64_t', j: 'int64_t', k: 'int64_t'}), 'int64_t']);
|
|
157
161
|
const MakeBFG = lib.func('BFG __stdcall MakeBFG(_Out_ BFG *p, int x, double y, const char *str)');
|
|
158
|
-
const MakePackedBFG = lib.func('
|
|
162
|
+
const MakePackedBFG = lib.func('AliasBFG __fastcall MakePackedBFG(int x, double y, _Out_ PackedBFG *p, const char *str)');
|
|
159
163
|
const ReturnBigString = process.platform == 'win32' ?
|
|
160
|
-
lib.stdcall(1, 'str', ['str']) :
|
|
164
|
+
lib.stdcall(1, koffi.disposable('str', koffi.free), ['str']) :
|
|
161
165
|
lib.func('const char * __stdcall ReturnBigString(const char *str)');
|
|
162
|
-
const PrintFmt = lib.func('
|
|
163
|
-
const Concat16 = lib.func('const char16_t
|
|
166
|
+
const PrintFmt = lib.func('str_free PrintFmt(const char *fmt, ...)');
|
|
167
|
+
const Concat16 = lib.func('const char16_t *! Concat16(const char16_t *str1, const char16_t *str2)')
|
|
164
168
|
const ReturnFixedStr = lib.func('FixedString ReturnFixedStr(FixedString str)');
|
|
165
169
|
const ReturnFixedStr2 = lib.func('FixedString2 ReturnFixedStr(FixedString2 str)');
|
|
166
170
|
const ReturnFixedWide = lib.func('FixedWide ReturnFixedWide(FixedWide str)');
|
|
@@ -187,7 +191,7 @@ async function test() {
|
|
|
187
191
|
assert.equal(GetMinusOne1(), -1);
|
|
188
192
|
assert.equal(GetMinusOne2(), -1);
|
|
189
193
|
assert.equal(GetMinusOne4(), -1);
|
|
190
|
-
assert.equal(GetMinusOne8(), -1);
|
|
194
|
+
assert.equal(GetMinusOne8(null), -1);
|
|
191
195
|
|
|
192
196
|
// Simple tests with Pack1
|
|
193
197
|
{
|
|
@@ -320,30 +324,36 @@ async function test() {
|
|
|
320
324
|
|
|
321
325
|
// Big numbers
|
|
322
326
|
{
|
|
323
|
-
assert.
|
|
324
|
-
assert.
|
|
325
|
-
assert.
|
|
326
|
-
assert.
|
|
327
|
-
|
|
328
|
-
assert.
|
|
329
|
-
assert.
|
|
330
|
-
assert.
|
|
331
|
-
assert.
|
|
332
|
-
|
|
333
|
-
assert.
|
|
334
|
-
assert.
|
|
335
|
-
assert.
|
|
336
|
-
assert.
|
|
337
|
-
|
|
338
|
-
assert.
|
|
339
|
-
assert.
|
|
340
|
-
|
|
341
|
-
assert.
|
|
342
|
-
|
|
343
|
-
assert.
|
|
344
|
-
assert.
|
|
345
|
-
assert.
|
|
346
|
-
assert.
|
|
327
|
+
assert.strictEqual(ThroughUInt32UU(4294967284), 4294967284);
|
|
328
|
+
assert.deepStrictEqual(ThroughUInt32SS({ v: 4294967284 }), { v: 4294967284 });
|
|
329
|
+
assert.deepStrictEqual(ThroughUInt32SU(4294967284), { v: 4294967284 });
|
|
330
|
+
assert.strictEqual(ThroughUInt32US({ v: 4294967284 }), 4294967284);
|
|
331
|
+
|
|
332
|
+
assert.strictEqual(ThroughUInt64UU(9007199254740992n), 9007199254740992);
|
|
333
|
+
assert.deepStrictEqual(ThroughUInt64SS({ v: 9007199254740992n }), { v: 9007199254740992 });
|
|
334
|
+
assert.deepStrictEqual(ThroughUInt64SU(9007199254740992n), { v: 9007199254740992 });
|
|
335
|
+
assert.strictEqual(ThroughUInt64US({ v: 9007199254740992n }), 9007199254740992);
|
|
336
|
+
assert.strictEqual(ThroughUInt64UU(9007199254740993n), 9007199254740993n);
|
|
337
|
+
assert.deepStrictEqual(ThroughUInt64SS({ v: 9007199254740993n }), { v: 9007199254740993n });
|
|
338
|
+
assert.deepStrictEqual(ThroughUInt64SU(9007199254740993n), { v: 9007199254740993n });
|
|
339
|
+
assert.strictEqual(ThroughUInt64US({ v: 9007199254740993n }), 9007199254740993n);
|
|
340
|
+
assert.strictEqual(ThroughUInt64UU(18446744073709551598n), 18446744073709551598n);
|
|
341
|
+
assert.deepStrictEqual(ThroughUInt64SS({ v: 18446744073709551598n }), { v: 18446744073709551598n });
|
|
342
|
+
assert.deepStrictEqual(ThroughUInt64SU(18446744073709551598n), { v: 18446744073709551598n });
|
|
343
|
+
assert.strictEqual(ThroughUInt64US({ v: 18446744073709551598n }), 18446744073709551598n);
|
|
344
|
+
|
|
345
|
+
assert.strictEqual(ThroughInt64II(-9007199254740992), -9007199254740992);
|
|
346
|
+
assert.deepStrictEqual(ThroughInt64SS({ v: -9007199254740992 }), { v: -9007199254740992 });
|
|
347
|
+
assert.deepStrictEqual(ThroughInt64SI(-9007199254740992), { v: -9007199254740992 });
|
|
348
|
+
assert.strictEqual(ThroughInt64IS({ v: -9007199254740992 }), -9007199254740992);
|
|
349
|
+
assert.strictEqual(ThroughInt64II(-9007199254740993n), -9007199254740993n);
|
|
350
|
+
assert.deepStrictEqual(ThroughInt64SS({ v: -9007199254740993n }), { v: -9007199254740993n });
|
|
351
|
+
assert.deepStrictEqual(ThroughInt64SI(-9007199254740993n), { v: -9007199254740993n });
|
|
352
|
+
assert.strictEqual(ThroughInt64IS({ v: -9007199254740993n }), -9007199254740993n);
|
|
353
|
+
assert.strictEqual(ThroughInt64II(-9223372036854775803n), -9223372036854775803n);
|
|
354
|
+
assert.deepStrictEqual(ThroughInt64SS({ v: -9223372036854775803n }), { v: -9223372036854775803n });
|
|
355
|
+
assert.deepStrictEqual(ThroughInt64SI(-9223372036854775803n), { v: -9223372036854775803n });
|
|
356
|
+
assert.strictEqual(ThroughInt64IS({ v: -9223372036854775803n }), -9223372036854775803n);
|
|
347
357
|
}
|
|
348
358
|
|
|
349
359
|
// Array pointers as input
|
package/vendor/libcc/libcc.cc
CHANGED
|
@@ -136,7 +136,7 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond)
|
|
|
136
136
|
|
|
137
137
|
class MallocAllocator: public Allocator {
|
|
138
138
|
protected:
|
|
139
|
-
void *Allocate(Size size, unsigned int flags
|
|
139
|
+
void *Allocate(Size size, unsigned int flags) override
|
|
140
140
|
{
|
|
141
141
|
void *ptr = malloc((size_t)size);
|
|
142
142
|
RG_CRITICAL(ptr, "Failed to allocate %1 of memory", FmtMemSize(size));
|
|
@@ -148,7 +148,7 @@ protected:
|
|
|
148
148
|
return ptr;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags
|
|
151
|
+
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override
|
|
152
152
|
{
|
|
153
153
|
if (!new_size) {
|
|
154
154
|
Release(*ptr, old_size);
|
|
@@ -172,12 +172,25 @@ protected:
|
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
+
class NullAllocator: public Allocator {
|
|
176
|
+
protected:
|
|
177
|
+
void *Allocate(Size, unsigned int) override { RG_UNREACHABLE(); }
|
|
178
|
+
void Resize(void **, Size, Size, unsigned int) override { RG_UNREACHABLE(); }
|
|
179
|
+
void Release(void *, Size) override {}
|
|
180
|
+
};
|
|
181
|
+
|
|
175
182
|
Allocator *GetDefaultAllocator()
|
|
176
183
|
{
|
|
177
184
|
static Allocator *default_allocator = new RG_DEFAULT_ALLOCATOR;
|
|
178
185
|
return default_allocator;
|
|
179
186
|
}
|
|
180
187
|
|
|
188
|
+
Allocator *GetNullAllocator()
|
|
189
|
+
{
|
|
190
|
+
static Allocator *null_allocator = new NullAllocator;
|
|
191
|
+
return null_allocator;
|
|
192
|
+
}
|
|
193
|
+
|
|
181
194
|
LinkedAllocator& LinkedAllocator::operator=(LinkedAllocator &&other)
|
|
182
195
|
{
|
|
183
196
|
ReleaseAll();
|
|
@@ -639,13 +652,13 @@ TimeSpec DecomposeTime(int64_t time, TimeMode mode)
|
|
|
639
652
|
#ifdef _WIN32
|
|
640
653
|
__time64_t time64 = time / 1000;
|
|
641
654
|
|
|
642
|
-
struct tm ti = {
|
|
655
|
+
struct tm ti = {};
|
|
643
656
|
int offset = INT_MAX;
|
|
644
657
|
switch (mode) {
|
|
645
658
|
case TimeMode::Local: {
|
|
646
659
|
_localtime64_s(&ti, &time64);
|
|
647
660
|
|
|
648
|
-
struct tm utc = {
|
|
661
|
+
struct tm utc = {};
|
|
649
662
|
_gmtime64_s(&utc, &time64);
|
|
650
663
|
|
|
651
664
|
offset = (int)(_mktime64(&ti) - _mktime64(&utc) + (3600 * ti.tm_isdst));
|
|
@@ -660,7 +673,7 @@ TimeSpec DecomposeTime(int64_t time, TimeMode mode)
|
|
|
660
673
|
#else
|
|
661
674
|
time_t time64 = time / 1000;
|
|
662
675
|
|
|
663
|
-
struct tm ti = {
|
|
676
|
+
struct tm ti = {};
|
|
664
677
|
int offset = 0;
|
|
665
678
|
switch (mode) {
|
|
666
679
|
case TimeMode::Local: {
|
package/vendor/libcc/libcc.hh
CHANGED
|
@@ -235,7 +235,7 @@ extern "C" void AssertMessage(const char *filename, int line, const char *cond);
|
|
|
235
235
|
RG_DEBUG_BREAK(); \
|
|
236
236
|
abort(); \
|
|
237
237
|
} while (false)
|
|
238
|
-
#elif defined(__GNUC__)
|
|
238
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
239
239
|
#define RG_UNREACHABLE() __builtin_unreachable()
|
|
240
240
|
#else
|
|
241
241
|
#define RG_UNREACHABLE() __assume(0)
|
|
@@ -622,6 +622,7 @@ struct Vec3 {
|
|
|
622
622
|
class Allocator;
|
|
623
623
|
|
|
624
624
|
Allocator *GetDefaultAllocator();
|
|
625
|
+
Allocator *GetNullAllocator();
|
|
625
626
|
|
|
626
627
|
class Allocator {
|
|
627
628
|
RG_DELETE_COPY(Allocator)
|
|
@@ -696,8 +697,8 @@ public:
|
|
|
696
697
|
void ReleaseAll();
|
|
697
698
|
|
|
698
699
|
protected:
|
|
699
|
-
void *Allocate(Size size, unsigned int flags
|
|
700
|
-
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags
|
|
700
|
+
void *Allocate(Size size, unsigned int flags) override;
|
|
701
|
+
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override;
|
|
701
702
|
void Release(void *ptr, Size size) override;
|
|
702
703
|
|
|
703
704
|
private:
|
|
@@ -724,8 +725,8 @@ public:
|
|
|
724
725
|
}
|
|
725
726
|
|
|
726
727
|
protected:
|
|
727
|
-
void *Allocate(Size size, unsigned int flags
|
|
728
|
-
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags
|
|
728
|
+
void *Allocate(Size size, unsigned int flags) override;
|
|
729
|
+
void Resize(void **ptr, Size old_size, Size new_size, unsigned int flags) override;
|
|
729
730
|
void Release(void *ptr, Size size) override;
|
|
730
731
|
|
|
731
732
|
void CopyFrom(BlockAllocatorBase *other);
|
|
@@ -2020,9 +2021,11 @@ public:
|
|
|
2020
2021
|
Iterator<HashTable> end() { return Iterator<HashTable>(this, capacity); }
|
|
2021
2022
|
Iterator<const HashTable> end() const { return Iterator<const HashTable>(this, capacity); }
|
|
2022
2023
|
|
|
2023
|
-
|
|
2024
|
+
template <typename T = KeyType>
|
|
2025
|
+
ValueType *Find(const T &key)
|
|
2024
2026
|
{ return (ValueType *)((const HashTable *)this)->Find(key); }
|
|
2025
|
-
|
|
2027
|
+
template <typename T = KeyType>
|
|
2028
|
+
const ValueType *Find(const T &key) const
|
|
2026
2029
|
{
|
|
2027
2030
|
if (!capacity)
|
|
2028
2031
|
return nullptr;
|
|
@@ -2031,9 +2034,11 @@ public:
|
|
|
2031
2034
|
Size idx = HashToIndex(hash);
|
|
2032
2035
|
return Find(&idx, key);
|
|
2033
2036
|
}
|
|
2034
|
-
|
|
2037
|
+
template <typename T = KeyType>
|
|
2038
|
+
ValueType FindValue(const T &key, const ValueType &default_value)
|
|
2035
2039
|
{ return (ValueType)((const HashTable *)this)->FindValue(key, default_value); }
|
|
2036
|
-
|
|
2040
|
+
template <typename T = KeyType>
|
|
2041
|
+
const ValueType FindValue(const T &key, const ValueType &default_value) const
|
|
2037
2042
|
{
|
|
2038
2043
|
const ValueType *it = Find(key);
|
|
2039
2044
|
return it ? *it : default_value;
|
|
@@ -2104,7 +2109,8 @@ public:
|
|
|
2104
2109
|
MarkEmpty(empty_idx);
|
|
2105
2110
|
new (&data[empty_idx]) ValueType();
|
|
2106
2111
|
}
|
|
2107
|
-
|
|
2112
|
+
template <typename T = KeyType>
|
|
2113
|
+
void Remove(const T &key) { Remove(Find(key)); }
|
|
2108
2114
|
|
|
2109
2115
|
void Trim()
|
|
2110
2116
|
{
|
|
@@ -2126,9 +2132,11 @@ public:
|
|
|
2126
2132
|
Size IsEmpty(Size idx) const { return IsEmpty(used, idx); }
|
|
2127
2133
|
|
|
2128
2134
|
private:
|
|
2129
|
-
|
|
2135
|
+
template <typename T = KeyType>
|
|
2136
|
+
ValueType *Find(Size *idx, const T &key)
|
|
2130
2137
|
{ return (ValueType *)((const HashTable *)this)->Find(idx, key); }
|
|
2131
|
-
|
|
2138
|
+
template <typename T = KeyType>
|
|
2139
|
+
const ValueType *Find(Size *idx, const T &key) const
|
|
2132
2140
|
{
|
|
2133
2141
|
#if __cplusplus >= 201703L
|
|
2134
2142
|
if constexpr(std::is_pointer<ValueType>::value) {
|
|
@@ -2341,6 +2349,16 @@ template <>
|
|
|
2341
2349
|
class HashTraits<const char *> {
|
|
2342
2350
|
public:
|
|
2343
2351
|
// FNV-1a
|
|
2352
|
+
static uint64_t Hash(Span<const char> key)
|
|
2353
|
+
{
|
|
2354
|
+
uint64_t hash = 0xCBF29CE484222325ull;
|
|
2355
|
+
for (char c: key) {
|
|
2356
|
+
hash ^= (uint64_t)c;
|
|
2357
|
+
hash *= 0x100000001B3ull;
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
return hash;
|
|
2361
|
+
}
|
|
2344
2362
|
static uint64_t Hash(const char *key)
|
|
2345
2363
|
{
|
|
2346
2364
|
uint64_t hash = 0xCBF29CE484222325ull;
|
|
@@ -2353,6 +2371,7 @@ public:
|
|
|
2353
2371
|
}
|
|
2354
2372
|
|
|
2355
2373
|
static bool Test(const char *key1, const char *key2) { return !strcmp(key1, key2); }
|
|
2374
|
+
static bool Test(const char *key1, Span<const char> key2) { return key2 == key1; }
|
|
2356
2375
|
};
|
|
2357
2376
|
|
|
2358
2377
|
template <>
|
|
@@ -2369,6 +2388,16 @@ public:
|
|
|
2369
2388
|
|
|
2370
2389
|
return hash;
|
|
2371
2390
|
}
|
|
2391
|
+
static uint64_t Hash(const char *key)
|
|
2392
|
+
{
|
|
2393
|
+
uint64_t hash = 0xCBF29CE484222325ull;
|
|
2394
|
+
for (Size i = 0; key[i]; i++) {
|
|
2395
|
+
hash ^= (uint64_t)key[i];
|
|
2396
|
+
hash *= 0x100000001B3ull;
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
return hash;
|
|
2400
|
+
}
|
|
2372
2401
|
|
|
2373
2402
|
static bool Test(Span<const char> key1, Span<const char> key2) { return key1 == key2; }
|
|
2374
2403
|
static bool Test(Span<const char> key1, const char * key2) { return key1 == key2; }
|
|
@@ -2381,9 +2410,11 @@ public:
|
|
|
2381
2410
|
{ return (KeyType)(value.KeyMember); } \
|
|
2382
2411
|
static KeyType GetKey(const ValueType *value) \
|
|
2383
2412
|
{ return (KeyType)(value->KeyMember); } \
|
|
2384
|
-
|
|
2413
|
+
template <typename TestKey> \
|
|
2414
|
+
static uint64_t HashKey(TestKey key) \
|
|
2385
2415
|
{ return HashFunc(key); } \
|
|
2386
|
-
|
|
2416
|
+
template <typename TestKey> \
|
|
2417
|
+
static bool TestKeys(KeyType key1, TestKey key2) \
|
|
2387
2418
|
{ return TestFunc((key1), (key2)); } \
|
|
2388
2419
|
}
|
|
2389
2420
|
#define RG_HASHTABLE_HANDLER_EX(ValueType, KeyType, KeyMember, HashFunc, TestFunc) \
|
|
@@ -2420,16 +2451,20 @@ public:
|
|
|
2420
2451
|
void Clear() { table.Clear(); }
|
|
2421
2452
|
void RemoveAll() { table.RemoveAll(); }
|
|
2422
2453
|
|
|
2423
|
-
|
|
2454
|
+
template <typename T = KeyType>
|
|
2455
|
+
ValueType *Find(const T &key)
|
|
2424
2456
|
{ return (ValueType *)((const HashMap *)this)->Find(key); }
|
|
2425
|
-
|
|
2457
|
+
template <typename T = KeyType>
|
|
2458
|
+
const ValueType *Find(const T &key) const
|
|
2426
2459
|
{
|
|
2427
2460
|
const Bucket *table_it = table.Find(key);
|
|
2428
2461
|
return table_it ? &table_it->value : nullptr;
|
|
2429
2462
|
}
|
|
2430
|
-
|
|
2463
|
+
template <typename T = KeyType>
|
|
2464
|
+
ValueType FindValue(const T &key, const ValueType &default_value)
|
|
2431
2465
|
{ return (ValueType)((const HashMap *)this)->FindValue(key, default_value); }
|
|
2432
|
-
|
|
2466
|
+
template <typename T = KeyType>
|
|
2467
|
+
const ValueType FindValue(const T &key, const ValueType &default_value) const
|
|
2433
2468
|
{
|
|
2434
2469
|
const ValueType *it = Find(key);
|
|
2435
2470
|
return it ? *it : default_value;
|
|
@@ -2462,6 +2497,7 @@ public:
|
|
|
2462
2497
|
return;
|
|
2463
2498
|
table.Remove((Bucket *)((uint8_t *)it - RG_OFFSET_OF(Bucket, value)));
|
|
2464
2499
|
}
|
|
2500
|
+
template <typename T = KeyType>
|
|
2465
2501
|
void Remove(const KeyType &key) { Remove(Find(key)); }
|
|
2466
2502
|
|
|
2467
2503
|
void Trim() { table.Trim(); }
|
|
@@ -2493,18 +2529,23 @@ public:
|
|
|
2493
2529
|
void Clear() { table.Clear(); }
|
|
2494
2530
|
void RemoveAll() { table.RemoveAll(); }
|
|
2495
2531
|
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2532
|
+
template <typename T = ValueType>
|
|
2533
|
+
ValueType *Find(const T &value) { return table.Find(value); }
|
|
2534
|
+
template <typename T = ValueType>
|
|
2535
|
+
const ValueType *Find(const T &value) const { return table.Find(value); }
|
|
2536
|
+
template <typename T = ValueType>
|
|
2537
|
+
ValueType FindValue(const T &value, const ValueType &default_value)
|
|
2499
2538
|
{ return table.FindValue(value, default_value); }
|
|
2500
|
-
|
|
2539
|
+
template <typename T = ValueType>
|
|
2540
|
+
const ValueType FindValue(const T &value, const ValueType &default_value) const
|
|
2501
2541
|
{ return table.FindValue(value, default_value); }
|
|
2502
2542
|
|
|
2503
2543
|
ValueType *Set(const ValueType &value) { return table.Set(value); }
|
|
2504
2544
|
std::pair<ValueType *, bool> TrySet(const ValueType &value) { return table.TrySet(value); }
|
|
2505
2545
|
|
|
2506
2546
|
void Remove(ValueType *it) { table.Remove(it); }
|
|
2507
|
-
|
|
2547
|
+
template <typename T = ValueType>
|
|
2548
|
+
void Remove(const T &value) { Remove(Find(value)); }
|
|
2508
2549
|
|
|
2509
2550
|
void Trim() { table.Trim(); }
|
|
2510
2551
|
};
|
|
@@ -3363,6 +3404,8 @@ static inline bool TestStr(Span<const char> str1, const char *str2)
|
|
|
3363
3404
|
}
|
|
3364
3405
|
return (i == str1.len) && !str2[i];
|
|
3365
3406
|
}
|
|
3407
|
+
static inline bool TestStr(const char *str1, Span<const char> str2)
|
|
3408
|
+
{ return TestStr(str2, str1); }
|
|
3366
3409
|
static inline bool TestStr(const char *str1, const char *str2)
|
|
3367
3410
|
{ return !strcmp(str1, str2); }
|
|
3368
3411
|
|
|
@@ -3392,6 +3435,8 @@ static inline bool TestStrI(Span<const char> str1, const char *str2)
|
|
|
3392
3435
|
}
|
|
3393
3436
|
return (i == str1.len) && !str2[i];
|
|
3394
3437
|
}
|
|
3438
|
+
static inline bool TestStrI(const char *str1, Span<const char> str2)
|
|
3439
|
+
{ return TestStr(str2, str1); }
|
|
3395
3440
|
static inline bool TestStrI(const char *str1, const char *str2)
|
|
3396
3441
|
{
|
|
3397
3442
|
Size i = 0;
|
|
@@ -3431,6 +3476,8 @@ static inline int CmpStr(Span<const char> str1, const char *str2)
|
|
|
3431
3476
|
return str1[i];
|
|
3432
3477
|
}
|
|
3433
3478
|
}
|
|
3479
|
+
static inline int CmpStr(const char *str1, Span<const char> str2)
|
|
3480
|
+
{ return -CmpStr(str2, str1); }
|
|
3434
3481
|
static inline int CmpStr(const char *str1, const char *str2)
|
|
3435
3482
|
{ return strcmp(str1, str2); }
|
|
3436
3483
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|