maprbcpp 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/maprbcpp/extconf.rb +3 -0
- data/ext/maprbcpp/rubymain.cpp +493 -0
- data/lib/maprbcpp/version.rb +3 -0
- data/maprbcpp.gemspec +27 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16ff4ebd10a8e0e6b68f8f8563331ac04b1e23af
|
4
|
+
data.tar.gz: 63d8abb83fb55d3d2391e962d258951463af7e69
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4bee0435efc61c974f729026e3c646f7cda3c785c060244256d04edbde6f03cf0449ef26f48242899984f165147b12f59448b4e0933f8e4c2e13d4b07fdfae0
|
7
|
+
data.tar.gz: 1d19d7622f862f5548b29e1e191f3e6a7522177769f00e1563370844e02c7c59badf558fbde472dc1d96f4d6c9dfc0e363652dc2741ddeee9deff9def62315d6
|
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/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,49 @@
|
|
1
|
+
# Maprbcpp
|
2
|
+
|
3
|
+
Maps are associative containers which store values, indexed by key, but which provide ordered access to the values, sorted by the key. This implementation wraps the standard implementation found in C++.
|
4
|
+
|
5
|
+
This implementation has been in my toolbox for a very long time, and the API is in definite need of some love to make it fully Hash compatible.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'map-rbcpp'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install map-rbcpp
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'maprbcpp'
|
27
|
+
|
28
|
+
m = Maprbcpp.new
|
29
|
+
m['z'] = 26
|
30
|
+
m['a'] = 1
|
31
|
+
|
32
|
+
pp m
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/map-rbcpp. 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.
|
44
|
+
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
49
|
+
|
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(:maprbcpp)
|
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 "map/rbcpp"
|
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
@@ -0,0 +1,493 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
#include <map>
|
3
|
+
#include <string>
|
4
|
+
#include "string.h"
|
5
|
+
using namespace std;
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
|
9
|
+
static VALUE MapClass;
|
10
|
+
|
11
|
+
struct classcomp {
|
12
|
+
bool operator() (const char *s1, const char *s2) const
|
13
|
+
{
|
14
|
+
if ( strcmp(s1,s2) < 0) {
|
15
|
+
return true;
|
16
|
+
} else {
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
typedef std::map<char *,VALUE,classcomp> rb_map;
|
23
|
+
typedef std::map<char *,VALUE,classcomp>::iterator rb_map_iterator;
|
24
|
+
|
25
|
+
static void sptm_mark (rb_map* st)
|
26
|
+
{
|
27
|
+
rb_map_iterator q_iterator;
|
28
|
+
if (st) {
|
29
|
+
for ( q_iterator = (*st).begin(); q_iterator != (*st).end(); q_iterator++ ) {
|
30
|
+
rb_gc_mark(q_iterator->second);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
static void sptm_free (rb_map* st)
|
36
|
+
{
|
37
|
+
if (st)
|
38
|
+
delete st;
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE sptm_new (VALUE self)
|
42
|
+
{
|
43
|
+
rb_map* st = new rb_map;
|
44
|
+
VALUE v = Data_Wrap_Struct (MapClass, sptm_mark, sptm_free, st);
|
45
|
+
return v;
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
static VALUE sptm_parent (VALUE self)
|
50
|
+
{
|
51
|
+
rb_map* st = NULL;
|
52
|
+
Data_Get_Struct(self, rb_map, st);
|
53
|
+
if (!st)
|
54
|
+
rb_raise (rb_eException, "No Map Object");
|
55
|
+
|
56
|
+
if ((*st).empty()) {
|
57
|
+
return Qnil;
|
58
|
+
} else {
|
59
|
+
rb_map_iterator parent = (*st).parent();
|
60
|
+
VALUE r = rb_ary_new();
|
61
|
+
|
62
|
+
rb_ary_push(r,rb_str_new2(parent->first));
|
63
|
+
rb_ary_push(r,parent->second);
|
64
|
+
return r;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
*/
|
68
|
+
|
69
|
+
static VALUE sptm_pop_front (VALUE self)
|
70
|
+
{
|
71
|
+
rb_map* st = NULL;
|
72
|
+
Data_Get_Struct(self, rb_map, st);
|
73
|
+
if (!st)
|
74
|
+
rb_raise (rb_eException, "No Map Object");
|
75
|
+
|
76
|
+
if ((*st).empty()) {
|
77
|
+
return Qnil;
|
78
|
+
} else {
|
79
|
+
rb_map_iterator front = (*st).begin();
|
80
|
+
VALUE r = rb_ary_new();
|
81
|
+
|
82
|
+
rb_ary_push(r,rb_str_new2(front->first));
|
83
|
+
rb_ary_push(r,front->second);
|
84
|
+
(*st).erase(front);
|
85
|
+
return r;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE sptm_pop_back (VALUE self)
|
90
|
+
{
|
91
|
+
rb_map* st = NULL;
|
92
|
+
Data_Get_Struct(self, rb_map, st);
|
93
|
+
if (!st)
|
94
|
+
rb_raise (rb_eException, "No Map Object");
|
95
|
+
|
96
|
+
if ((*st).empty()) {
|
97
|
+
return Qnil;
|
98
|
+
} else {
|
99
|
+
rb_map_iterator back = (*st).end();
|
100
|
+
back--;
|
101
|
+
VALUE r = rb_ary_new();
|
102
|
+
rb_ary_push(r,rb_str_new2(back->first));
|
103
|
+
rb_ary_push(r,back->second);
|
104
|
+
(*st).erase(back);
|
105
|
+
return r;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
static VALUE sptm_size (VALUE self)
|
111
|
+
{
|
112
|
+
rb_map* st = NULL;
|
113
|
+
Data_Get_Struct(self, rb_map, st);
|
114
|
+
if (!st)
|
115
|
+
rb_raise (rb_eException, "No Map Object");
|
116
|
+
|
117
|
+
return INT2NUM((*st).size());
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
static VALUE sptm_max_size (VALUE self)
|
122
|
+
{
|
123
|
+
rb_map* st = NULL;
|
124
|
+
Data_Get_Struct(self, rb_map, st);
|
125
|
+
if (!st)
|
126
|
+
rb_raise (rb_eException, "No Map Object");
|
127
|
+
|
128
|
+
return INT2NUM((*st).max_size());
|
129
|
+
}
|
130
|
+
|
131
|
+
static VALUE sptm_clear (VALUE self)
|
132
|
+
{
|
133
|
+
rb_map* st = NULL;
|
134
|
+
Data_Get_Struct(self, rb_map, st);
|
135
|
+
if (!st)
|
136
|
+
rb_raise (rb_eException, "No Map Object");
|
137
|
+
|
138
|
+
(*st).clear();
|
139
|
+
return self;
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE sptm_empty (VALUE self)
|
143
|
+
{
|
144
|
+
rb_map* st = NULL;
|
145
|
+
Data_Get_Struct(self, rb_map, st);
|
146
|
+
if (!st)
|
147
|
+
rb_raise (rb_eException, "No Map Object");
|
148
|
+
|
149
|
+
if ((*st).empty()) {
|
150
|
+
return Qtrue;
|
151
|
+
} else {
|
152
|
+
return Qfalse;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
static VALUE sptm_to_s (VALUE self)
|
157
|
+
{
|
158
|
+
VALUE s = rb_str_new2("");
|
159
|
+
|
160
|
+
rb_map* st = NULL;
|
161
|
+
rb_map_iterator q_iterator;
|
162
|
+
Data_Get_Struct(self, rb_map, st);
|
163
|
+
if (!st)
|
164
|
+
rb_raise (rb_eException, "No Map Object");
|
165
|
+
|
166
|
+
for ( q_iterator = (*st).begin(); q_iterator != (*st).end(); q_iterator++ ) {
|
167
|
+
rb_str_concat(s,rb_str_new2(q_iterator->first));
|
168
|
+
rb_str_concat(s,rb_convert_type(q_iterator->second, T_STRING, "String", "to_str"));
|
169
|
+
}
|
170
|
+
|
171
|
+
return rb_str_to_str(s);
|
172
|
+
}
|
173
|
+
|
174
|
+
static VALUE sptm_to_a (VALUE self)
|
175
|
+
{
|
176
|
+
VALUE ary = rb_ary_new();
|
177
|
+
|
178
|
+
rb_map* st = NULL;
|
179
|
+
rb_map_iterator q_iterator;
|
180
|
+
Data_Get_Struct(self, rb_map, st);
|
181
|
+
if (!st)
|
182
|
+
rb_raise (rb_eException, "No Map Object");
|
183
|
+
|
184
|
+
for ( q_iterator = (*st).begin(); q_iterator != (*st).end(); q_iterator++ ) {
|
185
|
+
rb_ary_push(ary,rb_str_new2(q_iterator->first));
|
186
|
+
rb_ary_push(ary,q_iterator->second);
|
187
|
+
}
|
188
|
+
|
189
|
+
return ary;
|
190
|
+
}
|
191
|
+
|
192
|
+
static VALUE sptm_inspect (VALUE self)
|
193
|
+
{
|
194
|
+
VALUE s = rb_str_new2("{");
|
195
|
+
VALUE arrow = rb_str_new2("=>");
|
196
|
+
VALUE comma = rb_str_new2(",");
|
197
|
+
|
198
|
+
rb_map* st = NULL;
|
199
|
+
rb_map_iterator q_iterator;
|
200
|
+
rb_map_iterator last_q_iterator;
|
201
|
+
rb_map_iterator before_last_q_iterator;
|
202
|
+
Data_Get_Struct(self, rb_map, st);
|
203
|
+
if (!st)
|
204
|
+
rb_raise (rb_eException, "No Map Object");
|
205
|
+
|
206
|
+
if (!((*st).end() == (*st).begin())) {
|
207
|
+
before_last_q_iterator = last_q_iterator = (*st).end();
|
208
|
+
before_last_q_iterator--;
|
209
|
+
|
210
|
+
for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
211
|
+
rb_str_concat(s,rb_inspect(rb_str_new2((*q_iterator).first)));
|
212
|
+
rb_str_concat(s,arrow);
|
213
|
+
rb_str_concat(s,rb_inspect((*q_iterator).second));
|
214
|
+
if (q_iterator != before_last_q_iterator)
|
215
|
+
rb_str_concat(s,comma);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
rb_str_concat(s,rb_str_new2("}"));
|
220
|
+
|
221
|
+
return rb_str_to_str(s);
|
222
|
+
}
|
223
|
+
|
224
|
+
static VALUE sptm_first (VALUE self)
|
225
|
+
{
|
226
|
+
rb_map* st = NULL;
|
227
|
+
Data_Get_Struct(self, rb_map, st);
|
228
|
+
if (!st)
|
229
|
+
rb_raise (rb_eException, "No Map Object");
|
230
|
+
|
231
|
+
if ((*st).empty()) {
|
232
|
+
return Qnil;
|
233
|
+
} else {
|
234
|
+
rb_map_iterator front = (*st).begin();
|
235
|
+
VALUE r = rb_ary_new();
|
236
|
+
rb_ary_push(r,rb_str_new2(front->first));
|
237
|
+
rb_ary_push(r,front->second);
|
238
|
+
return r;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
static VALUE sptm_last (VALUE self)
|
243
|
+
{
|
244
|
+
rb_map* st = NULL;
|
245
|
+
Data_Get_Struct(self, rb_map, st);
|
246
|
+
if (!st)
|
247
|
+
rb_raise (rb_eException, "No Map Object");
|
248
|
+
|
249
|
+
if ((*st).empty()) {
|
250
|
+
return Qnil;
|
251
|
+
} else {
|
252
|
+
rb_map_iterator back = (*st).end();
|
253
|
+
back--;
|
254
|
+
VALUE r = rb_ary_new();
|
255
|
+
rb_ary_push(r,rb_str_new2(back->first));
|
256
|
+
rb_ary_push(r,back->second);
|
257
|
+
return r;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
/*
|
262
|
+
static VALUE sptm_replace (VALUE self, VALUE new_st)
|
263
|
+
{
|
264
|
+
rb_map* st = NULL;
|
265
|
+
rb_map* nst = NULL;
|
266
|
+
rb_map_iterator q_iterator;
|
267
|
+
Data_Get_Struct(self, rb_map, st);
|
268
|
+
Data_Get_Struct(new_st, rb_map, nst);
|
269
|
+
if (!st)
|
270
|
+
rb_raise (rb_eException, "No Map Object");
|
271
|
+
|
272
|
+
if (!nst)
|
273
|
+
rb_raise (rb_eException, "No Map object to copy");
|
274
|
+
|
275
|
+
(*st).clear();
|
276
|
+
for ( q_iterator = (*nst).begin(); q_iterator != (*nst).end(); q_iterator++ ) {
|
277
|
+
(*st).push_back(*q_iterator);
|
278
|
+
}
|
279
|
+
|
280
|
+
return self;
|
281
|
+
}
|
282
|
+
*/
|
283
|
+
|
284
|
+
|
285
|
+
static VALUE sptm_insert (VALUE self, VALUE key, VALUE val)
|
286
|
+
{
|
287
|
+
rb_map* st = NULL;
|
288
|
+
std::pair<rb_map_iterator, bool> rv;
|
289
|
+
std::pair<char *,VALUE> sp;
|
290
|
+
char * skey;
|
291
|
+
char * svp;
|
292
|
+
|
293
|
+
svp = StringValuePtr(key);
|
294
|
+
skey = new char[strlen(svp)+1];
|
295
|
+
strcpy(skey,svp);
|
296
|
+
|
297
|
+
Data_Get_Struct(self, rb_map, st);
|
298
|
+
|
299
|
+
if (!st)
|
300
|
+
rb_raise (rb_eException, "No Map Object");
|
301
|
+
|
302
|
+
sp = make_pair(skey,val);
|
303
|
+
rv = (*st).insert(sp);
|
304
|
+
if (!rv.second) {
|
305
|
+
(*st).erase(rv.first);
|
306
|
+
(*st).insert(sp);
|
307
|
+
}
|
308
|
+
|
309
|
+
return self;
|
310
|
+
}
|
311
|
+
|
312
|
+
static VALUE sptm_at (VALUE self, VALUE key)
|
313
|
+
{
|
314
|
+
rb_map* st = NULL;
|
315
|
+
rb_map_iterator q_iterator;
|
316
|
+
|
317
|
+
char * skey = StringValuePtr(key);
|
318
|
+
|
319
|
+
Data_Get_Struct(self, rb_map, st);
|
320
|
+
|
321
|
+
if (!st)
|
322
|
+
rb_raise (rb_eException, "No Map Object");
|
323
|
+
|
324
|
+
q_iterator = (*st).find(skey);
|
325
|
+
if (q_iterator == (*st).end()) {
|
326
|
+
return Qnil;
|
327
|
+
} else {
|
328
|
+
return q_iterator->second;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
|
333
|
+
static VALUE sptm_delete (VALUE self, VALUE key)
|
334
|
+
{
|
335
|
+
rb_map* st = NULL;
|
336
|
+
rb_map_iterator q_iterator;
|
337
|
+
|
338
|
+
char * skey = StringValuePtr(key);
|
339
|
+
|
340
|
+
Data_Get_Struct(self, rb_map, st);
|
341
|
+
|
342
|
+
if (!st)
|
343
|
+
rb_raise (rb_eException, "No Map Object");
|
344
|
+
|
345
|
+
q_iterator = (*st).find(skey);
|
346
|
+
if (q_iterator == (*st).end()) {
|
347
|
+
return Qnil;
|
348
|
+
} else {
|
349
|
+
(*st).erase(q_iterator);
|
350
|
+
}
|
351
|
+
|
352
|
+
return self;
|
353
|
+
}
|
354
|
+
|
355
|
+
/*
|
356
|
+
static VALUE sptm_delete_value (VALUE self, VALUE obj)
|
357
|
+
{
|
358
|
+
rb_map* st = NULL;
|
359
|
+
rb_map_iterator q_iterator;
|
360
|
+
rb_map_iterator last_q_iterator;
|
361
|
+
|
362
|
+
Data_Get_Struct(self, rb_map, st);
|
363
|
+
|
364
|
+
if (!st)
|
365
|
+
rb_raise (rb_eException, "No Map Object");
|
366
|
+
|
367
|
+
last_q_iterator = (*st).end();
|
368
|
+
for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
369
|
+
if (rb_equal(q_iterator->second, obj)) {
|
370
|
+
(*st).erase(q_iterator);
|
371
|
+
break;
|
372
|
+
}
|
373
|
+
}
|
374
|
+
|
375
|
+
return self;
|
376
|
+
}
|
377
|
+
*/
|
378
|
+
|
379
|
+
static VALUE sptm_each (VALUE self)
|
380
|
+
{
|
381
|
+
rb_map* st = NULL;
|
382
|
+
rb_map_iterator q_iterator;
|
383
|
+
rb_map_iterator last_q_iterator;
|
384
|
+
|
385
|
+
Data_Get_Struct(self, rb_map, st);
|
386
|
+
|
387
|
+
if (!st)
|
388
|
+
rb_raise (rb_eException, "No Map Object");
|
389
|
+
|
390
|
+
last_q_iterator = (*st).end();
|
391
|
+
for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
392
|
+
rb_yield_values(2,rb_str_new2(q_iterator->first),q_iterator->second);
|
393
|
+
}
|
394
|
+
|
395
|
+
return self;
|
396
|
+
}
|
397
|
+
|
398
|
+
static VALUE sptm_index (VALUE self, VALUE match_obj)
|
399
|
+
{
|
400
|
+
rb_map* st = NULL;
|
401
|
+
rb_map_iterator q_iterator;
|
402
|
+
rb_map_iterator last_q_iterator;
|
403
|
+
|
404
|
+
Data_Get_Struct(self, rb_map, st);
|
405
|
+
|
406
|
+
if (!st)
|
407
|
+
rb_raise (rb_eException, "No Map Object");
|
408
|
+
|
409
|
+
last_q_iterator = (*st).end();
|
410
|
+
for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
411
|
+
if (rb_equal(q_iterator->second, match_obj)) {
|
412
|
+
return rb_str_new2(q_iterator->first);
|
413
|
+
}
|
414
|
+
}
|
415
|
+
return Qnil;
|
416
|
+
}
|
417
|
+
|
418
|
+
static VALUE sptm_keys (VALUE self)
|
419
|
+
{
|
420
|
+
rb_map* st = NULL;
|
421
|
+
rb_map_iterator q_iterator;
|
422
|
+
rb_map_iterator last_q_iterator;
|
423
|
+
|
424
|
+
Data_Get_Struct(self, rb_map, st);
|
425
|
+
|
426
|
+
if (!st)
|
427
|
+
rb_raise (rb_eException, "No Map Object");
|
428
|
+
|
429
|
+
last_q_iterator = (*st).end();
|
430
|
+
VALUE r = rb_ary_new();
|
431
|
+
for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
432
|
+
rb_ary_push(r,rb_str_new2(q_iterator->first));
|
433
|
+
}
|
434
|
+
|
435
|
+
return r;
|
436
|
+
}
|
437
|
+
|
438
|
+
static VALUE sptm_values (VALUE self)
|
439
|
+
{
|
440
|
+
rb_map* st = NULL;
|
441
|
+
rb_map_iterator q_iterator;
|
442
|
+
rb_map_iterator last_q_iterator;
|
443
|
+
|
444
|
+
Data_Get_Struct(self, rb_map, st);
|
445
|
+
|
446
|
+
if (!st)
|
447
|
+
rb_raise (rb_eException, "No Map Object");
|
448
|
+
|
449
|
+
last_q_iterator = (*st).end();
|
450
|
+
VALUE r = rb_ary_new();
|
451
|
+
for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
|
452
|
+
rb_ary_push(r,q_iterator->second);
|
453
|
+
}
|
454
|
+
|
455
|
+
return r;
|
456
|
+
}
|
457
|
+
|
458
|
+
/**********************
|
459
|
+
Init_sptm
|
460
|
+
**********************/
|
461
|
+
|
462
|
+
extern "C" void Init_maprbcpp()
|
463
|
+
{
|
464
|
+
MapClass = rb_define_class("Maprbcpp", rb_cObject);
|
465
|
+
|
466
|
+
rb_define_module_function (MapClass, "new", (VALUE (*)(...))sptm_new, 0);
|
467
|
+
rb_define_method (MapClass, "shift", (VALUE (*)(...))sptm_pop_front,0);
|
468
|
+
rb_define_method (MapClass, "pop", (VALUE (*)(...))sptm_pop_back,0);
|
469
|
+
rb_define_method (MapClass, "size", (VALUE (*)(...))sptm_size,0);
|
470
|
+
rb_define_method (MapClass, "length", (VALUE (*)(...))sptm_size,0);
|
471
|
+
rb_define_method (MapClass, "max_size", (VALUE (*)(...))sptm_max_size,0);
|
472
|
+
rb_define_method (MapClass, "clear", (VALUE (*)(...))sptm_clear,0);
|
473
|
+
rb_define_method (MapClass, "empty?", (VALUE (*)(...))sptm_empty,0);
|
474
|
+
rb_define_method (MapClass, "to_s", (VALUE (*)(...))sptm_to_s,0);
|
475
|
+
rb_define_method (MapClass, "to_a", (VALUE (*)(...))sptm_to_a,0);
|
476
|
+
rb_define_method (MapClass, "first", (VALUE (*)(...))sptm_first,0);
|
477
|
+
rb_define_method (MapClass, "last", (VALUE (*)(...))sptm_last,0);
|
478
|
+
//rb_define_method (MapClass, "parent", (VALUE(*)(...))sptm_parent,0);
|
479
|
+
//rb_define_method (MapClass, "replace", (VALUE(*)(...))sptm_replace,1);
|
480
|
+
rb_define_method (MapClass, "inspect", (VALUE (*)(...))sptm_inspect,0);
|
481
|
+
rb_define_method (MapClass, "at", (VALUE (*)(...))sptm_at,1);
|
482
|
+
rb_define_method (MapClass, "[]", (VALUE (*)(...))sptm_at,1);
|
483
|
+
rb_define_method (MapClass, "delete", (VALUE (*)(...))sptm_delete,1);
|
484
|
+
rb_define_method (MapClass, "insert", (VALUE (*)(...))sptm_insert,2);
|
485
|
+
rb_define_method (MapClass, "[]=", (VALUE (*)(...))sptm_insert,2);
|
486
|
+
rb_define_method (MapClass, "each", (VALUE (*)(...))sptm_each,0);
|
487
|
+
rb_define_method (MapClass, "index", (VALUE (*)(...))sptm_index,1);
|
488
|
+
rb_define_method (MapClass, "keys", (VALUE (*)(...))sptm_keys,0);
|
489
|
+
rb_define_method (MapClass, "values", (VALUE (*)(...))sptm_values,0);
|
490
|
+
|
491
|
+
rb_require("maprbcpp/version.rb");
|
492
|
+
// rb_include_module (MapClass, rb_mEnumerable);
|
493
|
+
}
|
data/maprbcpp.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'maprbcpp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "maprbcpp"
|
8
|
+
spec.version = MapRbcpp::VERSION
|
9
|
+
spec.authors = ["Kirk Haines"]
|
10
|
+
spec.email = ["wyhaines@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An implementation of a Map (ordered key/value storage container) that wraps the standard C++ container class.}
|
13
|
+
spec.description = %q{Maps are associative containers which store values, indexed by key, but which provide ordered access to the values, sorted by the key. This implementation wraps the standard implementation found in C++.}
|
14
|
+
spec.homepage = "http://github.com/wyhaines/map-rbcpp"
|
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/maprbcpp/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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maprbcpp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kirk Haines
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-06 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: Maps are associative containers which store values, indexed by key, but
|
70
|
+
which provide ordered access to the values, sorted by the key. This implementation
|
71
|
+
wraps the standard implementation found in C++.
|
72
|
+
email:
|
73
|
+
- wyhaines@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions:
|
76
|
+
- ext/maprbcpp/extconf.rb
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- ext/maprbcpp/extconf.rb
|
87
|
+
- ext/maprbcpp/rubymain.cpp
|
88
|
+
- lib/maprbcpp/version.rb
|
89
|
+
- maprbcpp.gemspec
|
90
|
+
homepage: http://github.com/wyhaines/map-rbcpp
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: An implementation of a Map (ordered key/value storage container) that wraps
|
114
|
+
the standard C++ container class.
|
115
|
+
test_files: []
|