【发布时间】:2019-01-28 16:12:30
【问题描述】:
我想在我的 javascript 项目中使用 dawg。我使用 Emscripten 将 dawg 代码 here 转换为 webassembly。
该项目提供了一个库 dawgdic,用于构建和访问使用有向无环词图 (DAWG) 实现的字典。
dawg 是通过将 trie 最小化为确定性有限自动机 (DFA) 来构造的,因此 dawg 在内存使用方面具有优势
我参考了给定的链接以转换为 Webassemly。 here
The below code store items in dawg graph format.
#include <cassert>
#include <iostream>
#include <string>
#include <dawgdic/dawg-builder.h>
#include <dawgdic/dictionary-builder.h>
#include <emscripten/emscripten.h>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
int EMSCRIPTEN_KEEPALIVE addToDawg(void(*f)(dawgdic::Dawg *c)) {
dawgdic::DawgBuilder dawg_builder;
assert(dawg_builder.Insert("apple"));
assert(dawg_builder.Insert("cherry"));
assert(!dawg_builder.Insert("banana"));
assert(dawg_builder.Insert("durian"));
dawgdic::Dawg dawg;
dawg_builder.Finish(&dawg);
return 0;
}
#ifdef __cplusplus
}
#endif
Here is link to see output: [here](https://demophp.digi-corp.com/nitin/dawg-builder-test.html)
How can I return address of memory segment where dawg is stored to Javascript such that later I can call another method to check if item exist in dawg graph? like dawg_dic.Contains("apple").
【问题讨论】:
标签: javascript emscripten webassembly