em-priority-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/Gemfile.lock +1 -1
- data/README.md +66 -0
- data/em-priority-queue.gemspec +3 -3
- data/lib/em-priority-queue/version.rb +1 -1
- data/spec/em-priority-queue_spec.rb +26 -0
- metadata +55 -93
- data/README +0 -1
data/Gemfile.lock
CHANGED
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
EventMachine Priority Queue
|
2
|
+
=============
|
3
|
+
|
4
|
+
##Install
|
5
|
+
[sudo] gem install em-priority-queue
|
6
|
+
|
7
|
+
##Usage
|
8
|
+
|
9
|
+
**Basic**
|
10
|
+
|
11
|
+
@q = EM::PriorityQueue.new
|
12
|
+
|
13
|
+
responses = []
|
14
|
+
EM.run do
|
15
|
+
|
16
|
+
|
17
|
+
@q.push("Mike", 20)
|
18
|
+
@q.push("Alex", 21)
|
19
|
+
@q.push("Bob", 22)
|
20
|
+
@q.push("Tim", 18)
|
21
|
+
|
22
|
+
4.times do
|
23
|
+
@q.pop do |e|
|
24
|
+
responses << e
|
25
|
+
EM.stop if responses.size == 4
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
responses[0] # Bob
|
31
|
+
responses[1] # Alex
|
32
|
+
responses[2] # Mike
|
33
|
+
responses[3] # Tim
|
34
|
+
|
35
|
+
**Custom Priority**
|
36
|
+
|
37
|
+
@q = EM::PriorityQueue.new {|x,y| x < y}
|
38
|
+
|
39
|
+
responses = []
|
40
|
+
EM.run do
|
41
|
+
|
42
|
+
|
43
|
+
@q.push("Mike", 20)
|
44
|
+
@q.push("Alex", 21)
|
45
|
+
@q.push("Bob", 22)
|
46
|
+
@q.push("Tim", 18)
|
47
|
+
|
48
|
+
4.times do
|
49
|
+
@q.pop do |e|
|
50
|
+
responses << e
|
51
|
+
EM.stop if responses.size == 4
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
responses[0] # Tim
|
57
|
+
responses[1] # Mike
|
58
|
+
responses[2] # Alex
|
59
|
+
responses[3] # Bob
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
To see all examples/cases, see the spec file.
|
65
|
+
|
66
|
+
|
data/em-priority-queue.gemspec
CHANGED
@@ -4,13 +4,13 @@ require "em-priority-queue/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "em-priority-queue"
|
7
|
-
s.version = EventMachine::PriorityQueue::VERSION
|
7
|
+
s.version = EventMachine::PriorityQueue::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Mike Lewis"]
|
10
10
|
s.email = ["ft.mikelewis@gmail.com"]
|
11
11
|
s.homepage = ""
|
12
|
-
s.summary = %q{
|
13
|
-
s.description = %q{
|
12
|
+
s.summary = %q{EventMachine Priority Queue}
|
13
|
+
s.description = %q{Asynchronous Priority Queue with EventMachine}
|
14
14
|
|
15
15
|
s.rubyforge_project = "em-priority-queue"
|
16
16
|
|
@@ -90,5 +90,31 @@ describe EventMachine::PriorityQueue do
|
|
90
90
|
responses[3].should == "Tim"
|
91
91
|
|
92
92
|
end
|
93
|
+
it "should give elements in the order of their priority - custom ordering schema" do
|
94
|
+
@q = EM::PriorityQueue.new {|x,y| x < y}
|
95
|
+
responses = []
|
96
|
+
EM.run do
|
97
|
+
|
98
|
+
|
99
|
+
@q.push("Mike", 20)
|
100
|
+
@q.push("Alex", 21)
|
101
|
+
@q.push("Bob", 22)
|
102
|
+
@q.push("Tim", 18)
|
103
|
+
|
104
|
+
4.times do
|
105
|
+
@q.pop do |e|
|
106
|
+
responses << e
|
107
|
+
EM.stop if responses.size == 4
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
responses[0].should == "Tim"
|
113
|
+
responses[1].should == "Mike"
|
114
|
+
responses[2].should == "Alex"
|
115
|
+
responses[3].should == "Bob"
|
116
|
+
|
117
|
+
end
|
118
|
+
|
93
119
|
end
|
94
120
|
end
|
metadata
CHANGED
@@ -1,99 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-priority-queue
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Mike Lewis
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: eventmachine
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2156155760 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 62196357
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 0
|
33
|
-
- 0
|
34
|
-
- beta
|
35
|
-
- 3
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
36
21
|
version: 1.0.0.beta.3
|
37
22
|
type: :runtime
|
38
|
-
version_requirements: *id001
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: algorithms
|
41
23
|
prerelease: false
|
42
|
-
|
24
|
+
version_requirements: *2156155760
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: algorithms
|
27
|
+
requirement: &2156146000 !ruby/object:Gem::Requirement
|
43
28
|
none: false
|
44
|
-
requirements:
|
29
|
+
requirements:
|
45
30
|
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
hash: 19
|
48
|
-
segments:
|
49
|
-
- 0
|
50
|
-
- 3
|
51
|
-
- 0
|
31
|
+
- !ruby/object:Gem::Version
|
52
32
|
version: 0.3.0
|
53
33
|
type: :runtime
|
54
|
-
version_requirements: *id002
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
34
|
prerelease: false
|
58
|
-
|
35
|
+
version_requirements: *2156146000
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2156140280 !ruby/object:Gem::Requirement
|
59
39
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
segments:
|
65
|
-
- 0
|
66
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
67
44
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
45
|
prerelease: false
|
72
|
-
|
46
|
+
version_requirements: *2156140280
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2156061260 !ruby/object:Gem::Requirement
|
73
50
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
81
55
|
type: :development
|
82
|
-
|
83
|
-
|
84
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2156061260
|
58
|
+
description: Asynchronous Priority Queue with EventMachine
|
59
|
+
email:
|
85
60
|
- ft.mikelewis@gmail.com
|
86
61
|
executables: []
|
87
|
-
|
88
62
|
extensions: []
|
89
|
-
|
90
63
|
extra_rdoc_files: []
|
91
|
-
|
92
|
-
files:
|
64
|
+
files:
|
93
65
|
- .gitignore
|
94
66
|
- Gemfile
|
95
67
|
- Gemfile.lock
|
96
|
-
- README
|
68
|
+
- README.md
|
97
69
|
- Rakefile
|
98
70
|
- em-priority-queue.gemspec
|
99
71
|
- lib/em-priority-queue.rb
|
@@ -101,40 +73,30 @@ files:
|
|
101
73
|
- lib/em-priority-queue/version.rb
|
102
74
|
- spec/em-priority-queue_spec.rb
|
103
75
|
- spec/spec_helper.rb
|
104
|
-
|
105
|
-
homepage: ""
|
76
|
+
homepage: ''
|
106
77
|
licenses: []
|
107
|
-
|
108
78
|
post_install_message:
|
109
79
|
rdoc_options: []
|
110
|
-
|
111
|
-
require_paths:
|
80
|
+
require_paths:
|
112
81
|
- lib
|
113
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
83
|
none: false
|
115
|
-
requirements:
|
116
|
-
- -
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
|
119
|
-
|
120
|
-
- 0
|
121
|
-
version: "0"
|
122
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
89
|
none: false
|
124
|
-
requirements:
|
125
|
-
- -
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
version: "0"
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
131
94
|
requirements: []
|
132
|
-
|
133
95
|
rubyforge_project: em-priority-queue
|
134
|
-
rubygems_version: 1.
|
96
|
+
rubygems_version: 1.8.10
|
135
97
|
signing_key:
|
136
98
|
specification_version: 3
|
137
|
-
summary:
|
138
|
-
test_files:
|
99
|
+
summary: EventMachine Priority Queue
|
100
|
+
test_files:
|
139
101
|
- spec/em-priority-queue_spec.rb
|
140
102
|
- spec/spec_helper.rb
|
data/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
EM Priority Queue
|