k2hash 1.1.33 → 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/binding.gyp +106 -0
- package/build/cjs/index.js +296 -0
- package/build/esm/index.js +293 -0
- package/buildutils/make_node_prebuild_variables.sh +359 -0
- package/buildutils/node_prebuild.sh +371 -0
- package/buildutils/node_prebuild_install.sh +307 -0
- package/index.js +4 -1
- package/index.mjs +154 -0
- package/package.json +76 -20
- package/src/index.ts +378 -0
- package/src/k2h_cbs.cc +27 -41
- package/src/k2h_cbs.h +17 -13
- package/src/k2h_common.h +1 -1
- package/src/k2h_keyqueue.cc +513 -339
- package/src/k2h_keyqueue.h +38 -30
- package/src/k2h_keyqueue_async.h +222 -184
- package/src/k2h_queue.cc +483 -304
- package/src/k2h_queue.h +38 -30
- package/src/k2h_queue_async.h +218 -173
- package/src/k2h_shm.cc +1963 -1221
- package/src/k2h_shm.h +109 -104
- package/src/k2h_shm_async.h +722 -560
- package/src/k2hash.cc +22 -8
- package/src/k2hkeyqueue.cc +21 -8
- package/src/k2hqueue.cc +21 -8
- package/types/index.d.ts +570 -0
- package/ChangeLog +0 -131
- package/src/binding.gyp +0 -146
package/src/k2h_cbs.cc
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
#include <fullock/flckbaselist.tcc>
|
|
23
23
|
#include "k2h_cbs.h"
|
|
24
24
|
|
|
25
|
-
using namespace v8;
|
|
26
25
|
using namespace std;
|
|
27
26
|
using namespace fullock;
|
|
28
27
|
|
|
@@ -40,68 +39,55 @@ StackEmitCB::~StackEmitCB()
|
|
|
40
39
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
// This method does not lock, thus must lock before calling this.
|
|
45
|
-
//
|
|
46
|
-
Nan::Callback* StackEmitCB::RawFind(const char* pemitname)
|
|
42
|
+
bool StackEmitCB::Set(const std::string& emitter, const Napi::Function& cb)
|
|
47
43
|
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
while(!flck_trylock_noshared_mutex(&lockval)); // LOCK
|
|
45
|
+
|
|
46
|
+
// clear if existed
|
|
47
|
+
auto it = EmitCbsMap.find(emitter);
|
|
48
|
+
if(EmitCbsMap.end() != it){
|
|
49
|
+
it->second.Reset();
|
|
50
|
+
EmitCbsMap.erase(it);
|
|
55
51
|
}
|
|
56
|
-
return cbfunc;
|
|
57
|
-
}
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
// Insert new persistent reference
|
|
54
|
+
Napi::FunctionReference ref = Napi::Persistent(cb);
|
|
55
|
+
EmitCbsMap.emplace(emitter, std::move(ref));
|
|
56
|
+
|
|
63
57
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
64
58
|
|
|
65
|
-
return
|
|
59
|
+
return true;
|
|
66
60
|
}
|
|
67
61
|
|
|
68
|
-
bool StackEmitCB::
|
|
62
|
+
bool StackEmitCB::Unset(const std::string& emitter)
|
|
69
63
|
{
|
|
70
|
-
string stremit = pemitname ? pemitname : "";
|
|
71
|
-
if(stremit.empty()){
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
64
|
while(!flck_trylock_noshared_mutex(&lockval)); // LOCK
|
|
76
65
|
|
|
77
|
-
|
|
78
|
-
if(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if(cbfunc){
|
|
82
|
-
EmitCbsMap[stremit] = cbfunc;
|
|
66
|
+
auto it = EmitCbsMap.find(emitter);
|
|
67
|
+
if(EmitCbsMap.end() == it){
|
|
68
|
+
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
69
|
+
return false;
|
|
83
70
|
}
|
|
71
|
+
it->second.Reset();
|
|
72
|
+
EmitCbsMap.erase(it);
|
|
73
|
+
|
|
84
74
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
85
75
|
|
|
86
76
|
return true;
|
|
87
77
|
}
|
|
88
78
|
|
|
89
|
-
|
|
79
|
+
Napi::FunctionReference* StackEmitCB::Find(const std::string& emitter)
|
|
90
80
|
{
|
|
91
|
-
string stremit = pemitname ? pemitname : "";
|
|
92
|
-
if(stremit.empty()){
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
81
|
while(!flck_trylock_noshared_mutex(&lockval)); // LOCK
|
|
97
82
|
|
|
98
|
-
|
|
99
|
-
if(
|
|
100
|
-
|
|
83
|
+
auto it = EmitCbsMap.find(emitter);
|
|
84
|
+
if(EmitCbsMap.end() == it){
|
|
85
|
+
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
86
|
+
return nullptr;
|
|
101
87
|
}
|
|
102
88
|
flck_unlock_noshared_mutex(&lockval); // UNLOCK
|
|
103
89
|
|
|
104
|
-
return
|
|
90
|
+
return &it->second;
|
|
105
91
|
}
|
|
106
92
|
|
|
107
93
|
/*
|
package/src/k2h_cbs.h
CHANGED
|
@@ -21,32 +21,36 @@
|
|
|
21
21
|
#ifndef K2H_CBS_H
|
|
22
22
|
#define K2H_CBS_H
|
|
23
23
|
|
|
24
|
+
#include <string>
|
|
25
|
+
#include <unordered_map>
|
|
24
26
|
#include "k2h_common.h"
|
|
25
27
|
|
|
26
28
|
//---------------------------------------------------------
|
|
27
29
|
// Typedefs
|
|
28
30
|
//---------------------------------------------------------
|
|
29
|
-
typedef std::
|
|
31
|
+
typedef std::unordered_map<std::string, Napi::FunctionReference> cbsmap;
|
|
30
32
|
|
|
31
33
|
//---------------------------------------------------------
|
|
32
34
|
// StackEmitCB Class
|
|
33
35
|
//---------------------------------------------------------
|
|
34
36
|
class StackEmitCB
|
|
35
37
|
{
|
|
36
|
-
protected:
|
|
37
|
-
cbsmap EmitCbsMap;
|
|
38
|
-
volatile int lockval; // lock variable for mapping
|
|
39
|
-
|
|
40
|
-
protected:
|
|
41
|
-
Nan::Callback* RawFind(const char* pemitname);
|
|
42
|
-
|
|
43
38
|
public:
|
|
44
39
|
StackEmitCB();
|
|
45
40
|
virtual ~StackEmitCB();
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
bool Set(const
|
|
49
|
-
|
|
42
|
+
// Set returns true if set succeeded
|
|
43
|
+
bool Set(const std::string& emitter, const Napi::Function& cb);
|
|
44
|
+
|
|
45
|
+
// Unset returns true if removed
|
|
46
|
+
bool Unset(const std::string& emitter);
|
|
47
|
+
|
|
48
|
+
// Find returns pointer to FunctionReference if set, otherwise nullptr
|
|
49
|
+
Napi::FunctionReference* Find(const std::string& emitter);
|
|
50
|
+
|
|
51
|
+
private:
|
|
52
|
+
cbsmap EmitCbsMap;
|
|
53
|
+
volatile int lockval; // lock variable for mapping
|
|
50
54
|
};
|
|
51
55
|
|
|
52
56
|
//---------------------------------------------------------
|
|
@@ -55,14 +59,14 @@ class StackEmitCB
|
|
|
55
59
|
inline const char* GetNormalizationEmitter(const char* emitter, const char* emitters[])
|
|
56
60
|
{
|
|
57
61
|
if(!emitter){
|
|
58
|
-
return
|
|
62
|
+
return nullptr;
|
|
59
63
|
}
|
|
60
64
|
for(const char** ptmp = &emitters[0]; ptmp && *ptmp; ++ptmp){
|
|
61
65
|
if(0 == strcasecmp(*ptmp, emitter)){
|
|
62
66
|
return *ptmp;
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
|
-
return
|
|
69
|
+
return nullptr;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
#endif
|