Skip to main content
9 events
when toggle format what by license comment
Jan 31, 2020 at 19:38 comment added slepic So yeah yours is gonna be (somewhat) faster in most real world scenarios. I already voted your answer up yesterday :) Anyway, now I'm getting curious if a simple for loop combining the map and filter can make it even faster...
Jan 31, 2020 at 19:29 comment added slepic To be more specific. If all the voucher categories are on the end of the master categories list, the performance will be same. If all voucher categories are on the beginning of the master categories list, then your implementation goes to v*v + v. Somewhere between for the rest (and likely most) of cases. The performance gain will also be proportional to c - v (assuming v<=c, although, in practise, likely just v<c or even v<<c).
Jan 31, 2020 at 12:34 history edited lgonzalo CC BY-SA 4.0
deleted 20 characters in body
Jan 31, 2020 at 12:25 history edited lgonzalo CC BY-SA 4.0
added 801 characters in body
Jan 31, 2020 at 12:19 comment added lgonzalo @slepic thanks for your comments. I'm assuming 'categories' is a master table of categories, with id as PK (unique). I'm also assuming 'categories' is in practice much longer than 'voucher.categories' (c >> v). So under these conditions, even with the same asymptotic limit, I think my function would be faster, but I haven't measured it.
Jan 30, 2020 at 9:10 comment added slepic But hey thinking about it, for randomly chosen voucher categories you probably save some searches in most cases. Just the asymptotic upper limit is the same.
Jan 30, 2020 at 8:58 comment added slepic You are wrong. Assuming the ids Are unique and c = categories.length And v=voucher.categories.length, ignoring sort And join, time complexity Is c*v+v in OP's implementation And v*c+v in yours. And that's the same thing.
Jan 29, 2020 at 15:25 review First posts
Jan 29, 2020 at 15:46
Jan 29, 2020 at 15:24 history answered lgonzalo CC BY-SA 4.0