Bug 16079 – memoize should cache objects too

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-05-26T13:47:59Z
Last change time
2018-01-05T13:30:32Z
Assigned to
No Owner
Creator
Seb

Comments

Comment #0 by greensunny12 — 2016-05-26T13:47:59Z
I don't see any reason why memoize should execute this code twice. int executed = 0; T median(T)(T[] nums) { import std.algorithm: sort; executed++; nums.sort(); if (nums.length % 2) return nums[$ / 2]; else return (nums[$ / 2 - 1] + nums[$ / 2]) / 2; } alias fastMedian = memoize!(median!int); assert(fastMedian([7, 5, 3]) == 5); assert(fastMedian([7, 5, 3]) == 5); assert(executed == 1); // ERROR, 2
Comment #1 by greeenify — 2016-12-27T14:13:34Z
sort changes the key -> closing as invalid.
Comment #2 by github-bugzilla — 2017-07-18T22:28:47Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/9e58ecab2aa6eb2d800d1e7e0635f7eee1a774aa Fix issue 16079 - memoize should work with arrays and objects https://github.com/dlang/phobos/commit/aefb5892a3ee1dbbb3433db951e261f3a1b5635c Merge pull request #4367 from wilzbach/fix_16079 Fix issue 16079 - memoize should work with arrays and objects
Comment #3 by github-bugzilla — 2017-08-16T13:22:40Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/9e58ecab2aa6eb2d800d1e7e0635f7eee1a774aa Fix issue 16079 - memoize should work with arrays and objects https://github.com/dlang/phobos/commit/aefb5892a3ee1dbbb3433db951e261f3a1b5635c Merge pull request #4367 from wilzbach/fix_16079
Comment #4 by github-bugzilla — 2018-01-05T13:30:32Z
Commit pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/aefb5892a3ee1dbbb3433db951e261f3a1b5635c Merge pull request #4367 from wilzbach/fix_16079