libelektra icon indicating copy to clipboard operation
libelektra copied to clipboard

ksSearch: should support cascading

Open markus2330 opened this issue 3 years ago • 1 comments
trafficstars

#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.

markus2330 avatar Sep 21 '22 15:09 markus2330

Actually, I would

  1. Move the full code of ksLookup into ksSearch
  2. Rewrite that code (i.e. all the functions called by ksLookup/ksSearch) to return a elektraCursor instead of a Key *.
  3. Implement ksLookup as ks->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 position ret
  • ret == -1: Key was not found and cannot be inserted into this KeySet
  • ret < -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.

kodebach avatar Sep 21 '22 21:09 kodebach

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:

github-actions[bot] avatar Oct 05 '23 01:10 github-actions[bot]

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:

github-actions[bot] avatar Nov 12 '23 01:11 github-actions[bot]