circular_queue 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/README.md +27 -0
- data/Rakefile +4 -0
- data/circular_queue.gemspec +1 -1
- data/lib/circular_queue.rb +7 -7
- metadata +11 -9
data/.travis.yml
ADDED
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Circular Queue
|
2
|
+
|
3
|
+
Documentation, including example use, is covered in the [API
|
4
|
+
Docs](http://rdoc.info/github/alindeman/circular_queue/master/CircularQueue).
|
5
|
+
|
6
|
+
## License
|
7
|
+
|
8
|
+
Copyright (c) 2011 Andy Lindeman
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
11
|
+
copy of this software and associated documentation files (the
|
12
|
+
"Software"), to deal in the Software without restriction, including
|
13
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included
|
19
|
+
in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
22
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
24
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
25
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
26
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
27
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
data/circular_queue.gemspec
CHANGED
data/lib/circular_queue.rb
CHANGED
@@ -19,8 +19,8 @@ require "thread"
|
|
19
19
|
# q << 3 # => [1, 2, 3]
|
20
20
|
#
|
21
21
|
# # Elements are replaced when the queue reaches capacity
|
22
|
-
# q << 4 # => [
|
23
|
-
# q << 5 # => [4, 5
|
22
|
+
# q << 4 # => [2, 3, 4]
|
23
|
+
# q << 5 # => [3, 4, 5]
|
24
24
|
class CircularQueue
|
25
25
|
# Returns the maximum number of elements that can be enqueued
|
26
26
|
# @return [Integer]
|
@@ -32,7 +32,7 @@ class CircularQueue
|
|
32
32
|
alias length size
|
33
33
|
|
34
34
|
# Creates a new queue of the specified capacity
|
35
|
-
# @param [Integer] the maximum capacity of the queue
|
35
|
+
# @param [Integer] capacity the maximum capacity of the queue
|
36
36
|
def initialize(capacity)
|
37
37
|
@capacity = capacity
|
38
38
|
@data = Array.new(capacity)
|
@@ -44,7 +44,7 @@ class CircularQueue
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Adds an item to the queue
|
47
|
-
# @param [Object] item to add
|
47
|
+
# @param [Object] item item to add
|
48
48
|
def enq(item)
|
49
49
|
@mutex.synchronize do
|
50
50
|
enq_item(item)
|
@@ -55,7 +55,7 @@ class CircularQueue
|
|
55
55
|
alias push enq
|
56
56
|
|
57
57
|
# Adds an item to the queue, raising an error if the queue is full
|
58
|
-
# @param [Object] item to add
|
58
|
+
# @param [Object] item item to add
|
59
59
|
# @raise [ThreadError] queue is full
|
60
60
|
def enq!(item)
|
61
61
|
@mutex.synchronize do
|
@@ -68,8 +68,8 @@ class CircularQueue
|
|
68
68
|
alias push! enq!
|
69
69
|
|
70
70
|
# Removes an item from the queue
|
71
|
-
# @param [Boolean] true to raise an error if the queue is empty;
|
72
|
-
# waits for an item to arrive from another thread
|
71
|
+
# @param [Boolean] non_block true to raise an error if the queue is empty;
|
72
|
+
# otherwise, waits for an item to arrive from another thread
|
73
73
|
# @raise [ThreadError] non_block was true and the queue was empty
|
74
74
|
def deq(non_block = false)
|
75
75
|
@mutex.synchronize 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.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-17 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2168477680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.7.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2168477680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2168476120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2168476120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &2168475140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2168475140
|
47
47
|
description: A circular queue (also called a circular buffer or ring buffer) is useful
|
48
48
|
when buffering data streams
|
49
49
|
email:
|
@@ -53,7 +53,9 @@ extensions: []
|
|
53
53
|
extra_rdoc_files: []
|
54
54
|
files:
|
55
55
|
- .gitignore
|
56
|
+
- .travis.yml
|
56
57
|
- Gemfile
|
58
|
+
- README.md
|
57
59
|
- Rakefile
|
58
60
|
- circular_queue.gemspec
|
59
61
|
- lib/circular_queue.rb
|
@@ -73,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
75
|
version: '0'
|
74
76
|
segments:
|
75
77
|
- 0
|
76
|
-
hash:
|
78
|
+
hash: 2997727403092005944
|
77
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
80
|
none: false
|
79
81
|
requirements:
|
@@ -82,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
84
|
version: '0'
|
83
85
|
segments:
|
84
86
|
- 0
|
85
|
-
hash:
|
87
|
+
hash: 2997727403092005944
|
86
88
|
requirements: []
|
87
89
|
rubyforge_project: circular_queue
|
88
90
|
rubygems_version: 1.8.10
|