Return-Path: X-Original-To: apmail-apr-dev-archive@www.apache.org Delivered-To: apmail-apr-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DD90F10818 for ; Tue, 29 Apr 2014 04:57:19 +0000 (UTC) Received: (qmail 24457 invoked by uid 500); 29 Apr 2014 04:57:18 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 24028 invoked by uid 500); 29 Apr 2014 04:57:05 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 24018 invoked by uid 99); 29 Apr 2014 04:57:03 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2014 04:57:03 +0000 Received: from localhost (HELO zulu.local) (127.0.0.1) (smtp-auth username brane, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2014 04:57:02 +0000 Message-ID: <535F3123.3050309@apache.org> Date: Tue, 29 Apr 2014 06:57:07 +0200 From: =?UTF-8?B?QnJhbmtvIMSMaWJlag==?= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: dev@apr.apache.org Subject: Re: Sorting an apr_array References: <535E54C2.1020101@apache.org> In-Reply-To: X-Enigmail-Version: 1.6 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAADBQTFRF IhsbCy0qZjoVOVRoeFxSAIKBzXQiAKaibYiewnk7nn9z0qCTgL3i87Ep6Kx/+tHBsrE+zgAAAjZJ REFUOMvF0jFoE1EYB/CzjWlqIzaTjqVIBifRRWyG0t5iUqlLyFpCeXBgKg5yq6A4degUDJjoUDpc 1Qt4Ux94B11SOLB0KGS4discpbkORTCn9/m9d3fvLhXnvuHu3f+Xx/veyyfZfLSdZHzgicSfeyw4 JISwdz8FT6M8lM8Ceg385Dlhs+cC9sQCDn0B78QCogzwN+sxfHGOIXBbRGkNAM4cZymGtgNsDPgz cByxon3EEm1TLmvAlghoHOO3CZSa+IQ/vF6JV8tgKOMow78gRgL2/+EIvATOUtB3SSdMg4GXgrbn uk0uLiGdoCHKbX4E+t1FUTqn1AtIdPJebssDQ64YANSQyyaQNyUOFs0ijMsMFnOPTahPLXKYowtY 08MfCP7vR7hRnc5zmPK7CDYYbHcbC7tHuyFA94U/1LYZaJpu/sxACHMwvwZljTLY0TbNk4x+zuEt yC3MfCM6uSIvfwur0itFL4FA2Yal8BzLfnYV4EIGwEPAk7o5zIcnvzHMEjwJrrhAKK7on6IrsfRJ 7A53BhaK+CL7fj6+q/sPeOvcDTtoZTxpUYsFeIknrOXep3p3l7Ua+8sZ5FPQKyKwWi+DfROTU7ny C1/9UhpeY7K287WJCzbsNPQm2S6Yk4PSCNhWM2r3nD0K9liYb6yPgCRJhSzPrxUK0yUBVk1VX0lj s7MzGZyp0wImMK/e8rHbz2soL+O+2r1dxfGsAmBcx0lNjS/RUhlUC7gRn1wGMdQ7Vw1/AReW/RN3 xFWdAAAAAElFTkSuQmCC Content-Type: multipart/alternative; boundary="------------060901040704000301010803" This is a multi-part message in MIME format. --------------060901040704000301010803 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 28.04.2014 20:35, Jeff Trawick wrote: > On Mon, Apr 28, 2014 at 9:16 AM, Branko Čibej > wrote: > > On 28.04.2014 13:06, Nick Kew wrote: > > I find myself wanting to sort an APR array. > > > > As it stands I can hack it using the array innards from > apr_tables.h: > > > > qsort(arr->elts, arr->nelts, arr->elt_size, my_compare); > > > > Any interest in APR-izing that into an apr_array_sort function > > (and a complementary apr_array_sort_r)? > > Subversion uses this in any number of places. We also have > functions for > sorting hash tables into arrays, if you're looking for code examples. > > -- Brane > > > I'm not sure how feasible this is without writing the code, but in > lieu of the dearth of high level array support (think of the mess of > casting and counting asterisks) perhaps it is feasible to save a > function with the array that can identify the "key" data in an array > element, and sorting or testing membership or perhaps other operations > would use the same mechanism. I dunno. http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sorts.c?revision=1577079&view=markup Look for svn_sort__array() and svn_sort__hash(), lines 138 and 146. -- Brane --------------060901040704000301010803 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 28.04.2014 20:35, Jeff Trawick wrote:
On Mon, Apr 28, 2014 at 9:16 AM, Branko Čibej <brane@apache.org> wrote:
On 28.04.2014 13:06, Nick Kew wrote:
> I find myself wanting to sort an APR array.
>
> As it stands I can hack it using the array innards from apr_tables.h:
>
>     qsort(arr->elts, arr->nelts, arr->elt_size, my_compare);
>
> Any interest in APR-izing that into an apr_array_sort function
> (and a complementary apr_array_sort_r)?

Subversion uses this in any number of places. We also have functions for
sorting hash tables into arrays, if you're looking for code examples.

-- Brane

I'm not sure how feasible this is without writing the code, but in lieu of the dearth of high level array support (think of the mess of casting and counting asterisks) perhaps it is feasible to save a function with the array that can identify the "key" data in an array element, and sorting or testing membership or perhaps other operations would use the same mechanism.  I dunno.

http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sorts.c?revision=1577079&view=markup

Look for svn_sort__array() and svn_sort__hash(), lines 138 and 146.

-- Brane

--------------060901040704000301010803--