Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ksSearch to public API #4026

Closed
markus2330 opened this issue Sep 5, 2021 · 11 comments · Fixed by #4002
Closed

add ksSearch to public API #4026

markus2330 opened this issue Sep 5, 2021 · 11 comments · Fixed by #4002
Assignees
Labels
Milestone

Comments

@markus2330
Copy link
Contributor

As we want external iteration as the only iteration it probably makes sense to put elektraCursor ksSearch(KeySet*, Key*) into the public API: it returns the cursor of a key name: as ksLookup, only the return types differs.

There is already a use case: #4002.

@lawli3t Do you think this would be still a minimal API?

Like always: everyone can share his/her thoughts about this proposal.

@kodebach
Copy link
Member

kodebach commented Sep 7, 2021

I agree that ksSearch could be useful. Regarding "minimal API": We could change ksLookup to be a thin wrapper around ksSearch.

static inline Key * ksLookup (KeySet * ks, Key * k, elektraLookupFlags options)
{
    elektraCursor cursor = ksSearch (ks, k);
    if (cursor < 0) return cursor;
    return ksAtCursor (cursor);
}

All elektraLookupFlags options should work with ksSearch, except for KDB_O_POP. IMO removing KDB_O_POP and requiring a separate call to something like ksRemove (KeySet *, elektraCursor) would be fine. It would certainly be more self-explanatory than the KDB_O_POP option.

Another benefit of making ksSearch the main API is that it highlights the ordered nature of a KeySet.

@markus2330
Copy link
Contributor Author

except for KDB_O_POP

  • KDB_O_CREATE also does not work
  • KDB_O_DEL was probably never a good idea (ksLookupByName is superior)
  • KDB_O_SPEC is now irrelevant as we do not want spec keys in the keyset anyway

So which flag remains which you think it is important for ksSearch?

Probably we should even get rid of the argument from ksLookup? (and provide ksRemove instead)

@lawli3t
Copy link
Contributor

lawli3t commented Sep 10, 2021 via email

@kodebach
Copy link
Member

KDB_O_CREATE also does not work

Why? ksSearch could still create and insert the key and then return the cursor for the new key.

KDB_O_DEL was probably never a good idea

I have used it once or twice, but adding another keyDel call wouldn't be too hard.

Probably we should even get rid of the argument from ksLookup? (and provide ksRemove instead)

Probably we should have a remove method that takes a cursor (called ksRemoveAt below, for lack of a better name). Then we can implement ksRemove as:

static inline Key * ksRemove (KeySet * ks, Key * k)
{
    return ksRemoveAt (ks, ksSearch (ks, k));
}

@markus2330
Copy link
Contributor Author

Why?

Actually it also applies to ksLookup: #4034

Probably we should have a remove method that takes a cursor (called ksRemoveAt below, for lack of a better name).

It makes sense that we offer a full iterator-based interface (including removal) and get rid all the special features from ksLookup (like creation and removal).

called ksRemoveAt below

ksRemoveAtCursor would be more consistent to ksAtCursor.

@tucek tucek added this to Stage in Java bindings overhaul via automation Sep 12, 2021
@tucek tucek moved this from Stage to blocked / waiting on in Java bindings overhaul Sep 12, 2021
@markus2330 markus2330 added this to the 0.9.* milestone Sep 13, 2021
@tucek tucek mentioned this issue Sep 13, 2021
20 tasks
@tucek tucek self-assigned this Sep 13, 2021
@tucek
Copy link
Contributor

tucek commented Sep 13, 2021

As discussed with @markus2330, I will add ksSearch to the public C API. ksSearch will first call elektraLookupOpmphmSearch and then fallback on ksSearchInternal.
ksSearchInternal will be made private (src/libs/elektra/symbols.map) and new ksSearch will be public.

@kodebach
Copy link
Member

ksSearchInternal will be made private (src/libs/elektra/symbols.map)

Is this necessary? I don't think there will be a need to call ksSearchInternal outside of libelektra-core.

@tucek
Copy link
Contributor

tucek commented Sep 13, 2021

Optimization of ksSearch by first searching hashmap is extracted to issue #4039

@tucek tucek linked a pull request Sep 13, 2021 that will close this issue
20 tasks
@markus2330
Copy link
Contributor Author

I will add ksSearch to the public C API

Thank you 👍

ksSearchInternal will be made private (src/libs/elektra/symbols.map)
Is this necessary? I don't think there will be a need to call ksSearchInternal outside of libelektra-core.

Exactly, that is why it should be made private.

@kodebach
Copy link
Member

But symbols in src/libs/elektra/symbols.map are still exported, i.e. it should only contain symbols that are used outside the library (.so) that defines them.

Symbols should be defined like this:

  1. Used only within one file: static
  2. Used within multiple files of a single library: non-static, but also not declared in a symbols.map
  3. Used within multiple libraries internally, but not public API: declared in the appropriate symbols.map within the libelektraprivate_1.0 section
  4. Public API: declared in the appropriate symbols.map in a section other than libelektraprivate_1.0

Note: "multiple libraries" in this context could also mean a single library and some tests, since tests are compiles as a separate ELF binary

This means, if ksSearchInternal is used in tests it should be in the private section. But if we rewrite the tests to use ksSearch, it should not be in the symbols.map at all (and could probably even be static).

tucek pushed a commit to tucek/libelektra that referenced this issue Sep 13, 2021
@tucek tucek moved this from blocked / waiting on to Ready for implementation in Java bindings overhaul Sep 13, 2021
@tucek tucek moved this from Ready for implementation to Review pending in Java bindings overhaul Sep 13, 2021
@markus2330
Copy link
Contributor Author

Yes 👍, ksSearchInternal can be static and then only ksSearch gets tested (which is a public symbol).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants