rusty_lru 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +86 -0
- data/.rubocop.yml +23 -2
- data/CHANGELOG.md +9 -1
- data/Cargo.toml +4 -4
- data/Gemfile +4 -0
- data/README.md +2 -1
- data/Rakefile +2 -1
- data/lib/rusty_lru.rb +1 -1
- data/lib/rusty_lru/version.rb +1 -1
- data/rusty_lru.gemspec +6 -3
- data/src/lib.rs +2 -2
- data/tasks/cargo.rake +2 -0
- data/tasks/check.rake +72 -0
- metadata +45 -16
- data/.travis.yml +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ed50fd6948de08b1f9f2bc8a58053f635a7faa13801cfb13572417cd7f9fec
|
4
|
+
data.tar.gz: efeafff2352f14125000dfa0fffabcfed70a2bb9549abc337dc7cf72925eeb6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dec4ee648d15e81ffa8ba035d53802148bf14e7a9858cc78f40804db626a25d2f3835a459fe7d6d06c652cb069105c08280579a34ac1a38e90e2cf18c65a06a
|
7
|
+
data.tar.gz: 04c6053d58b507e978fd11c242e04ba937db3a195fc42caa8b3fca3fb0c638af740c689efa38ec7f41b40e1d463488ffa195023876495165f2690f1b4e2b694d
|
@@ -0,0 +1,86 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
cargo-test:
|
11
|
+
name: Cargo test
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
|
17
|
+
matrix:
|
18
|
+
rust-version: [stable, nightly]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
|
23
|
+
- name: Set up Rust ${{ matrix.rust-version }}
|
24
|
+
uses: actions-rs/toolchain@v1
|
25
|
+
with:
|
26
|
+
profile: minimal
|
27
|
+
toolchain: ${{ matrix.rust-version }}
|
28
|
+
override: true
|
29
|
+
|
30
|
+
- name: Set up Ruby
|
31
|
+
uses: ruby/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: 3.0
|
34
|
+
bundler: latest
|
35
|
+
bundler-cache: true
|
36
|
+
|
37
|
+
- name: Cargo test
|
38
|
+
uses: actions-rs/cargo@v1
|
39
|
+
with:
|
40
|
+
command: test
|
41
|
+
|
42
|
+
rspec:
|
43
|
+
name: RSpec
|
44
|
+
runs-on: ubuntu-latest
|
45
|
+
|
46
|
+
strategy:
|
47
|
+
fail-fast: false
|
48
|
+
|
49
|
+
matrix:
|
50
|
+
ruby-version: [3.0, 2.7, 2.6, 2.5]
|
51
|
+
|
52
|
+
steps:
|
53
|
+
- uses: actions/checkout@v2
|
54
|
+
|
55
|
+
- uses: actions-rs/toolchain@v1
|
56
|
+
with:
|
57
|
+
profile: minimal
|
58
|
+
toolchain: stable
|
59
|
+
override: true
|
60
|
+
|
61
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
62
|
+
uses: ruby/setup-ruby@v1
|
63
|
+
with:
|
64
|
+
ruby-version: ${{ matrix.ruby-version }}
|
65
|
+
bundler: latest
|
66
|
+
bundler-cache: true
|
67
|
+
|
68
|
+
- name: RSpec
|
69
|
+
run: bundle exec rake spec
|
70
|
+
|
71
|
+
rubocop:
|
72
|
+
name: Rubocop
|
73
|
+
runs-on: ubuntu-latest
|
74
|
+
|
75
|
+
steps:
|
76
|
+
- uses: actions/checkout@v2
|
77
|
+
|
78
|
+
- name: Set up Ruby
|
79
|
+
uses: ruby/setup-ruby@v1
|
80
|
+
with:
|
81
|
+
ruby-version: 3.0
|
82
|
+
bundler: latest
|
83
|
+
bundler-cache: true
|
84
|
+
|
85
|
+
- name: Rubocop
|
86
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
@@ -1,14 +1,35 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
1
5
|
AllCops:
|
2
|
-
|
6
|
+
NewCops: enable
|
7
|
+
TargetRubyVersion: 2.5.0
|
3
8
|
Exclude:
|
4
9
|
- vendor/**/*
|
5
10
|
|
11
|
+
Layout/LineLength:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Lint/EmptyBlock:
|
15
|
+
Enabled: false
|
16
|
+
|
6
17
|
Metrics/BlockLength:
|
7
18
|
Exclude:
|
8
19
|
- ./*.gemspec
|
9
20
|
- spec/**/*.rb
|
21
|
+
- tasks/**/*.rake
|
22
|
+
|
23
|
+
RSpec/ExampleLength:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
RSpec/MultipleDescribes:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
RSpec/MultipleExpectations:
|
30
|
+
Enabled: false
|
10
31
|
|
11
|
-
|
32
|
+
RSpec/VerifiedDoubles:
|
12
33
|
Enabled: false
|
13
34
|
|
14
35
|
Style/FrozenStringLiteralComment:
|
data/CHANGELOG.md
CHANGED
@@ -4,11 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
|
8
|
+
## [v0.1.2] - 2021-06-05
|
9
|
+
### Changed
|
10
|
+
- rutie bumped to v0.8.2.
|
11
|
+
- lru bumped to v0.6.5.
|
12
|
+
- Some other dev dependency bumps.
|
13
|
+
|
7
14
|
## [v0.1.1] - 2019-08-30
|
8
15
|
### Changed
|
9
16
|
- Just an update to the README and the gemspec.
|
10
17
|
|
11
|
-
## [v0.1.0] - 2019-08-
|
18
|
+
## [v0.1.0] - 2019-08-30
|
12
19
|
### Added
|
13
20
|
- Implement basic Hash-like functionality by using
|
14
21
|
[rutie](https://rubygems.org/gems/rutie) to wrap the
|
@@ -17,5 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
17
24
|
- [YARD](https://yardoc.org/) docs.
|
18
25
|
- [Rubocop](https://www.rubocop.org/).
|
19
26
|
|
27
|
+
[v0.1.2]: https://github.com/asppsa/rusty_lru/compare/v0.1.1...v0.1.2
|
20
28
|
[v0.1.1]: https://github.com/asppsa/rusty_lru/compare/v0.1.0...v0.1.1
|
21
29
|
[v0.1.0]: https://github.com/asppsa/rusty_lru/releases/tag/v0.1.0
|
data/Cargo.toml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
[package]
|
2
2
|
name = "rusty_lru"
|
3
|
-
version = "0.1.
|
3
|
+
version = "0.1.2"
|
4
4
|
authors = ["Alastair Pharo <me@asph.dev>"]
|
5
5
|
edition = "2018"
|
6
6
|
|
7
7
|
[dependencies]
|
8
|
-
rutie = "0.
|
9
|
-
lru = "0.
|
10
|
-
lazy_static = "1.
|
8
|
+
rutie = "0.8.2"
|
9
|
+
lru = "0.6.5"
|
10
|
+
lazy_static = "1.4.0"
|
11
11
|
|
12
12
|
[lib]
|
13
13
|
name = "rusty_lru"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# RustyLRU
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rusty_lru.svg)](https://badge.fury.io/rb/rusty_lru)
|
4
|
+
[![CI](https://github.com/asppsa/rusty_lru/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/asppsa/rusty_lru/actions/workflows/ci.yml)
|
4
5
|
|
5
6
|
This gem provides an [LRU
|
6
7
|
cache](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU))
|
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
|
3
|
+
Dir['tasks/*.rake'].each(&method(:load))
|
4
4
|
|
5
5
|
RSpec::Core::RakeTask.new(spec: 'cargo:build')
|
6
6
|
|
7
|
+
desc 'Run Ruby and Rust tests'
|
7
8
|
task test: [:spec, 'cargo:test']
|
8
9
|
task default: :test
|
data/lib/rusty_lru.rb
CHANGED
data/lib/rusty_lru/version.rb
CHANGED
data/rusty_lru.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = RustyLRU::VERSION
|
8
8
|
spec.authors = ['Alastair Pharo']
|
9
9
|
spec.email = ['me@asph.dev']
|
10
|
+
spec.required_ruby_version = '>= 2.5'
|
10
11
|
|
11
12
|
spec.summary = 'An LRU cache implemented in Rust'
|
12
13
|
spec.description = <<-DESC
|
@@ -34,8 +35,10 @@ Gem::Specification.new do |spec|
|
|
34
35
|
spec.add_runtime_dependency 'rutie', '~> 0.0.3'
|
35
36
|
|
36
37
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
|
-
spec.add_development_dependency 'irb', '~> 1.
|
38
|
-
spec.add_development_dependency 'rake', '
|
38
|
+
spec.add_development_dependency 'irb', '~> 1.3.5'
|
39
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
39
40
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
-
spec.add_development_dependency 'rubocop', '~>
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 1.16.0'
|
42
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.5.1'
|
43
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
|
41
44
|
end
|
data/src/lib.rs
CHANGED
@@ -13,7 +13,7 @@ pub struct HashableObject {
|
|
13
13
|
|
14
14
|
impl HashableObject {
|
15
15
|
fn get_hash<T: Object>(object: &T) -> i64 {
|
16
|
-
object.send("hash", &[])
|
16
|
+
unsafe { object.send("hash", &[]) }
|
17
17
|
.try_convert_to::<Integer>()
|
18
18
|
.map_err(|e| VM::raise_ex(e))
|
19
19
|
.unwrap()
|
@@ -297,7 +297,7 @@ mod tests {
|
|
297
297
|
let mut hasher1 = DefaultHasher::new();
|
298
298
|
let mut hasher2 = DefaultHasher::new();
|
299
299
|
|
300
|
-
nil.send("hash", &[]).try_convert_to::<Integer>().unwrap().to_i64().hash(&mut hasher1);
|
300
|
+
unsafe { nil.send("hash", &[]) }.try_convert_to::<Integer>().unwrap().to_i64().hash(&mut hasher1);
|
301
301
|
ho.hash(&mut hasher2);
|
302
302
|
|
303
303
|
let hash1 = hasher1.finish();
|
data/tasks/cargo.rake
CHANGED
data/tasks/check.rake
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
namespace :check do
|
2
|
+
desc 'Benchmark Rusty against lru_redux'
|
3
|
+
task bench: 'cargo:build' do
|
4
|
+
require 'benchmark'
|
5
|
+
require 'lru_redux'
|
6
|
+
require 'rusty_lru'
|
7
|
+
|
8
|
+
rusty = RustyLRU::Cache.new(1_000)
|
9
|
+
|
10
|
+
redux = LruRedux::Cache.new(1_000)
|
11
|
+
redux_thread_safe = LruRedux::ThreadSafeCache.new(1_000)
|
12
|
+
|
13
|
+
Benchmark.bmbm do |bm|
|
14
|
+
bm.report 'RustyLRU::Cache' do
|
15
|
+
1_000_000.times { rusty[rand(2_000)] = :value }
|
16
|
+
end
|
17
|
+
|
18
|
+
bm.report 'LruRedux::Cache' do
|
19
|
+
1_000_000.times { redux[rand(2_000)] = :value }
|
20
|
+
end
|
21
|
+
|
22
|
+
bm.report 'LruRedux::ThreadSafeCache' do
|
23
|
+
1_000_000.times { redux_thread_safe[rand(2_000)] = :value }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Check memory consumption'
|
29
|
+
task mem: 'cargo:build' do
|
30
|
+
require 'rusty_lru'
|
31
|
+
require 'securerandom'
|
32
|
+
|
33
|
+
rusty = RustyLRU::Cache.new(1_000_000)
|
34
|
+
statm = File.open("/proc/#{Process.pid}/statm")
|
35
|
+
|
36
|
+
loop do
|
37
|
+
1_000_000.times { rusty[SecureRandom.random_bytes(100)] ||= SecureRandom.random_bytes(100) }
|
38
|
+
p %i[size resident shared text lib data dt].zip(statm.read.split.map(&:to_i)).to_h.slice(:size, :resident, :data)
|
39
|
+
statm.rewind
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Check thread safety'
|
44
|
+
task threadsafe: 'cargo:build' do
|
45
|
+
require 'rusty_lru'
|
46
|
+
require 'securerandom'
|
47
|
+
|
48
|
+
rusty = RustyLRU::Cache.new(1000)
|
49
|
+
pairs = (0..100).map do |j|
|
50
|
+
[j, SecureRandom.uuid]
|
51
|
+
end
|
52
|
+
|
53
|
+
return_values = pairs.map do |j, v|
|
54
|
+
Thread.new do
|
55
|
+
(0...100).map do
|
56
|
+
# Each thread tries to create the same pair. Only one should
|
57
|
+
# succeed.
|
58
|
+
Thread.new { rusty.create(j, v) }
|
59
|
+
end.map(&:value)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
return_values.each do |values|
|
64
|
+
count = values.select(&:itself).size
|
65
|
+
raise "#{j}: Got #{count}" unless count == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
pairs.each do |k, v|
|
69
|
+
p [k, v, rusty.delete(k) == v]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rusty_lru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alastair Pharo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rutie
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.3.5
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.3.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,42 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.16.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.16.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.5.1
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
110
|
+
version: 0.5.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.3.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.3.0
|
97
125
|
description: |2
|
98
126
|
This gem provides an LRU cache with an interface close to Hash. It uses Rutie
|
99
127
|
to wrap the Rust 'lru' crate.
|
@@ -104,10 +132,10 @@ extensions:
|
|
104
132
|
- ext/Rakefile
|
105
133
|
extra_rdoc_files: []
|
106
134
|
files:
|
135
|
+
- ".github/workflows/ci.yml"
|
107
136
|
- ".gitignore"
|
108
137
|
- ".rspec"
|
109
138
|
- ".rubocop.yml"
|
110
|
-
- ".travis.yml"
|
111
139
|
- CHANGELOG.md
|
112
140
|
- Cargo.toml
|
113
141
|
- Gemfile
|
@@ -122,6 +150,7 @@ files:
|
|
122
150
|
- rusty_lru.gemspec
|
123
151
|
- src/lib.rs
|
124
152
|
- tasks/cargo.rake
|
153
|
+
- tasks/check.rake
|
125
154
|
homepage: https://github.com/asppsa/rusty_lru
|
126
155
|
licenses:
|
127
156
|
- Apache-2.0
|
@@ -130,7 +159,7 @@ metadata:
|
|
130
159
|
documentation_uri: https://rubydoc.info/gems/rusty_lru
|
131
160
|
homepage_uri: https://github.com/asppsa/rusty_lru
|
132
161
|
source_code_uri: https://github.com/asppsa/rusty_lru.git
|
133
|
-
post_install_message:
|
162
|
+
post_install_message:
|
134
163
|
rdoc_options: []
|
135
164
|
require_paths:
|
136
165
|
- lib
|
@@ -138,15 +167,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
167
|
requirements:
|
139
168
|
- - ">="
|
140
169
|
- !ruby/object:Gem::Version
|
141
|
-
version: '
|
170
|
+
version: '2.5'
|
142
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
172
|
requirements:
|
144
173
|
- - ">="
|
145
174
|
- !ruby/object:Gem::Version
|
146
175
|
version: '0'
|
147
176
|
requirements: []
|
148
|
-
rubygems_version: 3.
|
149
|
-
signing_key:
|
177
|
+
rubygems_version: 3.2.15
|
178
|
+
signing_key:
|
150
179
|
specification_version: 4
|
151
180
|
summary: An LRU cache implemented in Rust
|
152
181
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
os:
|
3
|
-
- osx
|
4
|
-
- linux
|
5
|
-
rvm:
|
6
|
-
- 2.6
|
7
|
-
- 2.5
|
8
|
-
- 2.4
|
9
|
-
env:
|
10
|
-
- RUST_VERSION=stable
|
11
|
-
- RUST_VERSION=nightly
|
12
|
-
before_install:
|
13
|
-
- gem update --system
|
14
|
-
- gem install bundler
|
15
|
-
- curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUST_VERSION
|
16
|
-
- source $HOME/.cargo/env
|
17
|
-
cache:
|
18
|
-
bundler: true
|
19
|
-
directories:
|
20
|
-
- $HOME/.cargo
|
21
|
-
script:
|
22
|
-
- LD_LIBRARY_PATH=$(ruby -e "print RbConfig::CONFIG['libdir']") cargo test
|
23
|
-
- bundle exec rake spec
|
24
|
-
- bundle exec rubocop
|
25
|
-
matrix:
|
26
|
-
allow_failures:
|
27
|
-
- env: RUST_VERSION=nightly
|
28
|
-
branches:
|
29
|
-
only: master
|