rufus-lru 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,12 @@
2
2
  = rufus-lru CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-lru - 1.0.4 not yet released
6
+
7
+ - fixed issue issue false values
8
+ - 2012 refresh
9
+
10
+
5
11
  == rufus-lru - 1.0.3 released 2010/01/24
6
12
 
7
13
  - 2010 refresh
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2007-2010, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2007-2012, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md ADDED
@@ -0,0 +1,76 @@
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
+
12
+ ## usage
13
+
14
+ It's a regular hash, but you have to set a maxsize at instantiation.
15
+
16
+ Once the maxsize is reached, the hash will discard the element that was the
17
+ least recently used (hence LRU).
18
+
19
+ require 'rubygems'
20
+ require 'rufus/lru'
21
+
22
+ h = Rufus::Lru::Hash.new(3)
23
+
24
+ 5.times { |i| h[i] = "a" * i }
25
+
26
+ puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
27
+
28
+ h[:newer] = 'b'
29
+
30
+ puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
31
+
32
+
33
+ ## dependencies
34
+
35
+ None.
36
+
37
+
38
+ ## mailing list
39
+
40
+ On the rufus-ruby list:
41
+
42
+ http://groups.google.com/group/rufus-ruby
43
+
44
+
45
+ ## issue tracker
46
+
47
+ http://github.com/jmettraux/rufus-lru/issues
48
+
49
+
50
+ ## irc
51
+
52
+ irc.freenode.net #ruote
53
+
54
+
55
+ ## source
56
+
57
+ http://github.com/jmettraux/rufus-lru
58
+
59
+ git clone git://github.com/jmettraux/rufus-lru.git
60
+
61
+
62
+ ## author
63
+
64
+ John Mettraux, jmettraux@gmail.com
65
+ http://jmettraux.wordpress.com
66
+
67
+
68
+ ## the rest of Rufus
69
+
70
+ http://rufus.rubyforge.org
71
+
72
+
73
+ ## license
74
+
75
+ MIT
76
+
data/Rakefile CHANGED
@@ -1,78 +1,87 @@
1
1
 
2
-
3
- require 'lib/rufus/lru.rb'
2
+ $:.unshift('.') # 1.9.2
4
3
 
5
4
  require 'rubygems'
5
+ require 'rubygems/user_interaction' if Gem::RubyGemsVersion == '1.5.0'
6
+
6
7
  require 'rake'
8
+ require 'rake/clean'
9
+ #require 'rake/rdoctask'
10
+ require 'rdoc/task'
7
11
 
8
12
 
9
13
  #
10
- # CLEAN
14
+ # clean
11
15
 
12
- require 'rake/clean'
13
- CLEAN.include('pkg', 'tmp', 'html')
14
- task :default => [ :clean ]
16
+ CLEAN.include('pkg', 'rdoc')
15
17
 
16
18
 
17
19
  #
18
- # GEM
20
+ # test / spec
21
+
22
+ #task :spec => :check_dependencies do
23
+ task :spec do
24
+ exec 'rspec spec/'
25
+ end
26
+ task :test => :spec
19
27
 
20
- require 'jeweler'
28
+ task :default => :spec
21
29
 
22
- Jeweler::Tasks.new do |gem|
23
30
 
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'
31
+ #
32
+ # gem
27
33
 
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'
34
+ GEMSPEC_FILE = Dir['*.gemspec'].first
35
+ GEMSPEC = eval(File.read(GEMSPEC_FILE))
36
+ GEMSPEC.validate
35
37
 
36
- gem.test_file = 'test/test.rb'
37
38
 
38
- #gem.add_dependency 'json'
39
- gem.add_development_dependency 'yard', '>= 0'
39
+ desc %{
40
+ builds the gem and places it in pkg/
41
+ }
42
+ task :build do
40
43
 
41
- # gemspec spec : http://www.rubygems.org/read/chapter/20
44
+ sh "gem build #{GEMSPEC_FILE}"
45
+ sh "mkdir pkg" rescue nil
46
+ sh "mv #{GEMSPEC.name}-#{GEMSPEC.version}.gem pkg/"
42
47
  end
43
- Jeweler::GemcutterTasks.new
44
48
 
49
+ desc %{
50
+ builds the gem and pushes it to rubygems.org
51
+ }
52
+ task :push => :build do
45
53
 
46
- #
47
- # DOC
54
+ sh "gem push pkg/#{GEMSPEC.name}-#{GEMSPEC.version}.gem"
55
+ end
48
56
 
49
- begin
50
57
 
51
- require 'yard'
58
+ #
59
+ # rdoc
60
+ #
61
+ # make sure to have rdoc 2.5.x to run that
62
+
63
+ Rake::RDocTask.new do |rd|
52
64
 
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
65
+ rd.main = 'README.txt'
66
+ rd.rdoc_dir = "rdoc/#{GEMSPEC.name}"
59
67
 
60
- rescue LoadError
68
+ rd.rdoc_files.include('README.rdoc', 'CHANGELOG.txt', 'lib/**/*.rb')
61
69
 
62
- task :yard do
63
- abort "YARD is not available : sudo gem install yard"
64
- end
70
+ rd.title = "#{GEMSPEC.name} #{GEMSPEC.version}"
65
71
  end
66
72
 
67
73
 
68
74
  #
69
- # TO THE WEB
75
+ # upload_rdoc
70
76
 
71
- task :upload_website => [ :clean, :yard ] do
77
+ desc %{
78
+ upload the rdoc to rubyforge
79
+ }
80
+ task :upload_rdoc => [ :clean, :rdoc ] do
72
81
 
73
82
  account = 'jmettraux@rubyforge.org'
74
83
  webdir = '/var/www/gforge-projects/rufus'
75
84
 
76
- sh "rsync -azv -e ssh html/rufus-lru #{account}:#{webdir}/"
85
+ sh "rsync -azv -e ssh rdoc/#{GEMSPEC.name} #{account}:#{webdir}/"
77
86
  end
78
87
 
data/lib/rufus/lru.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2007-2010, John Mettraux, jmettraux@gmail.com
2
+ # Copyright (c) 2007-2012, John Mettraux, jmettraux@gmail.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -25,117 +25,125 @@
25
25
 
26
26
  module Rufus
27
27
  module Lru
28
- VERSION = '1.0.3'
29
- end
30
- end
31
28
 
29
+ VERSION = '1.0.4'
32
30
 
33
- #
34
- # A Hash that has a max size. After the maxsize has been reached, the
35
- # least recently used entries (LRU hence), will be discared to make
36
- # room for the new entries.
37
- #
38
- # require 'rubygems'
39
- # require 'rufus/lru'
40
- #
41
- # h = LruHash.new(3)
42
- #
43
- # 5.times { |i| h[i] = "a" * i }
44
- #
45
- # puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
46
- #
47
- # h[:newer] = "b"
48
- #
49
- # puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
50
- #
51
- #
52
- class LruHash < Hash
31
+ #
32
+ # A Hash that has a max size. After the maxsize has been reached, the
33
+ # least recently used entries (LRU hence), will be discared to make
34
+ # room for the new entries.
35
+ #
36
+ # require 'rubygems'
37
+ # require 'rufus/lru'
38
+ #
39
+ # h = LruHash.new(3)
40
+ #
41
+ # 5.times { |i| h[i] = "a" * i }
42
+ #
43
+ # puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}
44
+ #
45
+ # h[:newer] = "b"
46
+ #
47
+ # puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}
48
+ #
49
+ # Nota bene: this class is not threadsafe.
50
+ #
51
+ class Hash < ::Hash
53
52
 
54
- attr_reader :maxsize
53
+ attr_reader :maxsize
54
+ attr_reader :lru_keys
55
55
 
56
- # Initializes a LruHash with a given maxsize.
57
- #
58
- def initialize (maxsize)
56
+ # Initializes a LruHash with a given maxsize.
57
+ #
58
+ def initialize(maxsize)
59
59
 
60
- super()
60
+ super()
61
61
 
62
- @maxsize = maxsize
63
- @lru_keys = []
64
- end
62
+ @maxsize = maxsize
63
+ @lru_keys = []
64
+ end
65
65
 
66
- def maxsize= (s)
66
+ def maxsize=(i)
67
67
 
68
- @maxsize = s
69
- remove_lru
70
- end
68
+ @maxsize = i
69
+ remove_lru
71
70
 
72
- def clear
71
+ i
72
+ end
73
73
 
74
- super
75
- @lru_keys.clear
76
- end
74
+ def clear
77
75
 
78
- # Returns the keys with the lru in front.
79
- #
80
- def ordered_keys
76
+ @lru_keys.clear
81
77
 
82
- @lru_keys
83
- end
78
+ super
79
+ end
84
80
 
85
- def [] (key)
81
+ # Returns the keys with the lru in front.
82
+ #
83
+ alias ordered_keys lru_keys
86
84
 
87
- value = super
88
- return nil unless value
89
- touch(key)
85
+ def [](key)
90
86
 
91
- value
92
- end
87
+ return nil unless has_key?(key)
93
88
 
94
- def []= (key, value)
89
+ touch(key)
95
90
 
96
- remove_lru
97
- super
98
- touch(key)
91
+ super
92
+ end
99
93
 
100
- value
101
- end
94
+ def []=(key, value)
102
95
 
103
- def merge! (hash)
96
+ remove_lru
97
+ touch(key)
104
98
 
105
- hash.each { |k, v| self[k] = v }
99
+ super
100
+ end
106
101
 
107
- # not using 'super', but in order not guaranteed at all...
108
- end
102
+ def merge!(hash)
109
103
 
110
- def delete (key)
104
+ hash.each { |k, v| self[k] = v }
111
105
 
112
- value = super
113
- @lru_keys.delete(key)
106
+ # not using 'super', but in order not guaranteed at all...
107
+ end
114
108
 
115
- value
116
- end
109
+ def delete(key)
117
110
 
118
- protected
111
+ @lru_keys.delete(key)
119
112
 
120
- # Puts the key on top of the lru 'stack'.
121
- # The bottom being the lru place.
122
- #
123
- def touch (key)
113
+ super
114
+ end
124
115
 
125
- @lru_keys.delete(key)
126
- @lru_keys << key
127
- end
116
+ # Returns a regular Hash with the entries in this hash.
117
+ #
118
+ def to_h
128
119
 
129
- # Makes sure that the hash fits its maxsize. If not, will remove
130
- # the least recently used items.
131
- #
132
- def remove_lru
120
+ {}.merge!(self)
121
+ end
122
+
123
+ protected
133
124
 
134
- while size >= @maxsize
125
+ # Puts the key on top of the lru 'stack'.
126
+ # The bottom being the lru place.
127
+ #
128
+ def touch(key)
135
129
 
136
- key = @lru_keys.delete_at(0)
137
- delete(key)
130
+ @lru_keys.delete(key)
131
+ @lru_keys << key
132
+ end
133
+
134
+ # Makes sure that the hash fits its maxsize. If not, will remove
135
+ # the least recently used items.
136
+ #
137
+ def remove_lru
138
+
139
+ while size >= @maxsize
140
+ delete(@lru_keys.delete_at(0))
141
+ end
138
142
  end
139
143
  end
140
144
  end
145
+ end
146
+
147
+ class LruHash < Rufus::Lru::Hash
148
+ end
141
149
 
data/rufus-lru.gemspec CHANGED
@@ -1,55 +1,35 @@
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
1
 
6
2
  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"
3
+
4
+ s.name = 'rufus-lru'
5
+
6
+ s.version = File.read(
7
+ File.expand_path('../lib/rufus/lru.rb', __FILE__)
8
+ ).match(/ VERSION *= *['"]([^'"]+)/)[1]
9
+
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = [ 'John Mettraux' ]
12
+ s.email = [ 'jmettraux@gmail.com' ]
13
+ s.homepage = 'http://github.com/jmettraux/rufus-lru'
14
+ s.rubyforge_project = 'rufus'
15
+ s.summary = 'A Hash with a max size, controlled by a LRU mechanism'
16
+
17
+ s.description = %{
18
+ LruHash class, a Hash with a max size, controlled by a LRU mechanism
19
+ }.strip
20
+
21
+ #s.files = `git ls-files`.split("\n")
22
+ s.files = Dir[
23
+ 'Rakefile',
24
+ 'lib/**/*.rb', 'spec/**/*.rb', 'test/**/*.rb',
25
+ '*.gemspec', '*.txt', '*.rdoc', '*.md'
40
26
  ]
41
27
 
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
28
+ #s.add_runtime_dependency 'tzinfo', '>= 0.3.23'
29
+
30
+ s.add_development_dependency 'rake'
31
+ s.add_development_dependency 'rspec', '>= 2.7.0'
32
+
33
+ s.require_path = 'lib'
54
34
  end
55
35
 
data/spec/hash_spec.rb ADDED
@@ -0,0 +1,126 @@
1
+
2
+ require 'spec_helper'
3
+
4
+
5
+ describe Rufus::Lru::Hash do
6
+
7
+ let(:hash) { Rufus::Lru::Hash.new(3) }
8
+
9
+ context 'like a ::Hash' do
10
+
11
+ it 'supports insertion' do
12
+
13
+ hash[1] = 2
14
+
15
+ hash[1].should == 2
16
+ end
17
+
18
+ it 'supports deletion' do
19
+
20
+ hash[1] = 2
21
+
22
+ hash.delete(1).should == 2
23
+
24
+ hash.size.should == 0
25
+ end
26
+ end
27
+
28
+ context 'as a LRU Hash' do
29
+
30
+ it 'drops entries when the maxsize is reached' do
31
+
32
+ 4.times { |i| hash[i] = i }
33
+
34
+ hash.size.should == 3
35
+ end
36
+
37
+ it 're-inserting under a key places the key at the end of the lru_keys' do
38
+
39
+ 3.times { |i| hash[i] = i }
40
+
41
+ hash[0] = :new
42
+
43
+ hash.lru_keys.should == [ 1, 2, 0 ]
44
+ end
45
+
46
+ it 'removes keys from the lru_keys upon entry deletion' do
47
+
48
+ hash[1] = 1
49
+ hash.delete(1)
50
+
51
+ hash.lru_keys.should == []
52
+ end
53
+ end
54
+
55
+ describe '#lru_keys' do
56
+
57
+ it 'returns the keys with the least recently used first' do
58
+
59
+ 3.times { |i| hash[i] = i }
60
+
61
+ hash.lru_keys.should == [ 0, 1, 2 ]
62
+ end
63
+ end
64
+
65
+ describe '#ordered_keys' do
66
+
67
+ it 'is an alias for #lru_keys' do
68
+
69
+ 3.times { |i| hash[i] = i }
70
+
71
+ hash.lru_keys.should == [ 0, 1, 2 ]
72
+ end
73
+ end
74
+
75
+ describe '#[]' do
76
+
77
+ it 'returns nil if there is no value' do
78
+
79
+ hash[:x].should == nil
80
+ end
81
+
82
+ it 'returns false when the value is false' do
83
+
84
+ hash[1] = false
85
+
86
+ hash[1].should == false
87
+ end
88
+
89
+ it 'does not modify the LRU list when looking up a non-present key' do
90
+
91
+ hash[:x]
92
+
93
+ hash.lru_keys.should == []
94
+ end
95
+
96
+ it 'returns the current value' do
97
+
98
+ hash[1] = 2
99
+
100
+ hash[1].should == 2
101
+ end
102
+ end
103
+
104
+ describe '#merge!' do
105
+
106
+ it 'merges in place' do
107
+
108
+ hash.merge!(1 => 1, 2 => 2)
109
+
110
+ hash.size.should == 2
111
+ hash.lru_keys.sort.should == [ 1, 2 ]
112
+ end
113
+ end
114
+
115
+ describe '#to_h' do
116
+
117
+ it 'returns a new hash with the entries of the LRU hash' do
118
+
119
+ 4.times { |i| hash[i] = i }
120
+
121
+ hash.to_h.class.should == ::Hash
122
+ hash.to_h.should == { 1 => 1, 2 => 2, 3 => 3 }
123
+ end
124
+ end
125
+ end
126
+
@@ -0,0 +1,16 @@
1
+
2
+ require 'spec_helper'
3
+
4
+
5
+ describe LruHash do
6
+
7
+ it 'is available from the root namespace' do
8
+
9
+ h = LruHash.new(1)
10
+
11
+ 2.times { |i| h[i] = i }
12
+
13
+ h.size.should == 1
14
+ end
15
+ end
16
+
@@ -0,0 +1,21 @@
1
+
2
+ require 'rufus-lru'
3
+
4
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each do |f|
5
+ require(f)
6
+ end
7
+
8
+ RSpec.configure do |config|
9
+
10
+ # == Mock Framework
11
+ #
12
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
13
+ #
14
+ # config.mock_with :mocha
15
+ # config.mock_with :flexmock
16
+ # config.mock_with :rr
17
+ config.mock_with :rspec
18
+
19
+ #config.include SubalternHelper
20
+ end
21
+
metadata CHANGED
@@ -1,73 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rufus-lru
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - John Mettraux
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-01-24 00:00:00 +09:00
12
+ date: 2012-02-28 00:00:00.000000000 +09:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: yard
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &2161499280 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
17
23
  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 "
26
- email: jmettraux@gmail.com
24
+ prerelease: false
25
+ version_requirements: *2161499280
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2161498640 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.7.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2161498640
37
+ description: LruHash class, a Hash with a max size, controlled by a LRU mechanism
38
+ email:
39
+ - jmettraux@gmail.com
27
40
  executables: []
28
-
29
41
  extensions: []
30
-
31
- extra_rdoc_files:
32
- - LICENSE.txt
33
- - README.rdoc
34
- files:
35
- - CHANGELOG.txt
36
- - LICENSE.txt
37
- - README.rdoc
42
+ extra_rdoc_files: []
43
+ files:
38
44
  - Rakefile
39
- - doc/rdoc-style.css
40
- - lib/rufus-lru.rb
41
45
  - lib/rufus/lru.rb
46
+ - lib/rufus-lru.rb
47
+ - spec/hash_spec.rb
48
+ - spec/lru_hash_spec.rb
49
+ - spec/spec_helper.rb
42
50
  - rufus-lru.gemspec
43
- - test/test.rb
51
+ - CHANGELOG.txt
52
+ - LICENSE.txt
53
+ - README.md
44
54
  has_rdoc: true
45
- homepage: http://github.com/jmettraux/rufus-lru/
55
+ homepage: http://github.com/jmettraux/rufus-lru
46
56
  licenses: []
47
-
48
57
  post_install_message:
49
- rdoc_options:
50
- - --charset=UTF-8
51
- require_paths:
58
+ rdoc_options: []
59
+ require_paths:
52
60
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
58
- version:
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
65
73
  requirements: []
66
-
67
74
  rubyforge_project: rufus
68
- rubygems_version: 1.3.5
75
+ rubygems_version: 1.6.2
69
76
  signing_key:
70
77
  specification_version: 3
71
- summary: LruHash class, a Hash with a max size, controlled by a LRU mechanism
72
- test_files:
73
- - test/test.rb
78
+ summary: A Hash with a max size, controlled by a LRU mechanism
79
+ test_files: []
data/README.rdoc DELETED
@@ -1,80 +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
- 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
-
data/doc/rdoc-style.css DELETED
@@ -1,320 +0,0 @@
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; }
data/test/test.rb DELETED
@@ -1,84 +0,0 @@
1
-
2
- #
3
- # Testing rufus-lru
4
- #
5
- # Sun Oct 29 16:18:25 JST 2006
6
- # then Tue Jan 15 12:53:04 JST 2008
7
- #
8
-
9
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
-
11
- require 'test/unit'
12
- require 'rufus/lru'
13
-
14
-
15
- class LruTest < Test::Unit::TestCase
16
-
17
- #def setup
18
- #end
19
- #def teardown
20
- #end
21
-
22
- def test_0
23
-
24
- h = LruHash.new 3
25
-
26
- assert_equal 0, h.size
27
-
28
- h[:a] = "A"
29
-
30
- assert_equal 1, h.size
31
-
32
- h[:b] = "B"
33
- h[:c] = "C"
34
-
35
- assert_equal [ :a, :b, :c ], h.ordered_keys
36
-
37
- h[:d] = "D"
38
-
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
44
-
45
- h.delete :d
46
-
47
- #require 'pp'
48
- #puts "lru keys :"
49
- #pp h.ordered_keys
50
-
51
- assert_equal 2, h.size
52
- assert_equal [ :c, :b ], h.ordered_keys
53
-
54
- h[:a] = "A"
55
-
56
- assert_equal 3, h.size
57
- assert_equal [ :c, :b, :a ], h.ordered_keys
58
-
59
- h[:d] = "D"
60
-
61
-
62
- assert_equal 3, h.size
63
- assert_equal [ :b, :a, :d ], h.ordered_keys
64
-
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
71
-
72
- def test_1
73
-
74
- h = LruHash.new 3
75
-
76
- h[1] = 10
77
-
78
- h.merge!({ 2 => 20, 3 => 30, 4 => 40, 5 => 50 })
79
-
80
- assert_nil h[1]
81
- assert_equal 3, h.size
82
- end
83
- end
84
-