From: Laurent Bercot <ska-skaware@skarnet.org>
To: "supervision@list.skarnet.org" <supervision@list.skarnet.org>
Cc: skaware@list.skarnet.org
Subject: Re: genalloc
Date: Wed, 6 Jul 2011 17:50:04 +0200 [thread overview]
Message-ID: <20110706155004.GA1185@skarnet.org> (raw)
In-Reply-To: <1309963914.49518.YahooMailNeo@web28401.mail.ukl.yahoo.com>
Please use the skaware@list.skarnet.org list for questions about my
software that are not related to s6 or general supervision things.
Mail-Followup-To set.
> After having append many items, I didn't find any API in genalloc to remove an item and then collapse all.
>
> Did I miss something??
> Should I implement it with byte_copy??
Generally speaking, what you are asking for (to delete a cell in a
genalloc and shift all the following cells to the left) requires a lot
of memory rewriting and is not needed: there's always a way to avoid
shifting.
Say you have a genalloc g of type T and you want to delete cell number i.
If you don't care about the order of your cells, just replace the ith
cell with the last one:
unsigned int n = genalloc_len(T, g) ;
genalloc_s(T, g)[i] = genalloc_s(T, g)[n-1] ;
genalloc_setlen(T, g, n-1) ;
If you care about the order of your cells, a simple genalloc isn't the
best structure. You could use a linked list structure, using the genalloc
for storage purposes only: expand type T with an unsigned int that is
the index of your "next" cell in the genalloc, make 0 the head of your list,
and there you go. No rewriting needed.
If you really want to shift cells in a genalloc, then yes, I guess you
could implement it with byte_copy(). But it will be suboptimal in all
cases.
--
Laurent
prev parent reply other threads:[~2011-07-06 15:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-30 19:48 skalibs build failure Lorenzo Beretta
2011-06-30 20:42 ` Laurent Bercot
2011-07-06 14:51 ` genalloc Vincent de RIBOU
2011-07-06 15:50 ` Laurent Bercot [this message]
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=20110706155004.GA1185@skarnet.org \
--to=ska-skaware@skarnet.org \
--cc=skaware@list.skarnet.org \
--cc=supervision@list.skarnet.org \
/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;
as well as URLs for NNTP newsgroup(s).