-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_wasm.cpp
More file actions
75 lines (60 loc) · 1.66 KB
/
Copy pathhash_wasm.cpp
File metadata and controls
75 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <emscripten/bind.h>
#include <sstream>
#include "Hashtable.h"
using namespace emscripten;
// Wrapper class to expose Hashtable with JS-friendly methods
class HashtableWrapper {
private:
Hashtable* table;
public:
HashtableWrapper() {
table = new Hashtable();
}
HashtableWrapper(int capacity) {
table = new Hashtable(capacity);
}
~HashtableWrapper() {
delete table;
}
void insert(int value) {
table->insert(value);
}
void remove(int value) {
table->remove(value);
}
bool contains(int value) {
return table->contains(value);
}
int indexOf(int value) {
return table->indexOf(value);
}
int size() {
return table->size();
}
int capacity() {
return table->capacity();
}
bool empty() {
return table->empty();
}
void clear() {
table->clear();
}
double getLoadFactorThreshold() {
return table->getLoadFactorThreshold();
}
};
EMSCRIPTEN_BINDINGS(hash_module) {
class_<HashtableWrapper>("Hashtable")
.constructor<>()
.constructor<int>()
.function("insert", &HashtableWrapper::insert)
.function("remove", &HashtableWrapper::remove)
.function("contains", &HashtableWrapper::contains)
.function("indexOf", &HashtableWrapper::indexOf)
.function("size", &HashtableWrapper::size)
.function("capacity", &HashtableWrapper::capacity)
.function("empty", &HashtableWrapper::empty)
.function("clear", &HashtableWrapper::clear)
.function("getLoadFactorThreshold", &HashtableWrapper::getLoadFactorThreshold);
}