On Fri, Apr 27, 2018 at 11:44 AM, Jim Riggs <jim...@riggs.me> wrote: > > On 27 Apr 2018, at 05:06, Branko Čibej <br...@apache.org> wrote: > > > > On 27.04.2018 11:30, Nick Kew wrote: > >>> In my use cases, the search may often be strings, but not always, so I > thought that maybe APR could/should provide something more generic. The > above functions could then be rewritten to use this new function. Here are > my thoughts: > >>> > >>> 1. The search item (needle) can be anything rather than just a string > as above. > >>> 2. The caller provides a callback that compares the values to needle > in the same way strcmp()/strcasecmp() do. That is, 0 means "equal". In > fact, strcmp()/strcasecmp() can -- and probably often will -- be used as > the callback for strings. > >> There’s a bit of a mismatch between that and the “can be anything”. > >> The latter would call for a size parameter that could be passed to > memcmp, > >> as well as of course strncmp/strncasecmp. > > > > You can't just use any of the string comparison functions directly > > anyway: first because the signature is wrong, and second because there's > > no requirement that array elements are pointers. > > Nick - I don't expect that comp would ever do just a memcmp...unless > that's how someone implements it, but then that implementation would have > to know what kind of data (and the size) it is dealing with. The comparator > would be a custom written function that expects int or char* or struct* or > _____ and do whatever it considers an equality comparison. It may receive > struct*s and only compare one or two members to consider them "equal" in > the comparator's context. > > Branko - First, I can use them directly with either a compiler warning > (implicit cast char* to void*) or an explicit cast. Second, this does not > require that the elements be pointers. If they are char*, though, strcmp > and strcasecmp work fine. > > >>> 3. A start (input) and index (output) parameter can be used to iterate > and find all occurrences. > >>> What do others think? Is there value in this, or is it just me? > >> I’ve had occasion to search an array, though I don’t think I’ve needed > anything more > >> generic than the HTTPD functions you name above. > >> > >>> +typedef int (apr_array_find_comparison_callback_fn_t)(const void *x, > const void *y); > >> Minor quibble: the name seems quite tortuously overdescriptive! > > Agreed, but it's not something that really gets used much, though. I just > based it off the apr_table_do callback's name. >
If we code this abstractly, comparator declaration is not type-safe, but can be declared so that it is usable by table, hash, b-tree and many other approaches to data organization. With clever use of wrappers, we should be able to make a derivation (counted-byte-string tables, for example) behave in a type-safe manner at no performance penalty. We should cross check the subversion util feature set to ensure we don't have something ready to borrow, already.