MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / insert_t

Function insert_t

libCacheSim/dataStructure/splay_tuple.c:154–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152// }
153
154sTree_tuple *insert_t(splay_key_type_t i, sTree_tuple *t) {
155 /* Insert i into the sTree t, unless it's already there. */
156 /* Return a pointer to the resulting sTree. */
157 sTree_tuple *new;
158
159 new = (sTree_tuple *)malloc(sizeof(sTree_tuple));
160 if (new == NULL) {
161 printf("Ran out of space\n");
162 exit(1);
163 }
164 assign_key_t(new, i);
165 new->value = 1;
166 if (t == NULL) {
167 new->left = new->right = NULL;
168 return new;
169 }
170 t = splay_t(i, t);
171 if (key_cmp_t(i, t->key) < 0 || ((key_cmp_t(i, t->key) == 0) && (i->L < t->key->L))) {
172 new->left = t->left;
173 new->right = t;
174 t->left = NULL;
175 t->value = 1 + node_value_t(t->right);
176 } else if (key_cmp_t(i, t->key) > 0 || ((key_cmp_t(i, t->key) == 0) && (i->L > t->key->L))) {
177 new->right = t->right;
178 new->left = t;
179 t->right = NULL;
180 t->value = 1 + node_value_t(t->left);
181 } else {
182 free_node_t(new);
183 assert(t->value == 1 + node_value_t(t->left) + node_value_t(t->right));
184 return t;
185 }
186 new->value = 1 + node_value_t(new->left) + node_value_t(new->right);
187 return new;
188}
189
190sTree_tuple *splay_delete_t(splay_key_type_t i, sTree_tuple *t) {
191 if (t == NULL) return NULL;

Callers 1

Calls 4

assign_key_tFunction · 0.85
splay_tFunction · 0.85
free_node_tFunction · 0.85
assertFunction · 0.85

Tested by

no test coverage detected