Fork me on GitHub
#clojure
<
2019-06-30
>
yuhan09:06:02

what's the time complexity of multimethod dispatch? Does it do something clever with the dispatch values like case to avoid having to compare with each individually?

yuhan09:06:46

e.g. if I'm dispatching based on a 2 -element vector and have dozens of defmethods with the first element = :a and differing in the second

lmergen10:06:18

(a hash map to be precise)

yuhan11:06:20

that's interesting, I wonder why the case macro goes to so much trouble for constant-time performance when a simple hash map lookup is also O(1)

lmergen11:06:34

perhaps related to branch prediction

lmergen11:06:56

or even branchless approaches

bronsa12:06:05

a hash map lookup isn't O(1), and the constant factors are significantly different

☝️ 12
eggsyntax23:06:59

Earlier today I asked about whether anyone was aware of a way to use Datomic's pull syntax on vanilla Clojure data structures (without Datomic). Turns out Juxt wrote a nice library for it (https://github.com/juxt/pull), but in case anyone else has use for a simple standalone version that could be copy-pasted into a util namespace, I stuck my version in a gist: https://gist.github.com/eggsyntax/47ba79302f750bb70e9028aa67268500