From: Sven Verdoolaege Date: Tue, 28 Jun 2011 21:29:20 +0000 (+0200) Subject: add isl_vec_insert_zero_els X-Git-Tag: isl-0.07~63 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f56bb6ae497a84716e53c1531b8c02d6b1a41d8;p=platform%2Fupstream%2Fisl.git add isl_vec_insert_zero_els Signed-off-by: Sven Verdoolaege --- diff --git a/include/isl/vec.h b/include/isl/vec.h index 2602601..e592838 100644 --- a/include/isl/vec.h +++ b/include/isl/vec.h @@ -62,6 +62,10 @@ __isl_give isl_vec *isl_vec_read_from_file(isl_ctx *ctx, FILE *input); __isl_give isl_vec *isl_vec_drop_els(__isl_take isl_vec *vec, unsigned pos, unsigned n); +__isl_give isl_vec *isl_vec_insert_els(__isl_take isl_vec *vec, + unsigned pos, unsigned n); +__isl_give isl_vec *isl_vec_insert_zero_els(__isl_take isl_vec *vec, + unsigned pos, unsigned n); #if defined(__cplusplus) } diff --git a/isl_vec.c b/isl_vec.c index 693af8e..b0bd1a3 100644 --- a/isl_vec.c +++ b/isl_vec.c @@ -292,3 +292,44 @@ error: isl_vec_free(vec); return NULL; } + +__isl_give isl_vec *isl_vec_insert_els(__isl_take isl_vec *vec, + unsigned pos, unsigned n) +{ + isl_vec *ext = NULL; + + if (n == 0) + return vec; + if (!vec) + return NULL; + + if (pos > vec->size) + isl_die(vec->ctx, isl_error_invalid, + "position out of bounds", goto error); + + ext = isl_vec_alloc(vec->ctx, vec->size + n); + if (!ext) + goto error; + + isl_seq_cpy(ext->el, vec->el, pos); + isl_seq_cpy(ext->el + pos + n, vec->el + pos, vec->size - pos); + + isl_vec_free(vec); + return ext; +error: + isl_vec_free(vec); + isl_vec_free(ext); + return NULL; +} + +__isl_give isl_vec *isl_vec_insert_zero_els(__isl_take isl_vec *vec, + unsigned pos, unsigned n) +{ + vec = isl_vec_insert_els(vec, pos, n); + if (!vec) + return NULL; + + isl_seq_clr(vec->el + pos, n); + + return vec; +}