Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-08 Thread brian m. carlson
On Fri, Sep 07, 2018 at 12:23:53AM -0700, Jonathan Nieder wrote: > Ævar Arnfjörð Bjarmason wrote: > > If this turns out to be a common use-case perhaps the easiest way to > > support that would be to make the hashmap (optionally?) ordered, as Ruby > > 1.9 did with their hash implementation: > >

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-07 Thread Jeff King
On Thu, Sep 06, 2018 at 11:32:41PM -0700, Jonathan Nieder wrote: > > I think Stefan pointed out a "case 4" in the other part of the thread: > > ones where we really care not just about fast lookup, but actual > > iteration order. > > I had assumed that that was the whole point of this data

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-07 Thread Jonathan Nieder
Ævar Arnfjörð Bjarmason wrote: > On Fri, Sep 07 2018, Jonathan Nieder wrote: >> Jeff King wrote: >>> I don't see any point in generating a sorted list and _then_ making an >>> auxiliary hashmap. My idea was that if you're using a sorted string-list >>> for lookup, then you can replace the whole

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-07 Thread Ævar Arnfjörð Bjarmason
On Fri, Sep 07 2018, Jonathan Nieder wrote: > Jeff King wrote: > >> I don't see any point in generating a sorted list and _then_ making an >> auxiliary hashmap. My idea was that if you're using a sorted string-list >> for lookup, then you can replace the whole thing with a hash (inserting >> as

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-07 Thread Jonathan Nieder
Jeff King wrote: > I don't see any point in generating a sorted list and _then_ making an > auxiliary hashmap. My idea was that if you're using a sorted string-list > for lookup, then you can replace the whole thing with a hash (inserting > as you go, rather than sorting at the end). What if I'm

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Jeff King
On Thu, Sep 06, 2018 at 04:50:33PM -0700, Jonathan Nieder wrote: > Hi, > > Jeff King wrote: > > > But what I think is harmful is a _sorted_ list, because of the > > "accidentally quadratic" nature, and because it's easy to call its > > functions on an unsorted list. > > I agree --- in general,

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Jeff King
On Thu, Sep 06, 2018 at 01:54:15PM -0700, Stefan Beller wrote: > > > It turns out we make never use of a custom compare function in > > > the stringlist, which helps gaining confidence this use case is nowhere > > > to be found in the code. > > > > Plenty of code uses the default strcmp. You can

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Jonathan Nieder
Hi, Jeff King wrote: > But what I think is harmful is a _sorted_ list, because of the > "accidentally quadratic" nature, and because it's easy to call its > functions on an unsorted list. I agree --- in general, it tends to be better to build an unsorted string list and then sort it. Once I've

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Stefan Beller
> > Does a hashmap guarantee an order? > > No, it definitely doesn't. > > I guess the reading-between-the-lines assumption that I didn't quite say > is: I think most (if not all) of the users of sorted string lists don't > actually care about a particular order. They just want efficient lookup. >

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Jeff King
On Thu, Sep 06, 2018 at 01:04:18PM -0700, Stefan Beller wrote: > On Thu, Sep 6, 2018 at 12:12 PM Jeff King wrote: > > > > On Thu, Sep 06, 2018 at 10:59:42AM -0400, Jeff King wrote: > > > > > > + string_list_append(_list, *argv[0]); > > > > > > This will create an unsorted list. You'd

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Stefan Beller
On Thu, Sep 6, 2018 at 12:12 PM Jeff King wrote: > > On Thu, Sep 06, 2018 at 10:59:42AM -0400, Jeff King wrote: > > > > + string_list_append(_list, *argv[0]); > > > > This will create an unsorted list. You'd have to use > > string_list_insert() here for a sorted list, or > >

Re: ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Jeff King
On Thu, Sep 06, 2018 at 03:12:03PM -0400, Jeff King wrote: > On Thu, Sep 06, 2018 at 10:59:42AM -0400, Jeff King wrote: > > > > + string_list_append(_list, *argv[0]); > > > > This will create an unsorted list. You'd have to use > > string_list_insert() here for a sorted list, or > >

ordered string-list considered harmful, was Re: [PATCH v3] Allow aliases that include other aliases

2018-09-06 Thread Jeff King
On Thu, Sep 06, 2018 at 10:59:42AM -0400, Jeff King wrote: > > + string_list_append(_list, *argv[0]); > > This will create an unsorted list. You'd have to use > string_list_insert() here for a sorted list, or > unsorted_string_list_has_string() in the earlier call. > > It's