amirrajan / rubymotion-applied

RubyMotion documentation provided by the community. Submit a pull request to the docs for a free one year indie subscription.
Apache License 2.0
49 stars 10 forks source link

Create a foreign function interface to a widely supported C++ implementation of Sets #93

Open amirrajan opened 6 years ago

amirrajan commented 6 years ago

Need a cross-platform implementation of the Set data structure. Finding a solid, standalone C++ version (or pure C version), and creating a foreign function interface to it would be best I feel.

Take a look at this code to understand how to create an FFI: https://github.com/HipByte/motion-game/blob/master/src/rubymotion.h and https://github.com/HipByte/motion-game/blob/master/src/sprite.cpp

wndxlori commented 6 years ago

Implementing a foundational data structure like this has some profound performance aspects. And it’d have to be maintained. Your original thought (from the Slack group) to go with NSSet sounded good to me. To be cross-platform, we could use Java’s HashSet. And then layer over the top of those with the MRI standard library’s Set api, to ensure Ruby dev’s are comfortable/happy with it. We could even use MRI Set’s test suite to validate.

amirrajan commented 6 years ago

Implementing a foundational data structure like this has some profound performance aspects.

Agreed. I'd say that we'd reference an (already) widely supported C/C++ version. General rule for me is to "go as low as possible" when it comes to "core" pieces (C > C++ > Objective C/Java > Ruby > RubyMotion).

amirrajan commented 6 years ago

If there isn't a good candidate for these core data structures, then yes, I'd say an NSSet/HashSet polyfill would be best.

amirrajan commented 6 years ago

And then layer over the top of those with the MRI standard library’s Set api, to ensure Ruby dev’s are comfortable/happy with it. We could even use MRI Set’s test suite to validate.

Mixed feelings about this. If we end up using a lower level C API, it's much simpler to have a 1 to 1 relation between the two (I understand that there would be incompatibilities... but it might be worth addressing those as they come as opposed to upfront).

wndxlori commented 6 years ago

As far as C++ goes, no one’s gonna build one, when the STL already has one. I did a quick perusal last night, and didn’t find a C lib. Admittedly, it’s been a long time since I was a hard core C developer, so I might not be looking in the right places.

amirrajan commented 6 years ago

As far as C++ goes, no one’s gonna build one, when the STL already has one. I did a quick perusal last night, and didn’t find a C lib. Admittedly, it’s been a long time since I was a hard core C developer, so I might not be looking in the right places.

Same results for me.