static Bool trie_branch_in_tail (Trie *trie, TrieIndex sep_node, const TrieChar *suffix, TrieData data) { TrieIndex old_tail, old_da; TrieChar *old_suffix, *p; /* adjust separate point in old path */ old_tail = trie_da_get_tail_index (trie->da, sep_node); old_suffix = tail_get_suffix (trie->tail, old_tail); for (p = old_suffix; *p == *suffix; p++, suffix++) sep_node = da_insert_branch (trie->da, sep_node, *p); old_da = da_insert_branch (trie->da, sep_node, *p); if ('\0' != *p) ++p; tail_set_suffix (trie->tail, old_tail, p); trie_da_set_tail_index (trie->da, old_da, old_tail); free (old_suffix); /* insert the new branch at the new separate point */ return trie_branch_in_branch (trie, sep_node, suffix, data); }
static int trie_branch_in_tail( trie_t trie, trie_idx_t sep_node, const char *suffix, trie_data_t data) { trie_idx_t old_tail, old_da, s; const char *old_suffix, *p; /* adjust separate point in old path */ old_tail = trie_da_get_tail_index(trie->da, sep_node); if ((old_suffix = tail_get_suffix(trie->tail, old_tail)) == NULL) { return -1; } for (p = old_suffix, s = sep_node; *p == *suffix; p++, suffix++) { trie_idx_t t = da_insert_branch(trie->da, s, *p); if (t == TRIE_INDEX_ERROR) { goto fail; } s = t; } old_da = da_insert_branch(trie->da, s, *p); if (old_da == TRIE_INDEX_ERROR) { goto fail; } if (*p != '\0') { p++; } tail_set_suffix(trie->tail, old_tail, p); trie_da_set_tail_index(trie->da, old_da, old_tail); /* insert the new branch at the new separate point */ return trie_branch_in_branch(trie, s, suffix, data); fail: /* failed, undo previous insertions and return error */ da_prune_upto(trie->da, sep_node, s); trie_da_set_tail_index(trie->da, sep_node, old_tail); return -1; }
static Bool trie_branch_in_tail (Trie *trie, TrieIndex sep_node, const TrieChar *suffix, TrieData data) { TrieIndex old_tail, old_da, s; const TrieChar *old_suffix, *p; /* adjust separate point in old path */ old_tail = trie_da_get_tail_index (trie->da, sep_node); old_suffix = tail_get_suffix (trie->tail, old_tail); if (!old_suffix) return FALSE; for (p = old_suffix, s = sep_node; *p == *suffix; p++, suffix++) { TrieIndex t = da_insert_branch (trie->da, s, *p); if (TRIE_INDEX_ERROR == t) goto fail; s = t; } old_da = da_insert_branch (trie->da, s, *p); if (TRIE_INDEX_ERROR == old_da) goto fail; if ('\0' != *p) ++p; tail_set_suffix (trie->tail, old_tail, p); trie_da_set_tail_index (trie->da, old_da, old_tail); /* insert the new branch at the new separate point */ return trie_branch_in_branch (trie, s, suffix, data); fail: /* failed, undo previous insertions and return error */ da_prune_upto (trie->da, sep_node, s); trie_da_set_tail_index (trie->da, sep_node, old_tail); return FALSE; }
static Bool trie_branch_in_branch (Trie *trie, TrieIndex sep_node, const TrieChar *suffix, TrieData data) { TrieIndex new_da, new_tail; new_da = da_insert_branch (trie->da, sep_node, *suffix); if ('\0' != *suffix) ++suffix; new_tail = tail_add_suffix (trie->tail, suffix); trie_da_set_tail_index (trie->da, new_da, new_tail); return TRUE; }
static int trie_branch_in_branch( trie_t trie, trie_idx_t sep_node, const char *suffix, trie_data_t data) { trie_idx_t new_da, new_tail; new_da = da_insert_branch(trie->da, sep_node, *suffix); if (new_da == TRIE_INDEX_ERROR) { return -1; } if (*suffix != '\0') { ++suffix; } new_tail = tail_add_suffix(trie->tail, suffix); tail_set_data(trie->tail, new_tail, data); trie_da_set_tail_index(trie->da, new_da, new_tail); trie->dirtyp = 1; return 0; }
static Bool trie_branch_in_branch (Trie *trie, TrieIndex sep_node, const TrieChar *suffix, TrieData data) { TrieIndex new_da, new_tail; new_da = da_insert_branch (trie->da, sep_node, *suffix); if (TRIE_INDEX_ERROR == new_da) return FALSE; if ('\0' != *suffix) ++suffix; new_tail = tail_add_suffix (trie->tail, suffix); tail_set_data (trie->tail, new_tail, data); trie_da_set_tail_index (trie->da, new_da, new_tail); trie->is_dirty = TRUE; return TRUE; }