{"id":13507194,"url":"https://github.com/os6sense/DefMemo","last_synced_at":"2025-03-30T07:32:23.235Z","repository":{"id":28377639,"uuid":"31891709","full_name":"os6sense/DefMemo","owner":"os6sense","description":"DefMemo - Ryuk's little puppy! Bring apples.","archived":false,"fork":false,"pushed_at":"2017-03-12T13:41:12.000Z","size":29,"stargazers_count":33,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-08T12:12:39.516Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/os6sense.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-09T10:19:09.000Z","updated_at":"2024-08-23T17:37:39.000Z","dependencies_parsed_at":"2022-07-20T09:18:40.453Z","dependency_job_id":null,"html_url":"https://github.com/os6sense/DefMemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os6sense%2FDefMemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os6sense%2FDefMemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os6sense%2FDefMemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os6sense%2FDefMemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/os6sense","download_url":"https://codeload.github.com/os6sense/DefMemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222535160,"owners_count":16999232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:27.107Z","updated_at":"2024-11-01T06:31:32.992Z","avatar_url":"https://github.com/os6sense.png","language":"Elixir","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"DefMemo\n=======\nA memoization macro (defmemo) for Elixir.\n\n[![Build Status](https://travis-ci.org/os6sense/DefMemo.svg?branch=master)](https://travis-ci.org/os6sense/DefMemo)\n\nAdapted from : (Gustavo Brunoro) https://gist.github.com/brunoro/6159378\n\nI found Gustavo's Gist when looking at memoization and elixir and fixed it\nto work with version 1.0.x. Since then I've fixed a few of the problems with\nthe original implementation:\n\n- will correctly memoize the results of functions with identical signatures\n  but in different modules.\n\n- will work with 'when' guard clauses in function definitions. (That was fun!)\n\n- Added lots of lovely tests.\n\nUsage\n=====\n\nAdd defmemo to your mix.exs file:\n\n    {:defmemo, \"~\u003e 0.1.0\"}\n\nAnd run:\n\n    mix deps.get\n\nBefore *using* a defmemo'd function (it's fine to define them), start_link must\nbe called. e.g.\n\n  DefMemo.start_link\n\nor you can add :defmemo into the applications section of your mix.exs:\n\n    [applications: [:logger, :defmemo]]\n\nExample\n=======\n\n    defmodule FibMemo do\n      import DefMemo\n\n      defmemo fibs(0), do: 0\n      defmemo fibs(1), do: 1\n      defmemo fibs(n), do: fibs(n - 1) + fibs(n - 2)\n\n      def fib_10 do\n        fibs(10)\n      end\n    end\n\nPerformance\n===========\nAs you would expect for something like fibs, memoization provides dramatic\nperformance improvements:\n\n    UNMEMOIZED VS MEMOIZED\n    ***********************\n    fib (unmemoized)\n    function -\u003e {result, running time(μs)}\n    ==================================\n    fibs(30) -\u003e {832040, 31089}\n    fibs(30) -\u003e {832040, 31833}\n\n    FibMemo (memoized)\n    ==================================\n    fibs(30) -\u003e {832040, 79}\n    fibs(30) -\u003e {832040, 3}\n    fibs(50) -\u003e {12586269025, 103}\n    fibs(50) -\u003e {12586269025, 3}\n\nNote that these have also improved from version 0.1 to 0.1.1. The above numbers\nare on the low end of the spectrum with access ranging from 2 to 15 μs for me.\n\nTODO\n====\n- Add test for supervisor crashing.\n- Look at injecting the type of result table used.\n- Better documentation.\n- More tests (alwaaaays with the testing!)\n- Test with some biger data (e.g. for something like web crawling)\n\n- ~~Supervisor ~~\n- ~~Redis Based ResultTable - I've been playing with this - obviously there are\n  limitations on type and it's slower than gen server but there are of course\n  circumstances where it could be useful but for the most part its not a good\n  \"fit\".~~\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fos6sense%2FDefMemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fos6sense%2FDefMemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fos6sense%2FDefMemo/lists"}