libelektra
libelektra copied to clipboard
ksSearch: should support cascading
#4414 uncovered this problem. It is quite easy to implement if done similar to ksLookup: you basically only need to check if a key is cascading, then do elektraLookupByCascading, and then ksSearchInternal this key. (In #4039 we can take care of optimizations...)
Then there is another problem: the function is basically unable to return errors, which would be needed if no cascading key is found (and also on null ptrs). I would suggest that -1 is an error (like everywhere else) and the insertpos is -insertpos-2.
Actually, I would
- Move the full code of
ksLookupintoksSearch - Rewrite that code (i.e. all the functions called by
ksLookup/ksSearch) to return aelektraCursorinstead of aKey *. - Implement
ksLookupasks->array[ksSearch(...)]plus error handling
That should still be pretty simple. The functions in ksLookup all eventually call back into ksLookup with different arguments.
For the "error case", I'd actually say:
ret >= 0: Key was found at positionretret == -1: Key was not found and cannot be inserted into this KeySetret < -1: Key was not found, but could be inserted at-ret - 2
I wouldn't call it an error, because it is a valid result for ksSearch. Also the -1 case will in future apply to more cases, when we implement #3598, e.g. if you search for user:/foo in a keyset that contains meta:/ keys we should return -1, since ksAppendKey would fail.
I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart: