tt_dict_singleton

This commit is contained in:
Tony Garnock-Jones 2015-07-01 14:27:16 -04:00
parent d80ff03821
commit 22c9a2d5a0
2 changed files with 14 additions and 1 deletions

View File

@ -125,13 +125,20 @@ static int set_walk(tt_arena_t *a,
}
}
tt_node_ptr_t tt_dict_singleton(tt_arena_t *a,
tt_atom_t key,
tt_node_ptr_t trie)
{
return tt_cons_dict(a, RET_IF_NO_PTR(tt_cons_leaf(a, trie, key)), 1);
}
tt_node_ptr_t tt_dict_set(tt_arena_t *a,
tt_node_ptr_t t,
tt_atom_t key,
tt_node_ptr_t trie)
{
if (TT_EMPTY_DICT_P(t)) {
return tt_cons_dict(a, RET_IF_NO_PTR(tt_cons_leaf(a, trie, key)), 1);
return tt_dict_singleton(a, key, trie);
}
assert(tt_ptr_tag(t) == TT_TAG_DICT);

View File

@ -10,6 +10,12 @@ extern int tt_dict_size(tt_arena_t *a, tt_node_ptr_t t);
/* Returns TT_NO_PTR when key not present. Does not manipulate references. */
extern tt_node_ptr_t tt_dict_get(tt_arena_t *a, tt_node_ptr_t t, tt_atom_t key);
/* Returns TT_NO_PTR when allocation failed. Otherwise, a length-one dict.
Grabs `trie` if required. */
extern tt_node_ptr_t tt_dict_singleton(tt_arena_t *a,
tt_atom_t key,
tt_node_ptr_t trie);
/* Returns TT_NO_PTR when allocation failed. Otherwise, yields a dict.
Grabs `trie` if required. */
extern tt_node_ptr_t tt_dict_set(tt_arena_t *a,