deque 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.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/deque.gemspec +28 -0
- data/ext/deque/extconf.rb +3 -0
- data/ext/deque/rubymain.cpp +428 -0
- data/lib/deque/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c65845c668169e8cfc2f5141b808c9dce3490d1a
|
4
|
+
data.tar.gz: af586eef828b492e5b35e81fb4a7783aeede8883
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc47a1aadf9c213a655a167be61b588b7e7637d86d625a9a20dde8032aae66da0f9e4b6d3036f9c26ad5c17042c630e03ac5df96c64c5f003fc0de7afe43ac43
|
7
|
+
data.tar.gz: 2703c8582042b93bfabb25ef93fb8ce88d4c3dcad72607dec7a3fa63faa3283148db1e5ce2a7f90eec132149b49ded70fa77442ec21ef4ae8191300afb76edaa
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at wyhaines@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
deque (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.8.3)
|
10
|
+
rake (10.4.2)
|
11
|
+
rake-compiler (1.0.1)
|
12
|
+
rake
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (~> 1.12)
|
19
|
+
deque!
|
20
|
+
minitest (~> 5.0)
|
21
|
+
rake (~> 10.0)
|
22
|
+
rake-compiler
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kirk Haines
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Deque
|
2
|
+
|
3
|
+
Deque is a wrapper around the standard C++ data structure of the same name. A Deque provides a queue structure that can efficiently handle insertions and removals of data from both the front and the back of the structure.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'deque'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install deque
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The API is essentially the same as that of a Ruby Array.
|
24
|
+
|
25
|
+
* TODO: This code has been around in my toolbox for many years, and the API almost certainly can be cleaned up so that it is a much more feature-for-feature compatible struture to the current Ruby Array.
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deque. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rake/extensiontask"
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
t.libs << "lib"
|
8
|
+
t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
end
|
10
|
+
|
11
|
+
Rake::ExtensionTask.new(:deque)
|
12
|
+
|
13
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "deque"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/deque.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deque/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "deque"
|
8
|
+
spec.version = Deque::VERSION
|
9
|
+
spec.authors = ["Kirk Haines"]
|
10
|
+
spec.email = ["wyhaines@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Deque data structure for Ruby.}
|
13
|
+
spec.description = %q{A Deque is a queue type data structure that allows efficient insertion and deletion from both ends of the queue. This implementation wrapps the standard C++ structure of the same name.}
|
14
|
+
spec.homepage = "http://github.com/wyhaines/deque"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.extensions = %w[ext/deque/extconf.rb]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "rake-compiler", "~> 0"
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,428 @@
|
|
1
|
+
#include <deque>
|
2
|
+
#include <iostream>
|
3
|
+
#include <string>
|
4
|
+
using namespace std;
|
5
|
+
|
6
|
+
#include <ruby.h>
|
7
|
+
|
8
|
+
/* static VALUE DequeClassTop; */
|
9
|
+
static VALUE DequeClass;
|
10
|
+
|
11
|
+
|
12
|
+
static void deque_mark (deque<VALUE>* dq)
|
13
|
+
{
|
14
|
+
deque<VALUE>::iterator q_iterator;
|
15
|
+
if (dq) {
|
16
|
+
for ( q_iterator = (*dq).begin(); q_iterator != (*dq).end(); q_iterator++ ) {
|
17
|
+
rb_gc_mark(*q_iterator);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
static void deque_free (deque<VALUE>* dq)
|
23
|
+
{
|
24
|
+
if (dq)
|
25
|
+
delete dq;
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE deque_new (VALUE self)
|
29
|
+
{
|
30
|
+
deque<VALUE>* dq = new deque<VALUE>;
|
31
|
+
VALUE v = Data_Wrap_Struct (DequeClass, deque_mark, deque_free, dq);
|
32
|
+
return v;
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE deque_push_front (VALUE self, VALUE obj)
|
36
|
+
{
|
37
|
+
deque<VALUE>* dq = NULL;
|
38
|
+
Data_Get_Struct (self, deque<VALUE>, dq);
|
39
|
+
if (!dq)
|
40
|
+
rb_raise (rb_eException, "No Deque Object");
|
41
|
+
|
42
|
+
(*dq).push_front(obj);
|
43
|
+
|
44
|
+
return self;
|
45
|
+
}
|
46
|
+
|
47
|
+
static VALUE deque_pop_front (VALUE self)
|
48
|
+
{
|
49
|
+
deque<VALUE>* dq = NULL;
|
50
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
51
|
+
if (!dq)
|
52
|
+
rb_raise (rb_eException, "No Deque Object");
|
53
|
+
|
54
|
+
if ((*dq).empty()) {
|
55
|
+
return Qnil;
|
56
|
+
} else {
|
57
|
+
VALUE r = (*dq).front();
|
58
|
+
(*dq).pop_front();
|
59
|
+
return r;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
static VALUE deque_push_back (VALUE self, VALUE obj)
|
64
|
+
{
|
65
|
+
deque<VALUE>* dq = NULL;
|
66
|
+
Data_Get_Struct (self, deque<VALUE>, dq);
|
67
|
+
if (!dq)
|
68
|
+
rb_raise (rb_eException, "No Deque Object");
|
69
|
+
|
70
|
+
(*dq).push_back(obj);
|
71
|
+
|
72
|
+
return self;
|
73
|
+
}
|
74
|
+
|
75
|
+
static VALUE deque_pop_back (VALUE self)
|
76
|
+
{
|
77
|
+
deque<VALUE>* dq = NULL;
|
78
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
79
|
+
if (!dq)
|
80
|
+
rb_raise (rb_eException, "No Deque Object");
|
81
|
+
|
82
|
+
if ((*dq).empty()) {
|
83
|
+
return Qnil;
|
84
|
+
} else {
|
85
|
+
VALUE r = (*dq).back();
|
86
|
+
(*dq).pop_back();
|
87
|
+
return r;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
static VALUE deque_size (VALUE self)
|
92
|
+
{
|
93
|
+
deque<VALUE>* dq = NULL;
|
94
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
95
|
+
if (!dq)
|
96
|
+
rb_raise (rb_eException, "No Deque Object");
|
97
|
+
|
98
|
+
return INT2NUM((*dq).size());
|
99
|
+
}
|
100
|
+
|
101
|
+
static VALUE deque_max_size (VALUE self)
|
102
|
+
{
|
103
|
+
deque<VALUE>* dq = NULL;
|
104
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
105
|
+
if (!dq)
|
106
|
+
rb_raise (rb_eException, "No Deque Object");
|
107
|
+
|
108
|
+
return INT2NUM((*dq).max_size());
|
109
|
+
}
|
110
|
+
|
111
|
+
static VALUE deque_clear (VALUE self)
|
112
|
+
{
|
113
|
+
deque<VALUE>* dq = NULL;
|
114
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
115
|
+
if (!dq)
|
116
|
+
rb_raise (rb_eException, "No Deque Object");
|
117
|
+
|
118
|
+
(*dq).clear();
|
119
|
+
return self;
|
120
|
+
}
|
121
|
+
|
122
|
+
static VALUE deque_empty (VALUE self)
|
123
|
+
{
|
124
|
+
deque<VALUE>* dq = NULL;
|
125
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
126
|
+
if (!dq)
|
127
|
+
rb_raise (rb_eException, "No Deque Object");
|
128
|
+
|
129
|
+
if ((*dq).empty()) {
|
130
|
+
return Qtrue;
|
131
|
+
} else {
|
132
|
+
return Qfalse;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
static VALUE deque_to_s (VALUE self)
|
137
|
+
{
|
138
|
+
VALUE s = rb_str_new2("");
|
139
|
+
ID to_s = rb_intern("to_s");
|
140
|
+
ID concat = rb_intern("concat");
|
141
|
+
|
142
|
+
deque<VALUE>* dq = NULL;
|
143
|
+
deque<VALUE>::iterator q_iterator;
|
144
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
145
|
+
if (!dq)
|
146
|
+
rb_raise (rb_eException, "No Deque Object");
|
147
|
+
|
148
|
+
for ( q_iterator = (*dq).begin(); q_iterator != (*dq).end(); q_iterator++ ) {
|
149
|
+
s = rb_str_concat(s,rb_funcall(*q_iterator, to_s, 0));
|
150
|
+
}
|
151
|
+
return rb_str_to_str(s);
|
152
|
+
}
|
153
|
+
|
154
|
+
/*
|
155
|
+
static VALUE deque_join (VALUE self, VALUE delimiter)
|
156
|
+
{
|
157
|
+
VALUE s = rb_str_new2("");
|
158
|
+
ID to_s = rb_intern("to_s");
|
159
|
+
ID concat = rb_intern("concat");
|
160
|
+
|
161
|
+
deque<VALUE>* dq = NULL;
|
162
|
+
deque<VALUE>::iterator q_iterator;
|
163
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
164
|
+
if (!dq)
|
165
|
+
rb_raise (rb_eException, "No Deque Object");
|
166
|
+
|
167
|
+
for ( q_iterator = (*dq).begin(); q_iterator != (*dq).end(); q_iterator++ ) {
|
168
|
+
rb_funcall(s,concat,1,rb_funcall(*q_iterator,to_s,0));
|
169
|
+
}
|
170
|
+
|
171
|
+
return rb_str_to_str(s);
|
172
|
+
}
|
173
|
+
*/
|
174
|
+
static VALUE deque_to_a (VALUE self)
|
175
|
+
{
|
176
|
+
VALUE ary = rb_ary_new();
|
177
|
+
ID push = rb_intern("push");
|
178
|
+
|
179
|
+
deque<VALUE>* dq = NULL;
|
180
|
+
deque<VALUE>::iterator q_iterator;
|
181
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
182
|
+
if (!dq)
|
183
|
+
rb_raise (rb_eException, "No Deque Object");
|
184
|
+
|
185
|
+
for ( q_iterator = (*dq).begin(); q_iterator != (*dq).end(); q_iterator++ ) {
|
186
|
+
//rb_funcall(ary,push,1,*q_iterator);
|
187
|
+
rb_ary_push(ary,*q_iterator);
|
188
|
+
}
|
189
|
+
|
190
|
+
return ary;
|
191
|
+
}
|
192
|
+
|
193
|
+
static VALUE deque_inspect (VALUE self)
|
194
|
+
{
|
195
|
+
VALUE s = rb_str_new2("[");
|
196
|
+
VALUE comma = rb_str_new2(",");
|
197
|
+
ID inspect = rb_intern("inspect");
|
198
|
+
ID concat = rb_intern("concat");
|
199
|
+
|
200
|
+
deque<VALUE>* dq = NULL;
|
201
|
+
deque<VALUE>::iterator q_iterator;
|
202
|
+
deque<VALUE>::iterator last_q_iterator;
|
203
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
204
|
+
if (!dq)
|
205
|
+
rb_raise (rb_eException, "No Deque Object");
|
206
|
+
|
207
|
+
last_q_iterator = (*dq).end();
|
208
|
+
|
209
|
+
for ( q_iterator = (*dq).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
210
|
+
rb_str_concat(s,rb_funcall(*q_iterator,inspect,0));
|
211
|
+
if (q_iterator != (last_q_iterator - 1))
|
212
|
+
rb_str_concat(s,comma);
|
213
|
+
}
|
214
|
+
rb_str_concat(s,rb_str_new2("]"));
|
215
|
+
|
216
|
+
return rb_str_to_str(s);
|
217
|
+
}
|
218
|
+
|
219
|
+
static VALUE deque_first (VALUE self)
|
220
|
+
{
|
221
|
+
deque<VALUE>* dq = NULL;
|
222
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
223
|
+
if (!dq)
|
224
|
+
rb_raise (rb_eException, "No Deque Object");
|
225
|
+
|
226
|
+
return (*dq).front();
|
227
|
+
}
|
228
|
+
|
229
|
+
static VALUE deque_last (VALUE self)
|
230
|
+
{
|
231
|
+
deque<VALUE>* dq = NULL;
|
232
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
233
|
+
if (!dq)
|
234
|
+
rb_raise (rb_eException, "No Deque Object");
|
235
|
+
|
236
|
+
return (*dq).back();
|
237
|
+
}
|
238
|
+
|
239
|
+
static VALUE deque_replace (VALUE self, VALUE new_dq)
|
240
|
+
{
|
241
|
+
deque<VALUE>* dq = NULL;
|
242
|
+
deque<VALUE>* ndq = NULL;
|
243
|
+
deque<VALUE>::iterator q_iterator;
|
244
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
245
|
+
Data_Get_Struct(new_dq, deque<VALUE>, ndq);
|
246
|
+
if (!dq)
|
247
|
+
rb_raise (rb_eException, "No Deque Object");
|
248
|
+
|
249
|
+
if (!ndq)
|
250
|
+
rb_raise (rb_eException, "No Deque object to copy");
|
251
|
+
|
252
|
+
(*dq).clear();
|
253
|
+
for ( q_iterator = (*ndq).begin(); q_iterator != (*ndq).end(); q_iterator++ ) {
|
254
|
+
(*dq).push_back(*q_iterator);
|
255
|
+
}
|
256
|
+
|
257
|
+
return self;
|
258
|
+
}
|
259
|
+
|
260
|
+
static VALUE deque_at (VALUE self, VALUE pos)
|
261
|
+
{
|
262
|
+
deque<VALUE>* dq = NULL;
|
263
|
+
long c_pos = rb_num2long(pos);
|
264
|
+
|
265
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
266
|
+
|
267
|
+
if (!dq)
|
268
|
+
rb_raise (rb_eException, "No Deque Object");
|
269
|
+
|
270
|
+
if ((c_pos < 0) || (c_pos >= (*dq).size()))
|
271
|
+
rb_raise (rb_eException, "Out of bounds index on Deque object");
|
272
|
+
|
273
|
+
return *((*dq).begin() + c_pos);
|
274
|
+
}
|
275
|
+
|
276
|
+
static VALUE deque_delete (VALUE self, VALUE obj)
|
277
|
+
{
|
278
|
+
deque<VALUE>* dq = NULL;
|
279
|
+
deque<VALUE>::iterator q_iterator;
|
280
|
+
deque<VALUE>::iterator last_q_iterator;
|
281
|
+
|
282
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
283
|
+
|
284
|
+
if (!dq)
|
285
|
+
rb_raise (rb_eException, "No Deque Object");
|
286
|
+
|
287
|
+
last_q_iterator = (*dq).end();
|
288
|
+
for ( q_iterator = (*dq).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
289
|
+
if (rb_equal(*q_iterator, obj)) {
|
290
|
+
(*dq).erase(q_iterator);
|
291
|
+
break;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
return self;
|
296
|
+
}
|
297
|
+
|
298
|
+
static VALUE deque_delete_at (VALUE self, VALUE pos)
|
299
|
+
{
|
300
|
+
deque<VALUE>* dq = NULL;
|
301
|
+
deque<VALUE>::iterator q_iterator;
|
302
|
+
long c_pos = rb_num2long(pos);
|
303
|
+
|
304
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
305
|
+
|
306
|
+
if (!dq)
|
307
|
+
rb_raise (rb_eException, "No Deque Object");
|
308
|
+
|
309
|
+
if ((c_pos < 0) || (c_pos >= (*dq).size()))
|
310
|
+
rb_raise (rb_eException, "Out of bounds index on Deque object");
|
311
|
+
|
312
|
+
q_iterator = (*dq).begin();
|
313
|
+
for ( int n = 0; n < c_pos; n++) {
|
314
|
+
q_iterator++;
|
315
|
+
}
|
316
|
+
(*dq).erase(q_iterator);
|
317
|
+
|
318
|
+
return *q_iterator;
|
319
|
+
}
|
320
|
+
|
321
|
+
static VALUE deque_insert (VALUE self, VALUE pos, VALUE val)
|
322
|
+
{
|
323
|
+
deque<VALUE>* dq = NULL;
|
324
|
+
deque<VALUE>::iterator q_iterator;
|
325
|
+
long c_pos = rb_num2long(pos);
|
326
|
+
|
327
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
328
|
+
|
329
|
+
if (!dq)
|
330
|
+
rb_raise (rb_eException, "No Deque Object");
|
331
|
+
|
332
|
+
if ((c_pos < 0) || (c_pos > (*dq).size()))
|
333
|
+
rb_raise (rb_eException, "Out of bounds index on Deque object");
|
334
|
+
|
335
|
+
q_iterator = (*dq).begin() + c_pos;
|
336
|
+
(*dq).insert(q_iterator,val);
|
337
|
+
|
338
|
+
return self;
|
339
|
+
}
|
340
|
+
|
341
|
+
static VALUE deque_assign_at (VALUE self, VALUE pos, VALUE val)
|
342
|
+
{
|
343
|
+
deque_delete(self,pos);
|
344
|
+
deque_insert(self,pos,val);
|
345
|
+
|
346
|
+
return self;
|
347
|
+
}
|
348
|
+
|
349
|
+
static VALUE deque_each (VALUE self)
|
350
|
+
{
|
351
|
+
deque<VALUE>* dq = NULL;
|
352
|
+
deque<VALUE>::iterator q_iterator;
|
353
|
+
deque<VALUE>::iterator last_q_iterator;
|
354
|
+
|
355
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
356
|
+
|
357
|
+
if (!dq)
|
358
|
+
rb_raise (rb_eException, "No Deque Object");
|
359
|
+
|
360
|
+
last_q_iterator = (*dq).end();
|
361
|
+
for ( q_iterator = (*dq).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
362
|
+
rb_yield(*q_iterator);
|
363
|
+
}
|
364
|
+
|
365
|
+
return self;
|
366
|
+
}
|
367
|
+
|
368
|
+
static VALUE deque_index (VALUE self, VALUE match_obj)
|
369
|
+
{
|
370
|
+
deque<VALUE>* dq = NULL;
|
371
|
+
deque<VALUE>::iterator q_iterator;
|
372
|
+
deque<VALUE>::iterator last_q_iterator;
|
373
|
+
|
374
|
+
Data_Get_Struct(self, deque<VALUE>, dq);
|
375
|
+
if (!dq)
|
376
|
+
rb_raise (rb_eException, "No Deque Object");
|
377
|
+
|
378
|
+
last_q_iterator = (*dq).end();
|
379
|
+
int pos = 0;
|
380
|
+
for ( q_iterator = (*dq).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
381
|
+
if (rb_equal(*q_iterator,match_obj) == Qtrue) {
|
382
|
+
return INT2NUM(pos);
|
383
|
+
} else {
|
384
|
+
pos++;
|
385
|
+
}
|
386
|
+
}
|
387
|
+
return Qnil;
|
388
|
+
}
|
389
|
+
|
390
|
+
/**********************
|
391
|
+
Init_deque
|
392
|
+
**********************/
|
393
|
+
|
394
|
+
extern "C" void Init_deque()
|
395
|
+
{
|
396
|
+
/* DequeClassTop = rb_define_class("Deque", rb_cObject);
|
397
|
+
DequeClass = rb_define_class_under (DequeClassTop, "Deque", rb_cObject); */
|
398
|
+
DequeClass = rb_define_class ("Deque", rb_cObject);
|
399
|
+
|
400
|
+
rb_define_module_function (DequeClass, "new", (VALUE (*)(...))deque_new, 0);
|
401
|
+
rb_define_method (DequeClass, "unshift", (VALUE (*)(...))deque_push_front,1);
|
402
|
+
rb_define_method (DequeClass, "shift", (VALUE (*)(...))deque_pop_front,0);
|
403
|
+
rb_define_method (DequeClass, "push", (VALUE (*)(...))deque_push_back,1);
|
404
|
+
rb_define_method (DequeClass, "<<", (VALUE (*)(...))deque_push_back,1);
|
405
|
+
rb_define_method (DequeClass, "pop", (VALUE (*)(...))deque_pop_back,0);
|
406
|
+
rb_define_method (DequeClass, "size", (VALUE (*)(...))deque_size,0);
|
407
|
+
rb_define_method (DequeClass, "length", (VALUE (*)(...))deque_size,0);
|
408
|
+
rb_define_method (DequeClass, "max_size", (VALUE (*)(...))deque_max_size,0);
|
409
|
+
rb_define_method (DequeClass, "clear", (VALUE (*)(...))deque_clear,0);
|
410
|
+
rb_define_method (DequeClass, "empty?", (VALUE (*)(...))deque_empty,0);
|
411
|
+
rb_define_method (DequeClass, "to_s", (VALUE (*)(...))deque_to_s,0);
|
412
|
+
rb_define_method (DequeClass, "to_a", (VALUE (*)(...))deque_to_a,0);
|
413
|
+
rb_define_method (DequeClass, "first", (VALUE (*)(...))deque_first,0);
|
414
|
+
rb_define_method (DequeClass, "last", (VALUE (*)(...))deque_last,0);
|
415
|
+
rb_define_method (DequeClass, "replace", (VALUE (*)(...))deque_replace,1);
|
416
|
+
rb_define_method (DequeClass, "inspect", (VALUE (*)(...))deque_inspect,0);
|
417
|
+
rb_define_method (DequeClass, "at", (VALUE (*)(...))deque_at,1);
|
418
|
+
rb_define_method (DequeClass, "[]", (VALUE (*)(...))deque_at,1);
|
419
|
+
rb_define_method (DequeClass, "delete", (VALUE (*)(...))deque_delete,1);
|
420
|
+
rb_define_method (DequeClass, "delete_at", (VALUE (*)(...))deque_delete_at,1);
|
421
|
+
rb_define_method (DequeClass, "insert", (VALUE (*)(...))deque_insert,2);
|
422
|
+
rb_define_method (DequeClass, "[]=", (VALUE (*)(...))deque_assign_at,2);
|
423
|
+
rb_define_method (DequeClass, "each", (VALUE (*)(...))deque_each,0);
|
424
|
+
rb_define_method (DequeClass, "index", (VALUE (*)(...))deque_index,1);
|
425
|
+
|
426
|
+
rb_include_module (DequeClass, rb_mEnumerable);
|
427
|
+
rb_require("deque/version.rb");
|
428
|
+
}
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deque
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kirk Haines
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-05 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: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '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.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Deque is a queue type data structure that allows efficient insertion
|
70
|
+
and deletion from both ends of the queue. This implementation wrapps the standard
|
71
|
+
C++ structure of the same name.
|
72
|
+
email:
|
73
|
+
- wyhaines@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions:
|
76
|
+
- ext/deque/extconf.rb
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- deque.gemspec
|
88
|
+
- ext/deque/extconf.rb
|
89
|
+
- ext/deque/rubymain.cpp
|
90
|
+
- lib/deque/version.rb
|
91
|
+
homepage: http://github.com/wyhaines/deque
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: A Deque data structure for Ruby.
|
115
|
+
test_files: []
|