From: David Gibson <david@gibson.dropbear.id.au>
To: Damien Grassart <damien@grassart.com>
Cc: ccan@lists.ozlabs.org
Subject: Re: [PATCH] darray: Add darray_insert() to insert a value at a specified index
Date: Sun, 27 Aug 2017 12:59:18 +1000 [thread overview]
Message-ID: <20170827025918.GP2772@umbus.fritz.box> (raw)
In-Reply-To: <20170826180108.20693-1-damien@grassart.com>
[-- Attachment #1.1: Type: text/plain, Size: 1657 bytes --]
On Sat, Aug 26, 2017 at 08:01:08PM +0200, Damien Grassart wrote:
> This module currently supports removing but not inserting at a
> specified index, so this adds that. Inserting a value moves all
> existing data beyond index over one element.
Looks good but I need an S-o-b. Adding a testcase would also be good.
> ---
> ccan/darray/darray.h | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/ccan/darray/darray.h b/ccan/darray/darray.h
> index 75112419..fca20b8a 100644
> --- a/ccan/darray/darray.h
> +++ b/ccan/darray/darray.h
> @@ -56,6 +56,7 @@
> *
> * void darray_append(darray(T) arr, T item);
> * void darray_prepend(darray(T) arr, T item);
> + * void darray_insert(darray(T) arr, size_t index, T item);
> * void darray_push(darray(T) arr, T item); // same as darray_append
> *
> * Insertion (multiple items):
> @@ -169,6 +170,12 @@ typedef darray(unsigned long) darray_ulong;
> memmove((arr).item+1, (arr).item, ((arr).size-1)*sizeof(*(arr).item)); \
> (arr).item[0] = (__VA_ARGS__); \
> } while(0)
> +#define darray_insert(arr, index, ...) do { \
> + size_t __index = index; \
> + darray_resize(arr, (arr).size+1); \
> + memmove((arr).item+__index+1, (arr).item+__index, ((arr).size-__index-1)*sizeof(*(arr).item)); \
> + (arr).item[__index] = (__VA_ARGS__); \
> + } while(0)
> #define darray_push(arr, ...) darray_append(arr, __VA_ARGS__)
>
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
[-- Attachment #2: Type: text/plain, Size: 127 bytes --]
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
next prev parent reply other threads:[~2017-08-27 2:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-26 18:01 [PATCH] darray: Add darray_insert() to insert a value at a specified index Damien Grassart
2017-08-27 2:59 ` David Gibson [this message]
2017-08-27 19:40 ` Damien Grassart
2017-08-28 2:42 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170827025918.GP2772@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=ccan@lists.ozlabs.org \
--cc=damien@grassart.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox