Exemplo n.º 1
0
/* "Does any part of TARGET contain any matching substring?" */
static int
NM(trie_match)(const struct trie *trie, const U8 *s, STRLEN len) {
    unsigned char c;
    const struct NM(node) *root = ROOTNODE(trie);
    const struct NM(node) *next, *node = root;

    for (;;) {
        if (NODE_FINAL(node))
            return 1;
        if (len == 0)
            return 0;

        c = *s;

        for (;;) {
            next = c < node->min || c - node->min >= node->size ? 0
                 :           NODE(trie, node->next[c - node->min]);
            if (next || !NODE_FAIL(node))
                break;
            node = NODE(trie, NODE_FAIL(node));
        }

        node = next ? next : root;
        s++;
        len--;
    }
}
Exemplo n.º 2
0
/* Finds the longest proper suffix of BUF (whose length is CUR) that
 * represents the label of a node in TRIE, and returns a pointer to that
 * node. */
static struct NM(node) *
NM(longest_suffix)(const struct trie *trie, const U8 *buf, STRLEN cur) {
    STRLEN i;
    for (i = 1;  i <= cur;  i++) {
        struct NM(node) *node = ROOTNODE(trie);
        const U8 *s = buf + i;
        STRLEN len = cur - i;
        U8 c, offset;
        for (;;) {
            ADVANCE_OR(break);
            if (len == 0)
                return node;
        }
    }
    return ROOTNODE(trie);
}
Exemplo n.º 3
0
void BTreeInsert (btree_t t, double k, index_t data)
{
  index_t new_root;

  assert(t && ROOTNODE(t));

  if (BTreeInsertNode(t, ROOTINDEX(t), &k, &data))
    /* deal with root split */
    {
      new_root = BTreeNewNode(t);
      NODE(t,new_root)->level = ROOTNODE(t)->level + 1;

      NODE(t,new_root)->count = 1;
      NODE(t,new_root)->branch[0].key = k;
      NODE(t,new_root)->branch[0].child = ROOTINDEX(t);
      NODE(t,new_root)->branch[1].child = data;

      ROOTINDEX(t) = new_root;
    }
}
Exemplo n.º 4
0
/* "Is TARGET exactly equal to any matching substring?" */
static int
NM(trie_match_exact)(const struct trie *trie, const U8 *s, STRLEN len) {
    unsigned char c, offset;
    const struct NM(node) *node = ROOTNODE(trie);

    for (;;) {
        if (len == 0)
            return NODE_FINAL(node);
        ADVANCE_OR(return 0);
    }
}