MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / aa_child

Function aa_child

src/ui/atlas_api.c:90–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88} aa_children_t;
89
90static aa_tree_child_t *aa_child(aa_children_t *set, const char *name, bool is_file) {
91 /* Files and folders can share a name; disambiguate the map key. */
92 char key[CBM_SZ_512];
93 snprintf(key, sizeof(key), "%c%s", is_file ? 'f' : 'd', name);
94 void *slot = cbm_ht_get(set->by_name, key);
95 if (slot)
96 return &set->items[(int)(intptr_t)slot - 1];
97 if (set->count >= AA_TREE_MAX_CHILDREN) {
98 set->dropped++;
99 return NULL;
100 }
101 if (set->count >= set->cap) {
102 int nc = set->cap ? set->cap * 2 : 64;
103 aa_tree_child_t *grown =
104 cbm_realloc(CBM_MEM_CLASS_OTHER, set->items, (size_t)nc * sizeof(aa_tree_child_t));
105 if (!grown)
106 return NULL;
107 /* The by_name table stores indices, so growth is safe. */
108 set->items = grown;
109 set->cap = nc;
110 }
111 aa_tree_child_t *child = &set->items[set->count];
112 memset(child, 0, sizeof(*child));
113 child->name = aa_strdup(name);
114 child->region = -1;
115 child->is_file = is_file;
116 if (!child->name)
117 return NULL;
118 set->count++;
119 char *owned_key = aa_strdup(key);
120 if (owned_key)
121 cbm_ht_set(set->by_name, owned_key, (void *)(intptr_t)set->count);
122 return child;
123}
124
125static void aa_collect_keys(const char *key, void *value, void *userdata) {
126 (void)value;

Callers 1

cbm_atlas_tree_jsonFunction · 0.85

Calls 4

cbm_ht_getFunction · 0.85
cbm_reallocFunction · 0.85
aa_strdupFunction · 0.85
cbm_ht_setFunction · 0.85

Tested by

no test coverage detected