Giter Site home page Giter Site logo

Comments (4)

thep avatar thep commented on July 17, 2024

Changing TrieChar type would involve replacing <string.h> function calls in the Tails implementation with custom functions written for uint16 strings.

The amount of work should be about the same as changing the string representation from 0-terminated to length-counted. So, I think changing the type is not necessary.

What really matters is AlphaChar string, for which 0 termination is still assumed on every API. We need new APIs to allow character 0 in keys.

from libdatrie.

thep avatar thep commented on July 17, 2024

I think binary keys should be represented with a separate set of APIs, just like how memcpy() is separated from strcpy(). For ease of use, let's define a dedicated data type BinKey, e.g.

typedef struct _BinKey BinKey;
struct _BinKey {
    AlphaChar *key;
    int        key_len;
};

with some associated functions, say:

void bin_key_set (BinKey *bk, AlphaChar *key, int key_len);
void bin_key_cpy (BinKey *dst, const BinKey *src);
int  bin_key_cmp (const BinKey *bk1, const BinKey *bk2);
void bin_key_destruct (BinKey *bk);  // freeing the allocated *key

Then, it can be used in our APIs:

Bool trie_bin_retrieve (const Trie *trie, const BinKey *bin_key, TrieData *o_data);
Bool trie_bin_store (Trie *trie, const BinKey *bin_key, TrieData data);
Bool trie_bin_store_if_absent (Trie *trie, const BinKey *bin_key, TrieData data);
Bool trie_bin_delete (Trie *trie, const BinKey *bin_key);

typedef Bool (*TrieBinEnumFunc) (const BinKey *bin_key, TrieData data, void *user_data);
Bool trie_bin_enumerate (const Trie *trie, TrieBinEnumFunc enum_func, void *user_data);

The TrieIterator part also needs the BinKey counterpart. But let's elaborate further whether it needs a new iterator type for BinKey or just an additional method to the existing TrieIterator type.

from libdatrie.

superbobry avatar superbobry commented on July 17, 2024

I like the API, look forward to seeing it in the next libdatrie release :)

from libdatrie.

thep avatar thep commented on July 17, 2024

I think binary keys should be represented with a separate set of APIs, just like how memcpy() is separated from strcpy().

I've just got some free time to work on this. And the length-counted key appears to be a bad idea, as the concept of terminating TRIE_CHAR_TERM ('\0') is hard-wired in the trie structure, to allow a key to be prefix to other keys (e.g. 'an' is prefix to 'another'). And this also applies to binary keys.

So, let's consider changing the TrieChar typedef instead. AFAIK, this would break compatibility of the TAIL structure in current trie files.

from libdatrie.

Related Issues (20)

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.