rufus-lru 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+
2
+ = rufus-lru CHANGELOG.txt
3
+
4
+
5
+ == rufus-lru - 1.0.3 released 2010/01/24
6
+
7
+ - 2010 refresh
8
+
9
+
10
+ == rufus-lru - 1.0.2 released 2008/01/18
11
+
12
+ - todo #17103 : merge! now respecting maxsize
13
+
14
+
15
+ == rufus-lru - 1.0.1 released 2008/01/15
16
+
@@ -0,0 +1,21 @@
1
+
2
+ Copyright (c) 2007-2010, John Mettraux, jmettraux@gmail.com
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
@@ -0,0 +1,80 @@
1
+
2
+ = rufus-lru
3
+
4
+ LruHash class, a Hash with a max size, controlled by a LRU mechanism
5
+
6
+
7
+ == getting it
8
+
9
+ gem install rufus-lru
10
+
11
+ or at
12
+
13
+ http://rubyforge.org/frs/?group_id=4812
14
+
15
+
16
+ == usage
17
+
18
+ It's a regular hash, but you have to set a maxsize at instantiation.
19
+
20
+ Once the maxsize is reached, the hash will discard the element that was the
21
+ least recently used (hence LRU).
22
+
23
+ require 'rubygems'
24
+ require 'rufus/lru'
25
+
26
+ h = LruHash.new 3
27
+
28
+ 5.times { |i| h[i] = "a" * i }
29
+
30
+ puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
31
+
32
+ h[:newer] = "b"
33
+
34
+ puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
35
+
36
+
37
+ == dependencies
38
+
39
+ None.
40
+
41
+
42
+ == mailing list
43
+
44
+ On the rufus-ruby list[http://groups.google.com/group/rufus-ruby] :
45
+
46
+ http://groups.google.com/group/rufus-ruby
47
+
48
+
49
+ == issue tracker
50
+
51
+ http://github.com/jmettraux/rufus-lru/issues
52
+
53
+
54
+ == irc
55
+
56
+ irc.freenode.net #ruote
57
+
58
+
59
+ == source
60
+
61
+ http://github.com/jmettraux/rufus-lru
62
+
63
+ git clone git://github.com/jmettraux/rufus-lru.git
64
+
65
+
66
+ == author
67
+
68
+ John Mettraux, jmettraux@gmail.com
69
+ http://jmettraux.wordpress.com
70
+
71
+
72
+ == the rest of Rufus
73
+
74
+ http://rufus.rubyforge.org
75
+
76
+
77
+ == license
78
+
79
+ MIT
80
+
@@ -0,0 +1,78 @@
1
+
2
+
3
+ require 'lib/rufus/lru.rb'
4
+
5
+ require 'rubygems'
6
+ require 'rake'
7
+
8
+
9
+ #
10
+ # CLEAN
11
+
12
+ require 'rake/clean'
13
+ CLEAN.include('pkg', 'tmp', 'html')
14
+ task :default => [ :clean ]
15
+
16
+
17
+ #
18
+ # GEM
19
+
20
+ require 'jeweler'
21
+
22
+ Jeweler::Tasks.new do |gem|
23
+
24
+ gem.version = Rufus::Lru::VERSION
25
+ gem.name = 'rufus-lru'
26
+ gem.summary = 'LruHash class, a Hash with a max size, controlled by a LRU mechanism'
27
+
28
+ gem.description = %{
29
+ LruHash class, a Hash with a max size, controlled by a LRU mechanism
30
+ }
31
+ gem.email = 'jmettraux@gmail.com'
32
+ gem.homepage = 'http://github.com/jmettraux/rufus-lru/'
33
+ gem.authors = [ 'John Mettraux' ]
34
+ gem.rubyforge_project = 'rufus'
35
+
36
+ gem.test_file = 'test/test.rb'
37
+
38
+ #gem.add_dependency 'json'
39
+ gem.add_development_dependency 'yard', '>= 0'
40
+
41
+ # gemspec spec : http://www.rubygems.org/read/chapter/20
42
+ end
43
+ Jeweler::GemcutterTasks.new
44
+
45
+
46
+ #
47
+ # DOC
48
+
49
+ begin
50
+
51
+ require 'yard'
52
+
53
+ YARD::Rake::YardocTask.new do |doc|
54
+ doc.options = [
55
+ '-o', 'html/rufus-lru', '--title',
56
+ "rufus-lru #{Rufus::Lru::VERSION}"
57
+ ]
58
+ end
59
+
60
+ rescue LoadError
61
+
62
+ task :yard do
63
+ abort "YARD is not available : sudo gem install yard"
64
+ end
65
+ end
66
+
67
+
68
+ #
69
+ # TO THE WEB
70
+
71
+ task :upload_website => [ :clean, :yard ] do
72
+
73
+ account = 'jmettraux@rubyforge.org'
74
+ webdir = '/var/www/gforge-projects/rufus'
75
+
76
+ sh "rsync -azv -e ssh html/rufus-lru #{account}:#{webdir}/"
77
+ end
78
+
@@ -0,0 +1,320 @@
1
+ html, body {
2
+ height: 100%; }
3
+
4
+ body {
5
+ font-family: Helvetica Neue, Helvetica, sans-serif;
6
+ font-size: 85%;
7
+ margin: 0;
8
+ padding: 0;
9
+ background: white;
10
+ color: black; }
11
+
12
+ #wrapper {
13
+ min-height: 100%;
14
+ height: auto !important;
15
+ height: 100%;
16
+ margin: 0 auto -43px; }
17
+
18
+ #footer-push {
19
+ height: 43px; }
20
+
21
+ div.header, #footer {
22
+ background: #eee; }
23
+
24
+ #footer {
25
+ border-top: 1px solid silver;
26
+ margin-top: 12px;
27
+ padding: 0 2em;
28
+ line-height: 30px;
29
+ text-align: center;
30
+ font-variant: small-caps;
31
+ font-size: 95%; }
32
+
33
+ .clearing:after {
34
+ content: ".";
35
+ visibility: hidden;
36
+ height: 0;
37
+ display: block;
38
+ clear: both; }
39
+ * html .clearing {
40
+ height: 1px; }
41
+ .clearing *:first-child + html {
42
+ overflow: hidden; }
43
+
44
+ h1, h2, h3, h4, h5, h6 {
45
+ margin: 0;
46
+ font-weight: normal; }
47
+
48
+ a {
49
+ color: #0b3e71; }
50
+ a:hover {
51
+ background: #336699;
52
+ text-decoration: none;
53
+ color: #eef; }
54
+
55
+ #diagram img {
56
+ border: 0; }
57
+
58
+ #description a, .method .description a, .header a {
59
+ color: #336699; }
60
+ #description a:hover, .method .description a:hover, .header a:hover {
61
+ color: #eee; }
62
+ #description h1 a, #description h2 a, #description h3 a, #description h4 a, #description h5 a, #description h6 a, .method .description h1 a, .method .description h2 a, .method .description h3 a, .method .description h4 a, .method .description h5 a, .method .description h6 a, .header h1 a, .header h2 a, .header h3 a, .header h4 a, .header h5 a, .header h6 a {
63
+ color: #0b3e71; }
64
+
65
+ ol {
66
+ margin: 0;
67
+ padding: 0;
68
+ list-style: none; }
69
+ ol li {
70
+ margin-left: 0;
71
+ white-space: nowrap; }
72
+ ol li.other {
73
+ display: none; }
74
+
75
+ ol.expanded li.other {
76
+ display: list-item; }
77
+
78
+ table {
79
+ margin-bottom: 1em;
80
+ font-size: 1em;
81
+ border-collapse: collapse; }
82
+ table td, table th {
83
+ padding: .4em .8em; }
84
+ table thead {
85
+ background-color: #e8e8e8; }
86
+ table thead th {
87
+ font-variant: small-caps;
88
+ color: #666666; }
89
+ table tr {
90
+ border-bottom: 1px solid silver; }
91
+
92
+ #index a.show, div.header a.show {
93
+ text-decoration: underline;
94
+ font-style: italic;
95
+ color: #666666; }
96
+ #index a.show:after, div.header a.show:after {
97
+ content: " ..."; }
98
+ #index a.show:hover, div.header a.show:hover {
99
+ color: black;
100
+ background: #ffe; }
101
+
102
+ #index {
103
+ font: 85%/1.2 Helvetica neue, Helvetica, sans-serif; }
104
+ #index a {
105
+ text-decoration: none; }
106
+ #index h1 {
107
+ padding: .2em .5em .1em;
108
+ background: #ccc;
109
+ font: small-caps 1.2em Helvetica Neue, Helvetica, sans-serif;
110
+ color: #333;
111
+ border-bottom: 1px solid gray; }
112
+ #index form {
113
+ margin: 0;
114
+ padding: 0; }
115
+ #index form input {
116
+ margin: .4em;
117
+ margin-bottom: 0;
118
+ width: 90%; }
119
+ #index form #search.untouched {
120
+ color: #777777; }
121
+ #index ol {
122
+ padding: .4em .5em; }
123
+ #index ol li {
124
+ white-space: nowrap; }
125
+ #index #index-entries li a {
126
+ padding: 1px 2px; }
127
+ #index #index-entries.classes {
128
+ font-size: 1.1em; }
129
+ #index #index-entries.classes ol {
130
+ padding: 0; }
131
+ #index #index-entries.classes span.nodoc {
132
+ display: none; }
133
+ #index #index-entries.classes span.nodoc, #index #index-entries.classes a {
134
+ font-weight: bold; }
135
+ #index #index-entries.classes .parent {
136
+ font-weight: normal; }
137
+ #index #index-entries.methods li, #index #search-results.methods li {
138
+ margin-bottom: 0.2em; }
139
+ #index #index-entries.methods li a .method_name, #index #search-results.methods li a .method_name {
140
+ margin-right: 0.25em; }
141
+ #index #index-entries.methods li a .module_name, #index #search-results.methods li a .module_name {
142
+ color: #666666; }
143
+ #index #index-entries.methods li a:hover .module_name, #index #search-results.methods li a:hover .module_name {
144
+ color: #ddd; }
145
+
146
+ div.header {
147
+ font-size: 80%;
148
+ padding: .5em 2%;
149
+ font-family: Helvetica, sans-serif;
150
+ border-bottom: 1px solid silver; }
151
+ div.header .name {
152
+ font-size: 1.6em;
153
+ font-family: Helvetica, sans-serif; }
154
+ div.header .name .type {
155
+ color: #666666;
156
+ font-size: 80%;
157
+ font-variant: small-caps; }
158
+ div.header h1.name {
159
+ font-size: 2.2em; }
160
+ div.header .paths, div.header .last-update, div.header .parent {
161
+ color: #666666; }
162
+ div.header .last-update .datetime {
163
+ color: #484848; }
164
+ div.header .parent {
165
+ margin-top: .3em; }
166
+ div.header .parent strong {
167
+ font-weight: normal;
168
+ color: #484848; }
169
+
170
+ #content {
171
+ padding: 12px 2%; }
172
+ div.class #content {
173
+ position: relative;
174
+ width: 72%; }
175
+ #content pre, #content .method .synopsis {
176
+ font: 14px Monaco, DejaVu Sans Mono , Bitstream Vera Sans Mono , Courier New , monospace; }
177
+ #content pre {
178
+ color: black;
179
+ background: #eee;
180
+ border: 1px solid silver;
181
+ padding: .5em .8em;
182
+ overflow: auto; }
183
+ #content p code, #content p tt, #content li code, #content li tt, #content dl code, #content dl tt {
184
+ font: 14px Monaco, DejaVu Sans Mono , Bitstream Vera Sans Mono , Courier New , monospace;
185
+ background: #ffffe3;
186
+ padding: 2px 3px;
187
+ line-height: 1.4; }
188
+ #content h1 code, #content h1 tt, #content h2 code, #content h2 tt, #content h3 code, #content h3 tt, #content h4 code, #content h4 tt, #content h5 code, #content h5 tt, #content h6 code, #content h6 tt {
189
+ font-size: 1.1em; }
190
+ #content #text {
191
+ position: relative; }
192
+ #content #description p {
193
+ margin-top: .5em; }
194
+ #content #description h1, #content #description h2, #content #description h3, #content #description h4, #content #description h5, #content #description h6 {
195
+ font-family: Helvetica Neue, Helvetica, sans-serif; }
196
+ #content #description h1 {
197
+ font-size: 2.2em;
198
+ margin-bottom: .2em;
199
+ border-bottom: 3px double #d8d8d8;
200
+ padding-bottom: .1em; }
201
+ #content #description h2 {
202
+ font-size: 1.8em;
203
+ color: #0e3062;
204
+ margin: .8em 0 .3em 0; }
205
+ #content #description h3 {
206
+ font-size: 1.6em;
207
+ margin: .8em 0 .3em 0;
208
+ color: #666666; }
209
+ #content #description h4 {
210
+ font-size: 1.4em;
211
+ margin: .8em 0 .3em 0; }
212
+ #content #description h5 {
213
+ font-size: 1.2em;
214
+ margin: .8em 0 .3em 0;
215
+ color: #0e3062; }
216
+ #content #description h6 {
217
+ font-size: 1.0em;
218
+ margin: .8em 0 .3em 0;
219
+ color: #666666; }
220
+ #content #description ul, #content #description ol, #content .method .description ul, #content .method .description ol {
221
+ margin: .8em 0;
222
+ padding-left: 1.5em; }
223
+ #content #description ol, #content .method .description ol {
224
+ list-style: decimal; }
225
+ #content #description ol li, #content .method .description ol li {
226
+ white-space: normal; }
227
+
228
+ #method-list {
229
+ position: absolute;
230
+ top: 0px;
231
+ right: -33%;
232
+ width: 28%;
233
+ background: #eee;
234
+ border: 1px solid silver;
235
+ padding: .4em 1%;
236
+ overflow: hidden; }
237
+ #method-list h2 {
238
+ font-size: 1.3em; }
239
+ #method-list h3 {
240
+ font-variant: small-caps;
241
+ text-transform: capitalize;
242
+ font-family: Helvetica Neue, Helvetica, sans-serif;
243
+ color: #666;
244
+ font-size: 1.1em; }
245
+ #method-list ol {
246
+ padding: 0 0 .5em .5em; }
247
+
248
+ #context {
249
+ border-top: 1px dashed silver;
250
+ margin-top: 1em;
251
+ margin-bottom: 1em; }
252
+
253
+ #context h2, #section h2 {
254
+ font: small-caps 1.2em Helvetica Neue, Helvetica, sans-serif;
255
+ color: #444;
256
+ margin: 1em 0 .2em 0; }
257
+
258
+ #methods .method {
259
+ border: 1px solid silver;
260
+ margin-top: .5em;
261
+ background: #eee; }
262
+ #methods .method .synopsis {
263
+ color: black;
264
+ background: silver;
265
+ padding: .2em 1em; }
266
+ #methods .method .synopsis .name {
267
+ font-weight: bold; }
268
+ #methods .method .synopsis a {
269
+ text-decoration: none; }
270
+ #methods .method .description {
271
+ padding: 0 1em; }
272
+ #methods .method .description pre {
273
+ background: #f8f8f8; }
274
+ #methods .method .source {
275
+ margin: .5em 0; }
276
+ #methods .method .source-toggle {
277
+ font-size: 85%;
278
+ margin-left: 1em; }
279
+ #methods .public-class {
280
+ background: #ffffe4; }
281
+ #methods .public-instance .synopsis {
282
+ color: #eee;
283
+ background: #336699; }
284
+
285
+ #content .method .source pre {
286
+ font-size: 90%;
287
+ background: #262626;
288
+ color: #ffdead;
289
+ margin: 1em;
290
+ padding: 0.5em;
291
+ border: 1px dashed #999;
292
+ overflow: auto; }
293
+ #content .method .source pre .ruby-constant {
294
+ color: #7fffd4;
295
+ background: transparent; }
296
+ #content .method .source pre .ruby-keyword {
297
+ color: #00ffff;
298
+ background: transparent; }
299
+ #content .method .source pre .ruby-ivar {
300
+ color: #eedd82;
301
+ background: transparent; }
302
+ #content .method .source pre .ruby-operator {
303
+ color: #00ffee;
304
+ background: transparent; }
305
+ #content .method .source pre .ruby-identifier {
306
+ color: #ffdead;
307
+ background: transparent; }
308
+ #content .method .source pre .ruby-node {
309
+ color: #ffa07a;
310
+ background: transparent; }
311
+ #content .method .source pre .ruby-comment {
312
+ color: #b22222;
313
+ font-weight: bold;
314
+ background: transparent; }
315
+ #content .method .source pre .ruby-regexp {
316
+ color: #ffa07a;
317
+ background: transparent; }
318
+ #content .method .source pre .ruby-value {
319
+ color: #7fffd4;
320
+ background: transparent; }
@@ -0,0 +1,3 @@
1
+
2
+ require 'rufus/lru'
3
+
@@ -1,6 +1,5 @@
1
- #
2
1
  #--
3
- # Copyright (c) 2007-2008, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2007-2010, John Mettraux, jmettraux@gmail.com
4
3
  #
5
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -8,10 +7,10 @@
8
7
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
8
  # copies of the Software, and to permit persons to whom the Software is
10
9
  # furnished to do so, subject to the following conditions:
11
- #
10
+ #
12
11
  # The above copyright notice and this permission notice shall be included in
13
12
  # all copies or substantial portions of the Software.
14
- #
13
+ #
15
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
15
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
16
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -19,16 +18,16 @@
19
18
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
20
  # THE SOFTWARE.
22
- #++
23
- #
24
-
25
21
  #
26
22
  # "made in Japan"
27
- #
28
- # John Mettraux
29
- #
23
+ #++
30
24
 
31
- #require 'monitor'
25
+
26
+ module Rufus
27
+ module Lru
28
+ VERSION = '1.0.3'
29
+ end
30
+ end
32
31
 
33
32
 
34
33
  #
@@ -36,118 +35,107 @@
36
35
  # least recently used entries (LRU hence), will be discared to make
37
36
  # room for the new entries.
38
37
  #
39
- # require 'rubygems'
40
- # require 'rufus/lru'
38
+ # require 'rubygems'
39
+ # require 'rufus/lru'
41
40
  #
42
- # h = LruHash.new 3
41
+ # h = LruHash.new(3)
43
42
  #
44
- # 5.times { |i| h[i] = "a" * i }
43
+ # 5.times { |i| h[i] = "a" * i }
45
44
  #
46
- # puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
45
+ # puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
47
46
  #
48
- # h[:newer] = "b"
47
+ # h[:newer] = "b"
48
+ #
49
+ # puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
49
50
  #
50
- # puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
51
- #
52
51
  #
53
52
  class LruHash < Hash
54
53
 
55
- #--
56
- #include MonitorMixin
57
- #
58
- # seems not necessary for now, and it collides with expool's
59
- # @monitors own sync
60
- #++
54
+ attr_reader :maxsize
61
55
 
62
- attr_reader :maxsize
56
+ # Initializes a LruHash with a given maxsize.
57
+ #
58
+ def initialize (maxsize)
63
59
 
64
- #
65
- # Initializes a LruHash with a given maxsize.
66
- #
67
- def initialize (maxsize)
60
+ super()
68
61
 
69
- super()
62
+ @maxsize = maxsize
63
+ @lru_keys = []
64
+ end
70
65
 
71
- @maxsize = maxsize
72
- @lru_keys = []
73
- end
66
+ def maxsize= (s)
74
67
 
75
- def maxsize= (s)
68
+ @maxsize = s
69
+ remove_lru
70
+ end
76
71
 
77
- @maxsize = s
78
- remove_lru
79
- end
72
+ def clear
80
73
 
81
- def clear
74
+ super
75
+ @lru_keys.clear
76
+ end
82
77
 
83
- super
84
- @lru_keys.clear
85
- end
78
+ # Returns the keys with the lru in front.
79
+ #
80
+ def ordered_keys
86
81
 
87
- #
88
- # Returns the keys with the lru in front.
89
- #
90
- def ordered_keys
82
+ @lru_keys
83
+ end
91
84
 
92
- @lru_keys
93
- end
85
+ def [] (key)
94
86
 
95
- def [] (key)
87
+ value = super
88
+ return nil unless value
89
+ touch(key)
96
90
 
97
- value = super
98
- return nil unless value
99
- touch key
91
+ value
92
+ end
100
93
 
101
- value
102
- end
94
+ def []= (key, value)
103
95
 
104
- def []= (key, value)
96
+ remove_lru
97
+ super
98
+ touch(key)
105
99
 
106
- remove_lru
107
- super
108
- touch key
100
+ value
101
+ end
109
102
 
110
- value
111
- end
103
+ def merge! (hash)
112
104
 
113
- def merge! (hash)
105
+ hash.each { |k, v| self[k] = v }
114
106
 
115
- hash.each { |k, v| self[k] = v }
107
+ # not using 'super', but in order not guaranteed at all...
108
+ end
116
109
 
117
- # not using 'super', but in order not guaranteed at all...
118
- end
110
+ def delete (key)
119
111
 
120
- def delete (key)
112
+ value = super
113
+ @lru_keys.delete(key)
121
114
 
122
- value = super
123
- @lru_keys.delete key
115
+ value
116
+ end
124
117
 
125
- value
126
- end
118
+ protected
127
119
 
128
- protected
120
+ # Puts the key on top of the lru 'stack'.
121
+ # The bottom being the lru place.
122
+ #
123
+ def touch (key)
129
124
 
130
- #
131
- # Puts the key on top of the lru 'stack'.
132
- # The bottom being the lru place.
133
- #
134
- def touch (key)
125
+ @lru_keys.delete(key)
126
+ @lru_keys << key
127
+ end
135
128
 
136
- @lru_keys.delete key
137
- @lru_keys << key
138
- end
129
+ # Makes sure that the hash fits its maxsize. If not, will remove
130
+ # the least recently used items.
131
+ #
132
+ def remove_lru
139
133
 
140
- #
141
- # Makes sure that the hash fits its maxsize. If not, will remove
142
- # the least recently used items.
143
- #
144
- def remove_lru
134
+ while size >= @maxsize
145
135
 
146
- while size >= @maxsize
147
-
148
- key = @lru_keys.delete_at 0
149
- delete key
150
- end
151
- end
136
+ key = @lru_keys.delete_at(0)
137
+ delete(key)
138
+ end
139
+ end
152
140
  end
153
141
 
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rufus-lru}
8
+ s.version = "1.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["John Mettraux"]
12
+ s.date = %q{2010-01-24}
13
+ s.description = %q{
14
+ LruHash class, a Hash with a max size, controlled by a LRU mechanism
15
+ }
16
+ s.email = %q{jmettraux@gmail.com}
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "CHANGELOG.txt",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "doc/rdoc-style.css",
27
+ "lib/rufus-lru.rb",
28
+ "lib/rufus/lru.rb",
29
+ "rufus-lru.gemspec",
30
+ "test/test.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/jmettraux/rufus-lru/}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubyforge_project = %q{rufus}
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{LruHash class, a Hash with a max size, controlled by a LRU mechanism}
38
+ s.test_files = [
39
+ "test/test.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<yard>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<yard>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<yard>, [">= 0"])
53
+ end
54
+ end
55
+
@@ -2,84 +2,83 @@
2
2
  #
3
3
  # Testing rufus-lru
4
4
  #
5
- # jmettraux@gmail.com
6
- #
7
5
  # Sun Oct 29 16:18:25 JST 2006
8
6
  # then Tue Jan 15 12:53:04 JST 2008
9
7
  #
10
8
 
9
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+
11
11
  require 'test/unit'
12
12
  require 'rufus/lru'
13
13
 
14
14
 
15
15
  class LruTest < Test::Unit::TestCase
16
16
 
17
- #def setup
18
- #end
19
-
20
- #def teardown
21
- #end
17
+ #def setup
18
+ #end
19
+ #def teardown
20
+ #end
22
21
 
23
- def test_0
22
+ def test_0
24
23
 
25
- h = LruHash.new 3
24
+ h = LruHash.new 3
26
25
 
27
- assert_equal 0, h.size
26
+ assert_equal 0, h.size
28
27
 
29
- h[:a] = "A"
28
+ h[:a] = "A"
30
29
 
31
- assert_equal 1, h.size
30
+ assert_equal 1, h.size
32
31
 
33
- h[:b] = "B"
34
- h[:c] = "C"
32
+ h[:b] = "B"
33
+ h[:c] = "C"
35
34
 
36
- assert_equal [ :a, :b, :c ], h.ordered_keys
35
+ assert_equal [ :a, :b, :c ], h.ordered_keys
37
36
 
38
- h[:d] = "D"
37
+ h[:d] = "D"
39
38
 
40
- assert_equal 3, h.size
41
- assert_equal [ :b, :c, :d ], h.ordered_keys
42
- assert_equal nil, h[:a]
43
- assert_equal "B", h[:b]
44
- assert_equal [ :c, :d, :b ], h.ordered_keys
39
+ assert_equal 3, h.size
40
+ assert_equal [ :b, :c, :d ], h.ordered_keys
41
+ assert_equal nil, h[:a]
42
+ assert_equal "B", h[:b]
43
+ assert_equal [ :c, :d, :b ], h.ordered_keys
45
44
 
46
- h.delete :d
45
+ h.delete :d
47
46
 
48
- #require 'pp'
49
- #puts "lru keys :"
50
- #pp h.ordered_keys
47
+ #require 'pp'
48
+ #puts "lru keys :"
49
+ #pp h.ordered_keys
51
50
 
52
- assert_equal 2, h.size
53
- assert_equal [ :c, :b ], h.ordered_keys
51
+ assert_equal 2, h.size
52
+ assert_equal [ :c, :b ], h.ordered_keys
54
53
 
55
- h[:a] = "A"
54
+ h[:a] = "A"
56
55
 
57
- assert_equal 3, h.size
58
- assert_equal [ :c, :b, :a ], h.ordered_keys
56
+ assert_equal 3, h.size
57
+ assert_equal [ :c, :b, :a ], h.ordered_keys
59
58
 
60
- h[:d] = "D"
59
+ h[:d] = "D"
61
60
 
62
61
 
63
- assert_equal 3, h.size
64
- assert_equal [ :b, :a, :d ], h.ordered_keys
62
+ assert_equal 3, h.size
63
+ assert_equal [ :b, :a, :d ], h.ordered_keys
65
64
 
66
- assert_equal "B", h[:b]
67
- assert_equal "A", h[:a]
68
- assert_equal "D", h[:d]
69
- assert_equal nil, h[:c]
70
- assert_equal [ :b, :a, :d ], h.ordered_keys
71
- end
65
+ assert_equal "B", h[:b]
66
+ assert_equal "A", h[:a]
67
+ assert_equal "D", h[:d]
68
+ assert_equal nil, h[:c]
69
+ assert_equal [ :b, :a, :d ], h.ordered_keys
70
+ end
72
71
 
73
- def test_1
72
+ def test_1
74
73
 
75
- h = LruHash.new 3
74
+ h = LruHash.new 3
76
75
 
77
- h[1] = 10
76
+ h[1] = 10
78
77
 
79
- h.merge!({ 2 => 20, 3 => 30, 4 => 40, 5 => 50 })
80
-
81
- assert_nil h[1]
82
- assert_equal 3, h.size
83
- end
78
+ h.merge!({ 2 => 20, 3 => 30, 4 => 40, 5 => 50 })
84
79
 
80
+ assert_nil h[1]
81
+ assert_equal 3, h.size
82
+ end
85
83
  end
84
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-lru
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,28 +9,45 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-18 00:00:00 +09:00
12
+ date: 2010-01-24 00:00:00 +09:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yard
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: "\n LruHash class, a Hash with a max size, controlled by a LRU mechanism\n "
17
26
  email: jmettraux@gmail.com
18
27
  executables: []
19
28
 
20
29
  extensions: []
21
30
 
22
31
  extra_rdoc_files:
23
- - README.txt
32
+ - LICENSE.txt
33
+ - README.rdoc
24
34
  files:
25
- - lib/rufus
35
+ - CHANGELOG.txt
36
+ - LICENSE.txt
37
+ - README.rdoc
38
+ - Rakefile
39
+ - doc/rdoc-style.css
40
+ - lib/rufus-lru.rb
26
41
  - lib/rufus/lru.rb
42
+ - rufus-lru.gemspec
27
43
  - test/test.rb
28
- - README.txt
29
44
  has_rdoc: true
30
- homepage: http://rufus.rubyforge.org/rufus-lru
31
- post_install_message:
32
- rdoc_options: []
45
+ homepage: http://github.com/jmettraux/rufus-lru/
46
+ licenses: []
33
47
 
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
34
51
  require_paths:
35
52
  - lib
36
53
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -47,10 +64,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
64
  version:
48
65
  requirements: []
49
66
 
50
- rubyforge_project:
51
- rubygems_version: 0.9.5
67
+ rubyforge_project: rufus
68
+ rubygems_version: 1.3.5
52
69
  signing_key:
53
- specification_version: 2
70
+ specification_version: 3
54
71
  summary: LruHash class, a Hash with a max size, controlled by a LRU mechanism
55
72
  test_files:
56
73
  - test/test.rb
data/README.txt DELETED
@@ -1,70 +0,0 @@
1
-
2
- = rufus-lru
3
-
4
- LruHash class, a Hash with a max size, controlled by a LRU mechanism
5
-
6
-
7
- == getting it
8
-
9
- sudo gem install rufus-lru
10
-
11
- or at
12
-
13
- http://rubyforge.org/frs/?group_id=4812
14
-
15
-
16
- == usage
17
-
18
- It's a regular hash, but you have to set a maxsize at instantiation.
19
-
20
- Once the maxsize is reached, the hash will discard the element that was the
21
- least recently used (hence LRU).
22
-
23
- require 'rubygems'
24
- require 'rufus/lru'
25
-
26
- h = LruHash.new 3
27
-
28
- 5.times { |i| h[i] = "a" * i }
29
-
30
- puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
31
-
32
- h[:newer] = "b"
33
-
34
- puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
35
-
36
-
37
- == dependencies
38
-
39
- None.
40
-
41
-
42
- == mailing list
43
-
44
- On the OpenWFEru-user list for now :
45
-
46
- http://groups.google.com/group/openwferu-users
47
-
48
-
49
- == issue tracker
50
-
51
- http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse
52
-
53
-
54
- == source
55
-
56
- http://rufus.rubyforge.org/svn/trunk/lru
57
-
58
- svn checkout http://rufus.rubyforge.org/svn/trunk/lru
59
-
60
-
61
- == author
62
-
63
- John Mettraux, jmettraux@gmail.com
64
- http://jmettraux.wordpress.com
65
-
66
-
67
- == license
68
-
69
- MIT
70
-