Git Product home page Git Product logo

dastrie's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kobikun

dastrie's Issues

Retrieve all words

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 ?

An infinite loop

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;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.