[tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module

Alexander Turenko alexander.turenko at tarantool.org
Thu Apr 4 15:00:40 MSK 2019


> > > > Also, returning 1, 0, -1 to Lua looks uncommon. May be, we'd better
> > > > introduce 'equal', 'greater', 'less', etc helpers returning bool?
> > > 
> > > A function for table.sort(table, func) returns boolean, so it make
> > > sense. I'm a bit afraid that we'll need to make two calls: say, :less()
> > > and :equal() to determine an order of tuples strictly. But I cannot
> > > provide a case where it can be necessary. Are you know one?
> > 
> > No, I don't write much code in Lua.
> > 
> > However, if we decided to switch to bool return parameter, I'd implement
> > all possible combinations, i.e. eq, ge, le, gt, lt.
> 
> I mean are there cases when we need to check, say t1 < t2 and if it is
> false then check whether t1 == t2 or t1 > t2? In other words, cases when
> we need to distinguish all three possible situations. Some algorithms?
> 
> I looked throught [1] and it seems it does not contain any reason why
> <=> operator was added to C++20 except ones related to comparison
> operations autogeneration.
> 
> We can just add :cmp() in addition to all other variants, what do you
> think?
> 
> We can also do the trick: return {eq = <boolean>} from :le() / :ge()
> instead of true, but this way looks weird.
> 
> [1]: http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0515r0.pdf

One example that looks valid: search in a binary search tree, where
non-leaf nodes hold elements.



More information about the Tarantool-patches mailing list