Last active
October 11, 2019 13:22
-
-
Save nakagami/3ca60a82337ed66590d7e70a52efe352 to your computer and use it in GitHub Desktop.
Darts (Double-ARray Trie System) http://chasen.org/~taku/software/darts/ sample code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <darts.h> | |
// Darts http://chasen.org/~taku/software/darts/ sample code | |
int main (int argc, char **argv) | |
{ | |
using namespace std; | |
const Darts::DoubleArray::key_type *str[] = { "ALGOL", "ANSI", "ARCO", "ARPA", "ARPANET", "ASCII" }; // same as char* | |
Darts::DoubleArray::result_type val[] = { 1, 2, 3, 4, 5, 6 }; // same as int | |
// build | |
Darts::DoubleArray da; | |
da.build (6, str, 0, val); | |
// exactMatchSearch | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("ALGOL") << endl; | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("ANSI") << endl; | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("ARCO") << endl;; | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("ARPA") << endl;; | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("ARPANET") << endl;; | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("ASCII") << endl;; | |
cout << da.exactMatchSearch<Darts::DoubleArray::result_type>("APPARE") << endl; | |
// commonPrefixSearch | |
Darts::DoubleArray::result_pair_type result_pair[1024]; | |
size_t num = da.commonPrefixSearch("ARPANET", result_pair, sizeof(result_pair)); | |
cout << "found:" << num << endl; | |
for (size_t i = 0; i < num; ++i) { | |
cout << "\tvalue:" << result_pair[i].value << " matched key length:" << result_pair[i].length << endl; | |
} | |
num = da.commonPrefixSearch("ARPANET", result_pair, sizeof(result_pair)); | |
cout << "found:" << num << endl; | |
// save to file | |
da.save("sample.dic"); | |
da.clear(); | |
// load from file and commonPrefixSearch | |
Darts::DoubleArray da2; | |
da2.open("sample.dic"); | |
num = da2.commonPrefixSearch("ARPANET", result_pair, sizeof(result_pair)); | |
cout << "found:" << num << endl; | |
da2.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment