chokkan / dastrie Goto Github PK
View Code? Open in Web Editor NEWStatic Double Array Trie (DASTrie)
Home Page: http://www.chokkan.org/software/dastrie/
License: Other
Static Double Array Trie (DASTrie)
Home Page: http://www.chokkan.org/software/dastrie/
License: Other
Posted by a user. This is how to reproduce it:
typedef dastrie::builder<char*, int> builder_type;
typedef dastrie::trie<int> trie_type;
typedef builder_type::record_type record_type;
// Records sorted by dictionary order of keys.
record_type records[] = {
{"12", 12}, {"123", 123},
};
builder_type builder;
try {
// Build a double-array trie from the records.
builder.build(records, records + sizeof(records)/sizeof(records[0]));
} catch (const builder_type::exception& e) {
// Abort if something went wrong...
std::cerr << "ERROR: " << e.what() << std::endl;
}
trie_type trie;
trie.assign(builder.doublearray(), builder.tail(), builder.table());
trie_type::prefix_cursor pfx = trie.prefix("123876");
while (pfx.next()) {
std::cout
<< pfx.query.substr(0, pfx.length) << " "
<< pfx.value << std::endl;
}
I like the trie implementation so much ! It really helps doing my day to day work faster and with great easy. One issue I found and couldn't solve is how to get all the words from the trie after it has been built.
Although I do understand the theory behind traversing a tree like structure like the trie, I don't fully understand how to get it working with the current code.
Here's some pseudocode I'm thinking of:
`function printWords(trie_node, word, length) { // length is initially 0
if (trie_node->isLeaf) {
print(word);
return;
}
for all children of trie_node {
word[length] = trie_node->character;
printWords(child, word, length+1);
}
}`
But I don't know how to write it using dastrie's structures. Is any way of doing it with the double linked list implementation ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.