Replies: 2 comments 2 replies
-
I'm a bit skeptical in the fact of embedding such libraries. Either they are simple and often too simplistic, or they try to generalize (like providing a closure for comparison) and quickly become cumbersome and much slower. In my Tasmota experience, it's better to have your own super-compact implementation that fits your need. I did this for 2 or 3 different variants of insertion sort. |
Beta Was this translation helpful? Give feedback.
-
I understand that embedded systems are very sensitive to code bloat. If an application does not need any sorting, it would be a waste to include the code. A solution could be to implement compile-time options for selecting what to include, but then it could cause fragmentation of projects that offer pre-compiled packages. You might offer pre-compiled "lean" and "full" variants for each target that includes Berry, which would double the amount of download packages. Then, some users could start to demand further variants that are just the subset of "full" that they need. The result would be a combinatorial explosion. Another option would be to include the I see that most if not all |
Beta Was this translation helpful? Give feedback.
-
I believe that many applications would benefit from having something that would find the N best elements of a larger collection, as well as something that would sort a
list
according to a comparison predicate, like this,As part of arendst/Tasmota#22529 I implemented a module
binary_heap.be
that definesmake_heap
,remove_heap
, andsort
. I checked the internals of Berry a little, and I understood that most if not all of the built-in modules are implemented in native code. I see that the implementation of thelist
data structure resembles a C++std::vector<object*>
. This is great, because it facilitates a straightforward array representation of a binary heap, like the one implemented in the Berry module. It would seem to be technically feasible to implement this natively by defining a few more functions in the built-inlist
module. I’d be interested in such an exercise, but I would like to know how likely it would be for it to be included in Berry as well as Tasmota. I see that @s-hadinger is active in both projects.If this idea is considered feasible, I’d welcome some suggestions regarding naming.
list.sort(cmp)
orlist.heap_sort(cmp)
would be intuitive, butlist.make_heap(cmp)
andlist.remove_heap(cmp)
could feel somewhat awkward.Beta Was this translation helpful? Give feedback.
All reactions