memoize 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +7 -0
- data/README +11 -5
- data/lib/memoize.rb +13 -34
- data/test/tc_memoize.rb +1 -1
- metadata +24 -18
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
= 1.2.1 - 2-Feb-2006
|
2
|
+
* Cache files are now read in binary mode to eliminate issues with Marshal
|
3
|
+
and MS Windows. Thanks go to Brian Buckley for the spot.
|
4
|
+
* Refactored code base down to about half previous size. Thanks go to Andrew
|
5
|
+
Johnson.
|
6
|
+
* Some documentation corrections.
|
7
|
+
|
1
8
|
= 1.2.0 - 31-Dec-2005
|
2
9
|
* Added support for memoizing to file rather than memory
|
3
10
|
* Corresponding changes in the test suite and example programs
|
data/README
CHANGED
@@ -44,10 +44,9 @@ Memoize#memoize(method, file=nil)
|
|
44
44
|
you the value from the table instead of letting the method compute the
|
45
45
|
value again.
|
46
46
|
|
47
|
-
If +file+ is provided, the results are cached to that file
|
48
|
-
|
49
|
-
|
50
|
-
upgrade.
|
47
|
+
If +file+ is provided, the results are cached to that file. Note that
|
48
|
+
this uses Marshal internally. Beware of changes in the Marshal format
|
49
|
+
should you happen to upgrade.
|
51
50
|
|
52
51
|
Returns the cache, which you can inspect or manipulate directly if you are
|
53
52
|
so inclined.
|
@@ -55,13 +54,20 @@ Memoize#memoize(method, file=nil)
|
|
55
54
|
= Acknowledgements
|
56
55
|
Code borrowed from Nobu Nakada (ruby-talk:155159).
|
57
56
|
Code borrowed from Ara Howard (ruby-talk:173428).
|
57
|
+
Code borrowed from Andrew Johnson (http://tinyurl.com/8ymx8)
|
58
58
|
Ideas taken from Brian Buckley and Sean O'Halpin.
|
59
|
+
Tiny URL provided for Andrew Johnson because I could not find the ruby-talk
|
60
|
+
reference. The gateway may have been broken at the time.
|
61
|
+
|
62
|
+
== Known Issues
|
63
|
+
None that I'm aware of. Please report any problems on the Shards tracker
|
64
|
+
or the forums at http://www.rubyforge.org/projects/shards.
|
59
65
|
|
60
66
|
== License
|
61
67
|
Ruby's
|
62
68
|
|
63
69
|
== Copyright
|
64
|
-
(C) 2005, Daniel J. Berger
|
70
|
+
(C) 2005, 2006 Daniel J. Berger
|
65
71
|
All Rights Reserved
|
66
72
|
|
67
73
|
= Author
|
data/lib/memoize.rb
CHANGED
@@ -1,39 +1,18 @@
|
|
1
1
|
module Memoize
|
2
|
-
MEMOIZE_VERSION = "1.2.
|
2
|
+
MEMOIZE_VERSION = "1.2.1"
|
3
3
|
|
4
4
|
# Memoize the method +name+. If +file+ is provided, then the method results
|
5
|
-
# are stored on disk
|
6
|
-
# memory and is persistant.
|
5
|
+
# are stored on disk as well as in memory.
|
7
6
|
def memoize(name, file=nil)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
define_method(name) do |*args|
|
19
|
-
unless cache.has_key?(args)
|
20
|
-
cache[args] = meth.call(*args)
|
21
|
-
File.open(file, "wb+"){|f| Marshal.dump(cache, f) }
|
22
|
-
end
|
23
|
-
cache[args]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
else
|
27
|
-
(class << self; self; end).class_eval do
|
28
|
-
define_method(name) do |*args|
|
29
|
-
if cache.has_key?(args)
|
30
|
-
cache[args]
|
31
|
-
else
|
32
|
-
cache[args] ||= meth.call(*args)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
cache
|
7
|
+
cache = File.open(file, "rb"){ |io| Marshal.load(io) } rescue {}
|
8
|
+
|
9
|
+
(class<<self; self; end).send(:define_method, name) do |*args|
|
10
|
+
unless cache[args]
|
11
|
+
cache[args] = super
|
12
|
+
File.open(file, "wb+"){ |f| Marshal.dump(cache, f) } if file
|
13
|
+
end
|
14
|
+
cache[args]
|
15
|
+
end
|
16
|
+
cache
|
38
17
|
end
|
39
|
-
end
|
18
|
+
end
|
data/test/tc_memoize.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.11
|
3
3
|
specification_version: 1
|
4
4
|
name: memoize
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.2.
|
7
|
-
date:
|
6
|
+
version: 1.2.1
|
7
|
+
date: 2006-02-02 00:00:00 -07:00
|
8
8
|
summary: Speeds up methods at the cost of memory (or disk space)
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: djberg96@gmail.com
|
12
12
|
homepage: http://www.rubyforge.org/projects/shards
|
13
13
|
rubyforge_project:
|
@@ -18,27 +18,33 @@ bindir: bin
|
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
27
28
|
authors:
|
28
|
-
|
29
|
+
- Daniel J. Berger
|
29
30
|
files:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
- lib/memoize.rb
|
32
|
+
- CHANGES
|
33
|
+
- MANIFEST
|
34
|
+
- README
|
35
|
+
- test/tc_memoize.rb
|
35
36
|
test_files:
|
36
|
-
|
37
|
+
- test/tc_memoize.rb
|
37
38
|
rdoc_options: []
|
39
|
+
|
38
40
|
extra_rdoc_files:
|
39
|
-
|
40
|
-
|
41
|
+
- README
|
42
|
+
- CHANGES
|
41
43
|
executables: []
|
44
|
+
|
42
45
|
extensions: []
|
46
|
+
|
43
47
|
requirements: []
|
44
|
-
|
48
|
+
|
49
|
+
dependencies: []
|
50
|
+
|