MCPcopy Create free account
hub / github.com/acl-dev/acl / dlink_add

Function dlink_add

lib_acl/src/stdlib/common/acl_dlink.c:219–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219static ACL_DITEM *dlink_add(ACL_ARRAY *a, acl_int64 begin, acl_int64 end)
220{
221 ACL_DITEM *pitem_right, *pitem_left, *pitem;
222 int idx_begin, idx_end;
223 int ret;
224
225 /* sanity check, maybe useless */
226 /* because it's used internal */
227 if(begin > end)
228 return NULL;
229
230 idx_begin = begin_pos(a, begin);
231 if(idx_begin < 0 || idx_begin >= acl_array_size(a)) /* an error happened */
232 return NULL;
233
234 idx_end = end_pos(a, end);
235 if(idx_end < 0 || idx_end >= acl_array_size(a)) /* an error happened */
236 return NULL;
237
238 if(idx_begin > idx_end) /* an error happened */
239 return NULL;
240
241 if(acl_array_size(a) == 0) { /* the d-link is empty so just add one :) */
242 pitem = dlink_append(a, begin, end);
243 return pitem;
244 }
245
246 pitem_left = (ACL_DITEM *) acl_array_index(a, idx_begin);
247 pitem_right = (ACL_DITEM *) acl_array_index(a, idx_end);
248
249 /* if idx_end == 0 then idx_begin must be equal to 0, I'm sure it :) */
250 if (idx_begin == idx_end) {
251 /*
252 * pitem_left == pitem_right
253 * here idx_begin maybe one of: 0, a->count - 1,
254 * or the one between 0 and a->count
255 * this is to say the begin and end is on the same d-link
256 */
257
258 if (end + 1 < pitem_left->begin) {
259 /*
260 * here idx_begin == idx_end must be equal to 0
261 * the begin and the end must be less
262 * than the next node's begin
263 * add one new node before the one
264 */
265 pitem = dlink_prepend(a, begin, end);
266 return pitem;
267 }
268
269 if (begin > pitem_left->end + 1) {
270 /*
271 * this is to say begin and end
272 * between the current node's end
273 * the next node's begin, and we just
274 * insert one new node between the
275 * current node and the next node, when
276 * the next node is NULL(which say that

Callers 3

acl_dlink_insertFunction · 0.85
acl_dlink_delete_rangeFunction · 0.85
acl_dlink_modifyFunction · 0.85

Calls 8

begin_posFunction · 0.85
acl_array_sizeFunction · 0.85
end_posFunction · 0.85
dlink_appendFunction · 0.85
acl_array_indexFunction · 0.85
dlink_prependFunction · 0.85
dlink_succ_insertFunction · 0.85
dlink_node_mergeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…