Replies: 1 comment
-
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.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
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