Giter VIP home page Giter VIP logo

memoize's Introduction

= Description
  A method that speeds methods up at the cost of memory (or disk space).
   
= Installation
  gem install memoize

= Synopsis
  require 'memoize'
  include Memoize

  # Inefficient fibonacci method
  def fib(n)
    return n if n < 2
    fib(n-1) + fib(n-2)
  end

  fib(100) # Slow

  memoize(:fib)
  fib(100) # Fast
   
  # Or store the cache to a file for later use
  memoize(:fib, "fib.cache")
  fib(100) # Fast

= Constants
Memoize::MEMOIZE_VERSION
   Returns the version of this package as a String.

= Methods
Memoize#memoize(method, file=nil)
   Takes a +method+ (symbol) and caches the results of +method+ in a hash
   table. If you call +method+ again with the same arguments, memoize gives
   you the value from the table instead of letting the method compute the
   value again.
   
   If +file+ is provided, the results are cached to that file.  Note that
   this uses Marshal internally.  Beware of changes in the Marshal format
   should you happen to upgrade.

   Returns the cache, which you can inspect or manipulate directly if you are
   so inclined.

= Acknowledgements
  Code borrowed from Nobu Nakada (ruby-talk:155159).
  Code borrowed from Ara Howard (ruby-talk:173428).
  Code borrowed from Andrew Johnson (http://tinyurl.com/8ymx8)
  Ideas taken from Brian Buckley and Sean O'Halpin.
  Tiny URL provided for Andrew Johnson because I could not find the ruby-talk
  reference. The gateway may have been broken at the time.

= Alternatives
  * memoizable from James Edward Gray
  * simple_memoize from Jack Canty

  Running "gem search -r memoize" will list more alternatives.
   
== Known Issues
  None that I'm aware of.  Please report any problems on the Shards tracker
  or the forums at http://www.rubyforge.org/projects/shards.

== License
  Artistic 2.0
   
== Warranty
  This package is provided "as is" and without any express or
  implied warranties, including, without limitation, the implied
  warranties of merchantability and fitness for a particular purpose.

== Copyright
  (C) 2005-2010 Daniel J. Berger
  All Rights Reserved

= Author
  Daniel J. Berger

memoize's People

Contributors

djberg96 avatar

Watchers

James Cloos avatar SA avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.