circular_queue 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format doc
3
+ --order random
@@ -1,9 +1,9 @@
1
1
  rvm:
2
- - 1.8.7
3
2
  - 1.9.2
4
3
  - 1.9.3
5
- - rbx-2.0
4
+ # - rbx-2.0 <https://github.com/rubinius/rubinius/issues/811>
6
5
  - jruby
7
- - ree
6
+ env:
7
+ - JRUBY_OPTS="--1.9" RBXOPT="-X19"
8
8
  notifications:
9
9
  disabled: true
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Circular Queue
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/alindeman/circular_queue.png)](http://travis-ci.org/alindeman/circular_queue)
4
+
5
+ **circular_queue** *requires* Ruby 1.9 or a Ruby implementation that
6
+ supports 1.9 syntax and standard library (e.g., JRuby in 1.9 mode;
7
+ Rubinius 2.0 should work if/when Mutex#sleep is implemented).
8
+
3
9
  Documentation, including example use, is covered in the [API
4
10
  Docs](http://rdoc.info/github/alindeman/circular_queue/master/CircularQueue).
5
11
 
@@ -3,10 +3,10 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "circular_queue"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
7
7
  s.authors = ["Andy Lindeman"]
8
8
  s.email = ["alindeman@gmail.com"]
9
- s.homepage = ""
9
+ s.homepage = "https://github.com/alindeman/circular_queue"
10
10
  s.summary = %q{Data structure that uses a single, fixed-size buffer as if it were connected end-to-end}
11
11
  s.description = %q{A circular queue (also called a circular buffer or ring buffer) is useful when buffering data streams}
12
12
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_development_dependency "rspec", "~>2.7.0"
21
- s.add_development_dependency "rake", "~>0.9.2"
20
+ s.add_development_dependency "rspec", "~>2.10.0"
21
+ s.add_development_dependency "rake"
22
22
  s.add_development_dependency "yard"
23
23
  end
@@ -120,7 +120,12 @@ class CircularQueue
120
120
  def enq_item(item)
121
121
  @data[@back] = item
122
122
 
123
- @size += 1 unless full?
123
+ if full?
124
+ @front += 1
125
+ @front %= @capacity
126
+ else
127
+ @size += 1
128
+ end
124
129
 
125
130
  @back += 1
126
131
  @back %= @capacity
@@ -84,6 +84,19 @@ describe CircularQueue do
84
84
  end
85
85
  end
86
86
  end
87
+
88
+ context "when full" do
89
+ it "overrides elements at the beginning of the queue" do
90
+ 1.upto(capacity) { |i| subject.enq(i) }
91
+
92
+ # Queue is full
93
+ subject.enq(capacity + 1)
94
+
95
+ # Returns the item that's been waiting the longest, not the overridden
96
+ # value. 1 was overridden.
97
+ subject.pop.should == 2
98
+ end
99
+ end
87
100
  end
88
101
 
89
102
  describe "clearing the queue" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circular_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,43 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-17 00:00:00.000000000Z
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2168477680 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.7.0
21
+ version: 2.10.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2168477680
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.10.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &2168476120 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ~>
35
+ - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: 0.9.2
37
+ version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2168476120
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: yard
38
- requirement: &2168475140 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2168475140
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: A circular queue (also called a circular buffer or ring buffer) is useful
48
63
  when buffering data streams
49
64
  email:
@@ -53,6 +68,7 @@ extensions: []
53
68
  extra_rdoc_files: []
54
69
  files:
55
70
  - .gitignore
71
+ - .rspec
56
72
  - .travis.yml
57
73
  - Gemfile
58
74
  - README.md
@@ -61,7 +77,7 @@ files:
61
77
  - lib/circular_queue.rb
62
78
  - spec/circular_queue_spec.rb
63
79
  - spec/spec_helper.rb
64
- homepage: ''
80
+ homepage: https://github.com/alindeman/circular_queue
65
81
  licenses: []
66
82
  post_install_message:
67
83
  rdoc_options: []
@@ -75,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
91
  version: '0'
76
92
  segments:
77
93
  - 0
78
- hash: 2997727403092005944
94
+ hash: -217273425497455269
79
95
  required_rubygems_version: !ruby/object:Gem::Requirement
80
96
  none: false
81
97
  requirements:
@@ -84,15 +100,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
100
  version: '0'
85
101
  segments:
86
102
  - 0
87
- hash: 2997727403092005944
103
+ hash: -217273425497455269
88
104
  requirements: []
89
105
  rubyforge_project: circular_queue
90
- rubygems_version: 1.8.10
106
+ rubygems_version: 1.8.23
91
107
  signing_key:
92
108
  specification_version: 3
93
109
  summary: Data structure that uses a single, fixed-size buffer as if it were connected
94
110
  end-to-end
95
- test_files:
96
- - spec/circular_queue_spec.rb
97
- - spec/spec_helper.rb
111
+ test_files: []
98
112
  has_rdoc: