From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/2109 Path: news.gmane.org!not-for-mail From: Laurent Bercot Newsgroups: gmane.comp.sysutils.supervision.general Subject: Re: genalloc Date: Wed, 6 Jul 2011 17:50:04 +0200 Message-ID: <20110706155004.GA1185@skarnet.org> References: <1309963914.49518.YahooMailNeo@web28401.mail.ukl.yahoo.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1309967247 25730 80.91.229.12 (6 Jul 2011 15:47:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Jul 2011 15:47:27 +0000 (UTC) Cc: skaware@list.skarnet.org To: "supervision@list.skarnet.org" Original-X-From: supervision-return-2343-gcsg-supervision=m.gmane.org@list.skarnet.org Wed Jul 06 17:47:23 2011 Return-path: Envelope-to: gcsg-supervision@lo.gmane.org Original-Received: from antah.skarnet.org ([212.85.147.14]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QeUJt-0004wH-UR for gcsg-supervision@lo.gmane.org; Wed, 06 Jul 2011 17:47:22 +0200 Original-Received: (qmail 3858 invoked by uid 76); 6 Jul 2011 15:50:04 -0000 Mailing-List: contact supervision-help@list.skarnet.org; run by ezmlm List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Archive: Original-Received: (qmail 3846 invoked by uid 1000); 6 Jul 2011 15:50:04 -0000 Mail-Followup-To: skaware@list.skarnet.org Content-Disposition: inline In-Reply-To: <1309963914.49518.YahooMailNeo@web28401.mail.ukl.yahoo.com> User-Agent: Mutt/1.4i Xref: news.gmane.org gmane.comp.sysutils.supervision.general:2109 Archived-At: 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