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

Embed into other languages #15

Open
flip111 opened this issue Jan 29, 2021 · 7 comments
Open

Embed into other languages #15

flip111 opened this issue Jan 29, 2021 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@flip111
Copy link

flip111 commented Jan 29, 2021

Hey thanks for the library. Is there any possibility for a C version of this? Then it would be much easier to embed in other languages. A C-wrapper would also be a good compromise.

@gvinciguerra
Copy link
Owner

Hi @flip111, thank you for your interest!

Writing a C version would take quite some time, I'd rather go with wrappers from C++ to the target language. For example, for the Python wrapper, I used the pybind11 library and wrapped manually the main class pgm::PGMIndex. Do you have in mind any particular target language?

But if we want to scale, maybe we should look at automatic wrapper generators, such as SWIG and similar tools. But they have a learning curve too.

I'll leave this issue open. Maybe someone more experienced with these tools wants to help 😉

@gvinciguerra gvinciguerra added enhancement New feature or request good first issue Good for newcomers labels Jan 30, 2021
@flip111
Copy link
Author

flip111 commented Jan 30, 2021

Going from C++ directly to the target language is not trivial due to ABI, that's why i was asking for a C wrapper. This doesn't need additional tools or libraries https://isocpp.org/wiki/faq/mixing-c-and-cpp

@darko20
Copy link

darko20 commented Jan 30, 2021

Although I agree that a C wrapper is preferable because most languages can fairly trivally adapt to C due to the standard ABI and there are a large number of possible languages, writing a C wrapper for a C++ program is not a trivial matter.

The C++ code uses language features that have no equivalent in C so there is a lot of work creating a C API that approximates those features. With things like C++ templates you have no hope and just have to only provide support for some basic instatiations, invoke some kind of C macro magic or resort to build-time hackery.

Having said that, tools like SWIG end up being a lot of work anyway and may not be worth the effort.

Personally I'd approach it by defining some minimalist C API for the entire library and build on that when and if required. I like this idea because it would make the library much more accessible to those who just want to exploit these powerful new algorithms.

@gvinciguerra
Copy link
Owner

I'll work on the C API in the upcoming week. Stay tuned 😉

@darko20
Copy link

darko20 commented Jan 31, 2021

Great, I'll be ready to test it when it's done.

I use LMDB right now and I'm very interested to see how it might perform in practice with PMG indexes replacing its B+Trees. LMDB's memory mapped approach is very fast and convenient and seems complementary to this.

gvinciguerra added a commit that referenced this issue Feb 2, 2021
@gvinciguerra
Copy link
Owner

I pushed a first version of the C interface and some examples of usage under /c-interface/examples :)

@gvinciguerra
Copy link
Owner

Here there's a re-implementation in Java!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants