circular_queue 0.0.5 → 1.0.0

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: ec86881eee3351cb2f8f6dc4bd4bb36991a7a76331f5f31f51c108e0743b1d9b
4
+ data.tar.gz: 187c3358ade45e3e313b501182d1091abf9800949d23f6dc4aa6aef0862f1e33
5
+ SHA512:
6
+ metadata.gz: 7431d4752102a6e68a6196fdf3c3c766dca1c3db468a03d086aabda32f02831613c257c9b6e9dd517709e3f5f7f28ed7dfa1b099efe8fe0ca8b9386a74c9e993
7
+ data.tar.gz: 893ee822375a8b0b846e333967629e6a70cbb98e966f3b618283ec39b46ea3f8960365eec108fa33d9aca931332715c570390ff91dd26d0496ebbf592ada6c15
data/.gitignore CHANGED
@@ -1,7 +1,9 @@
1
- bin/
2
1
  *.gem
3
2
  .bundle
4
- Gemfile.lock
5
- pkg/*
6
- doc
7
3
  .yardoc
4
+ Gemfile.lock
5
+ /tags
6
+ /bin/
7
+ /doc/
8
+ /pkg/*
9
+ /spec/failures.txt
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --format doc
3
- --order random
2
+ --require spec_helper
@@ -1,9 +1,12 @@
1
+ dist: xenial
2
+ language: ruby
1
3
  rvm:
2
- - 1.9.2
3
- - 1.9.3
4
- # - rbx-2.0 <https://github.com/rubinius/rubinius/issues/811>
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
5
7
  - jruby
6
- env:
7
- - JRUBY_OPTS="--1.9" RBXOPT="-X19"
8
+ before_install:
9
+ - gem update --system
10
+ - gem install bundler
8
11
  notifications:
9
12
  disabled: true
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2019-04-18
11
+ ### Added
12
+ - Changelog (you're looking at!).
13
+
14
+ ### Changed
15
+ - Extract MIT License into its own file, for GitHub UX.
16
+
17
+ ### Removed
18
+ - Drop support for older Rubies (Ruby 2.4+).
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2011 Andy Lindeman
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,36 +1,23 @@
1
1
  # Circular Queue
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/circular_queue.svg)](https://badge.fury.io/rb/circular_queue)
3
4
  [![Build Status](https://secure.travis-ci.org/alindeman/circular_queue.png)](http://travis-ci.org/alindeman/circular_queue)
4
5
 
5
- Data structure that uses a single, fixed-size buffer as if it were connected
6
- end-to-end.
6
+ Data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
7
7
 
8
- **circular_queue** *requires* Ruby 1.9 or a Ruby implementation that
9
- supports 1.9 syntax and standard library (e.g., JRuby in 1.9 mode;
10
- Rubinius 2.0 should work if/when Mutex#sleep is implemented).
8
+ ### Support
11
9
 
12
- Documentation, including example use, is covered in the [API
13
- Docs](http://rdoc.info/github/alindeman/circular_queue/master/CircularQueue).
10
+ `circular_queue` officially supports the [currently supported Ruby versions][rubies], which tends to mean the last three major release.
11
+ As of now that's Ruby 2.6, 2.5, and 2.4.
12
+ Older Rubies, back to Ruby 1.9, *might* work, but are not officially supported.
14
13
 
15
- ## License
14
+ ### Documentation
16
15
 
17
- Copyright (c) 2011 Andy Lindeman
16
+ Documentation, including example use, is covered in the [API Docs][api-docs].
18
17
 
19
- Permission is hereby granted, free of charge, to any person obtaining a
20
- copy of this software and associated documentation files (the
21
- "Software"), to deal in the Software without restriction, including
22
- without limitation the rights to use, copy, modify, merge, publish,
23
- distribute, sublicense, and/or sell copies of the Software, and to
24
- permit persons to whom the Software is furnished to do so, subject to
25
- the following conditions:
18
+ ### [Changelog](CHANGELOG.md)
26
19
 
27
- The above copyright notice and this permission notice shall be included
28
- in all copies or substantial portions of the Software.
20
+ ### [License](LICENSE.md)
29
21
 
30
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ [api-docs]: http://rdoc.info/github/alindeman/circular_queue/master/CircularQueue
23
+ [rubies]: https://www.ruby-lang.org/en/downloads/branches/ "Ruby Maintenance Branches"
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
- task :default => :spec
5
+ task default: :spec
@@ -1,23 +1,31 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "circular_queue"
6
- s.version = "0.0.5"
6
+ s.version = "1.0.0"
7
7
  s.authors = ["Andy Lindeman"]
8
8
  s.email = ["alindeman@gmail.com"]
9
+
10
+ s.summary = "Data structure that uses a single, fixed-size buffer as if it were connected end-to-end"
9
11
  s.homepage = "https://github.com/alindeman/circular_queue"
10
- s.summary = %q{Data structure that uses a single, fixed-size buffer as if it were connected end-to-end}
11
- s.description = %q{A circular queue (also called a circular buffer or ring buffer) is useful when buffering data streams}
12
+ s.description = "A circular queue (also called a circular buffer or ring buffer) is useful when buffering data streams"
13
+ s.license = "MIT"
14
+ s.metadata = {
15
+ "homepage_uri" => "https://github.com/alindeman/circular_queue",
16
+ "changelog_uri" => "https://github.com/alindeman/circular_queue/blob/master/CHANGELOG.md",
17
+ "source_code_uri" => "https://github.com/alindeman/circular_queue",
18
+ }
12
19
 
13
20
  s.rubyforge_project = "circular_queue"
14
21
 
15
22
  s.files = `git ls-files`.split("\n")
16
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
25
  s.require_paths = ["lib"]
19
26
 
20
- s.add_development_dependency "rspec", "~>2.11.0"
27
+ s.add_development_dependency "bundler", "~> 2.0"
28
+ s.add_development_dependency "rspec", "~> 3.8.0"
21
29
  s.add_development_dependency "rake"
22
30
  s.add_development_dependency "yard"
23
31
  end
@@ -1,5 +1,3 @@
1
- require "thread"
2
-
3
1
  # A thread-safe queue with a size limitation. When more elements than the
4
2
  # capacity are added, the queue either loops back on itself (removing the
5
3
  # oldest elements first) or raises an error (if `enq!` is used).
@@ -38,7 +36,7 @@ class CircularQueue
38
36
  @data = Array.new(capacity)
39
37
 
40
38
  @mutex = Mutex.new
41
- @waiting = Array.new
39
+ @waiting = []
42
40
 
43
41
  clear
44
42
  end
@@ -73,7 +71,7 @@ class CircularQueue
73
71
  # @raise [ThreadError] non_block was true and the queue was empty
74
72
  def deq(non_block = false)
75
73
  @mutex.synchronize do
76
- while true
74
+ loop do
77
75
  if empty?
78
76
  raise ThreadError.new("Queue is empty") if non_block
79
77
 
@@ -119,7 +117,7 @@ class CircularQueue
119
117
  end
120
118
 
121
119
  # Returns the last/most recent item in the queue
122
- # @return [Object]
120
+ # @return [Object]
123
121
  # Peek at last item without removing
124
122
  def back
125
123
  @mutex.synchronize do
@@ -173,12 +171,10 @@ class CircularQueue
173
171
  end
174
172
 
175
173
  def wakeup_next_waiter
176
- begin
177
- if thread = @waiting.shift
178
- thread.wakeup
179
- end
180
- rescue ThreadError
181
- retry
174
+ if thread = @waiting.shift
175
+ thread.wakeup
182
176
  end
177
+ rescue ThreadError
178
+ retry
183
179
  end
184
180
  end
@@ -1,76 +1,74 @@
1
- require "spec_helper"
2
-
3
- describe CircularQueue do
1
+ RSpec.describe CircularQueue do
4
2
  let(:capacity) { 5 }
5
- subject { described_class.new(capacity) }
3
+ subject(:queue) { described_class.new(capacity) }
6
4
 
7
5
  describe "initialization" do
8
6
  it "can be initialized with a capacity" do
9
- subject.capacity.should == capacity
7
+ expect(queue.capacity).to eq(capacity)
10
8
  end
11
9
  end
12
10
 
13
11
  describe "adding items" do
14
12
  it "accepts new items" do
15
- subject.enq(1234)
16
- subject.front.should == 1234
17
- subject.back.should == 1234
18
- subject.deq.should == 1234
13
+ queue.enq(1234)
14
+ expect(queue.front).to eq(1234)
15
+ expect(queue.back).to eq(1234)
16
+ expect(queue.deq).to eq(1234)
19
17
  end
20
18
 
21
19
  it "increases its size when a new item is added" do
22
- subject.enq(1234)
23
- subject.size.should == 1
20
+ queue.enq(1234)
21
+ expect(queue.size).to eq(1)
24
22
  end
25
23
 
26
24
  it "allows for peeking at first and last items" do
27
- subject.enq(1)
25
+ queue.enq(1)
28
26
 
29
- subject.front.should == 1
30
- subject.back.should == 1
27
+ expect(queue.front).to eq(1)
28
+ expect(queue.back).to eq(1)
31
29
 
32
- 2.upto(capacity) { |i| subject.enq(i) }
33
- subject.front.should == 1
34
- subject.back.should == capacity
30
+ 2.upto(capacity) { |i| queue.enq(i) }
31
+ expect(queue.front).to eq(1)
32
+ expect(queue.back).to eq(capacity)
35
33
  end
36
34
 
37
35
  it "presents the appearance of accepting infinite items" do
38
- 1.upto(capacity * 2) { |i| subject.enq(i) }
36
+ 1.upto(capacity * 2) { |i| queue.enq(i) }
39
37
 
40
38
  1.upto(capacity) do |i|
41
- subject.deq.should == i + capacity
39
+ expect(queue.deq).to eq(i + capacity)
42
40
  end
43
41
 
44
- subject.size.should be_zero
42
+ expect(queue.size).to be_zero
45
43
  end
46
44
 
47
45
  it "raises an error if the queue is full and enq! is used to add items" do
48
- 1.upto(capacity) { |i| subject.enq(i) }
46
+ 1.upto(capacity) { |i| queue.enq(i) }
49
47
 
50
48
  expect {
51
- subject.enq!(1)
49
+ queue.enq!(1)
52
50
  }.to raise_error(ThreadError)
53
51
  end
54
52
  end
55
53
 
56
54
  describe "removing items" do
57
55
  it "removes items from the queue until the queue is empty" do
58
- 1.upto(capacity) { |i| subject.enq(i) }
56
+ 1.upto(capacity) { |i| queue.enq(i) }
59
57
 
60
58
  1.upto(capacity) do |i|
61
- subject.deq.should == i
59
+ expect(queue.deq).to eq(i)
62
60
  end
63
61
 
64
- subject.size.should be_zero
62
+ expect(queue.size).to be_zero
65
63
  end
66
64
 
67
65
  context "when empty" do
68
66
  context "non-blocking" do
69
67
  it "raises a ThreadError if the queue is empty" do
70
- subject.clear
68
+ queue.clear
71
69
 
72
70
  expect {
73
- subject.deq(true)
71
+ queue.deq(true)
74
72
  }.to raise_error(ThreadError)
75
73
  end
76
74
  end
@@ -82,15 +80,15 @@ describe CircularQueue do
82
80
  enqueue = false
83
81
  done = false
84
82
 
85
- enqueue_thread = Thread.new do
83
+ Thread.new do
86
84
  until done
87
- subject.enq(1) if enqueue
85
+ queue.enq(1) if enqueue
88
86
  end
89
87
  end
90
88
 
91
89
  begin
92
90
  enqueue = true
93
- subject.deq.should == 1
91
+ expect(queue.deq).to eq(1)
94
92
  ensure
95
93
  done = true
96
94
  end
@@ -100,35 +98,35 @@ describe CircularQueue do
100
98
 
101
99
  context "when full" do
102
100
  it "overrides elements at the beginning of the queue" do
103
- 1.upto(capacity) { |i| subject.enq(i) }
101
+ 1.upto(capacity) { |i| queue.enq(i) }
104
102
 
105
103
  # Queue is full
106
- subject.enq(capacity + 1)
104
+ queue.enq(capacity + 1)
107
105
 
108
106
  # Returns the item that's been waiting the longest, not the overridden
109
107
  # value. 1 was overridden.
110
- subject.pop.should == 2
108
+ expect(queue.pop).to eq(2)
111
109
  end
112
110
  end
113
111
  end
114
112
 
115
113
  describe "clearing the queue" do
116
114
  it "removes all items from the queue" do
117
- subject.enq(1)
118
- subject.clear
115
+ queue.enq(1)
116
+ queue.clear
119
117
 
120
- subject.size.should be_zero
118
+ expect(queue.size).to be_zero
121
119
  end
122
120
  end
123
121
 
124
122
  describe "data" do
125
123
  it "allows taking a snapshot of the data in the queue" do
126
- subject.enq(1)
127
- subject.enq(2)
128
- subject.enq(3)
129
- subject.deq
124
+ queue.enq(1)
125
+ queue.enq(2)
126
+ queue.enq(3)
127
+ queue.deq
130
128
 
131
- subject.data.should == [2, 3]
129
+ expect(queue.data).to eq([2, 3])
132
130
  end
133
131
  end
134
132
  end
@@ -1 +1,41 @@
1
- require File.expand_path("../lib/circular_queue", File.dirname(__FILE__))
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+
17
+ require "circular_queue"
18
+
19
+ RSpec.configure do |config|
20
+ config.expect_with :rspec do |expectations|
21
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
22
+ end
23
+
24
+ config.mock_with :rspec do |mocks|
25
+ mocks.verify_partial_doubles = true
26
+ end
27
+
28
+ config.shared_context_metadata_behavior = :apply_to_host_groups
29
+ config.filter_run_when_matching :focus
30
+ config.example_status_persistence_file_path = "spec/failures.txt"
31
+ config.disable_monkey_patching!
32
+ config.warnings = true
33
+
34
+ if config.files_to_run.one?
35
+ config.default_formatter = "doc"
36
+ end
37
+
38
+ config.profile_examples = 10
39
+ config.order = :random
40
+ Kernel.srand config.seed
41
+ end
metadata CHANGED
@@ -1,62 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circular_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andy Lindeman
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-12 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
13
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'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: rspec
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ~>
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
- version: 2.11.0
33
+ version: 3.8.0
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ~>
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
- version: 2.11.0
40
+ version: 3.8.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: yard
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  description: A circular queue (also called a circular buffer or ring buffer) is useful
@@ -67,10 +74,12 @@ executables: []
67
74
  extensions: []
68
75
  extra_rdoc_files: []
69
76
  files:
70
- - .gitignore
71
- - .rspec
72
- - .travis.yml
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
73
81
  - Gemfile
82
+ - LICENSE.md
74
83
  - README.md
75
84
  - Rakefile
76
85
  - circular_queue.gemspec
@@ -78,37 +87,32 @@ files:
78
87
  - spec/circular_queue_spec.rb
79
88
  - spec/spec_helper.rb
80
89
  homepage: https://github.com/alindeman/circular_queue
81
- licenses: []
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ homepage_uri: https://github.com/alindeman/circular_queue
94
+ changelog_uri: https://github.com/alindeman/circular_queue/blob/master/CHANGELOG.md
95
+ source_code_uri: https://github.com/alindeman/circular_queue
82
96
  post_install_message:
83
97
  rdoc_options: []
84
98
  require_paths:
85
99
  - lib
86
100
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
101
  requirements:
89
- - - ! '>='
102
+ - - ">="
90
103
  - !ruby/object:Gem::Version
91
104
  version: '0'
92
- segments:
93
- - 0
94
- hash: -1552142011722040456
95
105
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
106
  requirements:
98
- - - ! '>='
107
+ - - ">="
99
108
  - !ruby/object:Gem::Version
100
109
  version: '0'
101
- segments:
102
- - 0
103
- hash: -1552142011722040456
104
110
  requirements: []
105
- rubyforge_project: circular_queue
106
- rubygems_version: 1.8.24
111
+ rubygems_version: 3.0.3
107
112
  signing_key:
108
- specification_version: 3
113
+ specification_version: 4
109
114
  summary: Data structure that uses a single, fixed-size buffer as if it were connected
110
115
  end-to-end
111
116
  test_files:
112
117
  - spec/circular_queue_spec.rb
113
118
  - spec/spec_helper.rb
114
- has_rdoc: