dbms_buffers 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3ee12df3813b088a33c85ef865b7c6c68b8b1691ea96938394624ebcbb74cbc9
4
+ data.tar.gz: c62465c4f2ec50e8ef7de8ee586a0c3b712565d1503971298639c2db7aa38c15
5
+ SHA512:
6
+ metadata.gz: 236576f69b30141a843f9278914fce0c88d02310f458a3ee3290bd9a60599f40333762726c4e479ced96f22f81d1f04a5a1ad9de7b8b25690ac015d7c3698efa
7
+ data.tar.gz: e4f32e07e317a0f322e590770684a687cc5b334be9985fc8419821169f7e7e17446a46fb0d455b2b4e2565c3a10f701ba233217367e22cabd8a5352efb5db728
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,7 @@
1
+ ---
2
+ detectors:
3
+ IrresponsibleModule:
4
+ enabled: false
5
+ TooManyStatements:
6
+ enabled: true
7
+ max_statements: 15
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ Layout/LineLength:
2
+ Max: 100
3
+ Style/SymbolArray:
4
+ EnforcedStyle: brackets
5
+ Style/WordArray:
6
+ EnforcedStyle: brackets
@@ -0,0 +1 @@
1
+ dbms_buffers
@@ -0,0 +1 @@
1
+ 2.7.0
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,5 @@
1
+ ## CHANGELOG
2
+
3
+ ## Current
4
+
5
+ * Gem created, rubocop added.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in dbms_buffers.gemspec
6
+ gemspec
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dbms_buffers (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ axiom-types (0.1.1)
11
+ descendants_tracker (~> 0.0.4)
12
+ ice_nine (~> 0.11.0)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ codeclimate-engine-rb (0.4.1)
15
+ virtus (~> 1.0)
16
+ coercible (1.0.0)
17
+ descendants_tracker (~> 0.0.1)
18
+ descendants_tracker (0.0.4)
19
+ thread_safe (~> 0.3, >= 0.3.1)
20
+ diff-lcs (1.3)
21
+ equalizer (0.0.11)
22
+ ice_nine (0.11.2)
23
+ jaro_winkler (1.5.4)
24
+ kwalify (0.7.2)
25
+ parallel (1.19.1)
26
+ parser (2.6.5.0)
27
+ ast (~> 2.4.0)
28
+ psych (3.1.0)
29
+ rainbow (3.0.0)
30
+ rake (10.5.0)
31
+ reek (5.5.0)
32
+ codeclimate-engine-rb (~> 0.4.0)
33
+ kwalify (~> 0.7.0)
34
+ parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
35
+ psych (~> 3.1.0)
36
+ rainbow (>= 2.0, < 4.0)
37
+ rspec (3.9.0)
38
+ rspec-core (~> 3.9.0)
39
+ rspec-expectations (~> 3.9.0)
40
+ rspec-mocks (~> 3.9.0)
41
+ rspec-core (3.9.1)
42
+ rspec-support (~> 3.9.1)
43
+ rspec-expectations (3.9.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-mocks (3.9.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-support (3.9.2)
50
+ rubocop (0.78.0)
51
+ jaro_winkler (~> 1.5.1)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.6)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 1.4.0, < 1.7)
57
+ ruby-progressbar (1.10.1)
58
+ thread_safe (0.3.6)
59
+ unicode-display_width (1.6.1)
60
+ virtus (1.0.5)
61
+ axiom-types (~> 0.1)
62
+ coercible (~> 1.0)
63
+ descendants_tracker (~> 0.0, >= 0.0.3)
64
+ equalizer (~> 0.0, >= 0.0.9)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 2.0)
71
+ dbms_buffers!
72
+ rake (~> 10.0)
73
+ reek (~> 5.5.0)
74
+ rspec (~> 3.0)
75
+ rubocop (~> 0.78)
76
+
77
+ BUNDLED WITH
78
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Manuel Dossinger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # DbmsBuffers
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dbms_buffers`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dbms_buffers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dbms_buffers
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dbms_buffers.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'dbms_buffers'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'dbms_buffers/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'dbms_buffers'
9
+ spec.version = DbmsBuffers::VERSION
10
+ spec.authors = ['Manuel Dossinger']
11
+
12
+ spec.summary = 'Buffer implementations that can be found in typical DBMS lectures.'
13
+ spec.homepage = 'https://github.com/contradictioned/dbms-buffers'
14
+ spec.license = 'MIT'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/contradictioned/dbms-buffers'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/contradictioned/dbms-buffers/blob/master/CHANGELOG.md'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'reek', '~> 5.5.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'rubocop', '~> 0.78'
34
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dbms_buffers/version'
4
+ require 'dbms_buffers/clock'
5
+ require 'dbms_buffers/generators'
6
+ require 'dbms_buffers/lru'
7
+
8
+ module DbmsBuffers
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DbmsBuffers
4
+ ClockBufferEntry = Struct.new(:value, :clock_value)
5
+
6
+ # The clock buffer, also known as second-change buffer,
7
+ # arranges entries in a logical clock and a single hand.
8
+ # When the buffer is full and a not-yet-inserted entry needs space,
9
+ # the hand goes clockwise until it finds an entry with clock_value = 0.
10
+ # This entry is evicted, removed from the buffer, and the new values
11
+ # is inserted with clock_value 1.
12
+ # All entries the hand passes where clock_value = 1, this value is decremented,
13
+ # but they are not replaced yet (they have a second chance).
14
+ # When an element is accessed that has clock_value = 0, this value is set to 1 again.
15
+ class ClockBuffer
16
+ attr_reader :pointer, :size
17
+
18
+ def initialize(size)
19
+ @size = size
20
+ @buffer = []
21
+ @pointer = 0
22
+ end
23
+
24
+ def access(value)
25
+ try_touch(value) || try_insert_new(value) || try_replace(value)
26
+ end
27
+
28
+ def clock_value_of(value)
29
+ @buffer[index(value)].clock_value
30
+ end
31
+
32
+ def entries
33
+ @buffer.clone
34
+ end
35
+
36
+ def contains?(value)
37
+ @buffer.any? { |entry| value == entry.value }
38
+ end
39
+
40
+ def used
41
+ @buffer.size
42
+ end
43
+
44
+ private
45
+
46
+ # If value is contained in the buffer, it's value is set to 1
47
+ # and true is returned, otherwise false
48
+ def try_touch(value)
49
+ result = contains? value
50
+ touch(value) if result
51
+ result
52
+ end
53
+
54
+ # If buffer slots are free, inserts value and returns true.
55
+ def try_insert_new(value)
56
+ return false if used == @size
57
+
58
+ entry = ClockBufferEntry.new(value, 1)
59
+ @buffer[@pointer] = entry
60
+ advance_pointer
61
+
62
+ true
63
+ end
64
+
65
+ def try_replace(value)
66
+ entry = @buffer[@pointer]
67
+ if entry.clock_value.zero?
68
+ entry.value = value
69
+ entry.clock_value = 1
70
+ return true
71
+ end
72
+
73
+ entry.clock_value = 0
74
+ advance_pointer
75
+ try_replace value
76
+ end
77
+
78
+ def advance_pointer
79
+ @pointer = (@pointer + 1) % @size
80
+ end
81
+
82
+ def index(value)
83
+ @buffer.index { |entry| entry.value == value }
84
+ end
85
+
86
+ def touch(value)
87
+ @buffer.find { |entry| entry.value == value }.clock_value = 1
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DbmsBuffers
4
+ # The SimpleGenerator generates random elements for putting into the buffer.
5
+ # By default, it generates a letter from A to Z.
6
+ # This can be adjusted using the range method, e.g.
7
+ # SimpleGenerator.new.range(['A', 'B', 'C'])
8
+ class SimpleGenerator
9
+ def initialize(seed = Random.new_seed)
10
+ @rng = Random.new(seed)
11
+ @range = *('A'..'Z')
12
+ end
13
+
14
+ def range(range)
15
+ @range = range.to_a
16
+ self
17
+ end
18
+
19
+ def get
20
+ idx = @rng.rand(@range.size)
21
+ @range[idx]
22
+ end
23
+
24
+ def repeat(amount)
25
+ result = []
26
+ amount.times { result << get }
27
+ result
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DbmsBuffers
4
+ LRUBufferEntry = Struct.new(:value, :timestamp)
5
+
6
+ # The LRUBuffer applies least recently used as eviction strategy.
7
+ # For this, it saves the time of the last access with each buffered value.
8
+ class LRUBuffer
9
+ attr_reader :size
10
+
11
+ def initialize(size)
12
+ @size = size
13
+ @buffer = []
14
+ @time = 0
15
+ end
16
+
17
+ def access(value)
18
+ @time += 1
19
+ try_touch(value) || try_insert_new(value) || try_replace(value)
20
+ end
21
+
22
+ def entries
23
+ @buffer.clone
24
+ end
25
+
26
+ def contains?(value)
27
+ @buffer.any? { |entry| value == entry.value }
28
+ end
29
+
30
+ def used
31
+ @buffer.size
32
+ end
33
+
34
+ private
35
+
36
+ def try_touch(value)
37
+ result = contains? value
38
+ touch(value) if result
39
+ result
40
+ end
41
+
42
+ def try_insert_new(value)
43
+ return false if used == @size
44
+
45
+ entry = LRUBufferEntry.new(value, @time)
46
+ @buffer << entry
47
+
48
+ true
49
+ end
50
+
51
+ def try_replace(value)
52
+ entry = oldest_entry
53
+ entry.value = value
54
+ entry.timestamp = @time
55
+
56
+ true
57
+ end
58
+
59
+ def index(value)
60
+ @buffer.index { |entry| entry.value == value }
61
+ end
62
+
63
+ def oldest_entry
64
+ @buffer.min { |entry_a, entry_b| entry_a.timestamp <=> entry_b.timestamp }
65
+ end
66
+
67
+ def touch(value)
68
+ @buffer.find { |entry| entry.value == value }.timestamp = @time
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DbmsBuffers
4
+ VERSION = '0.1.1'
5
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbms_buffers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Dossinger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: reek
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.5.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.78'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.78'
83
+ description:
84
+ email:
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".reek.yml"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - dbms_buffers.gemspec
105
+ - lib/dbms_buffers.rb
106
+ - lib/dbms_buffers/clock.rb
107
+ - lib/dbms_buffers/generators.rb
108
+ - lib/dbms_buffers/lru.rb
109
+ - lib/dbms_buffers/version.rb
110
+ homepage: https://github.com/contradictioned/dbms-buffers
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ homepage_uri: https://github.com/contradictioned/dbms-buffers
115
+ source_code_uri: https://github.com/contradictioned/dbms-buffers
116
+ changelog_uri: https://github.com/contradictioned/dbms-buffers/blob/master/CHANGELOG.md
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubygems_version: 3.1.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Buffer implementations that can be found in typical DBMS lectures.
136
+ test_files: []