swiftiply 0.6.1.1 → 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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTORS +2 -0
  3. data/README.md +62 -0
  4. data/bin/{mongrel_rails → evented_mongrel_rails} +6 -14
  5. data/bin/swiftiplied_mongrel_rails +246 -0
  6. data/bin/swiftiply +136 -116
  7. data/bin/swiftiply_mongrel_rails +2 -2
  8. data/bin/swiftiplyctl +283 -0
  9. data/cleanup.sh +5 -0
  10. data/ext/deque/extconf.rb +162 -0
  11. data/ext/deque/swiftcore/rubymain.cpp +435 -0
  12. data/ext/fastfilereader/extconf.rb +2 -2
  13. data/ext/fastfilereader/mapper.cpp +2 -0
  14. data/ext/map/extconf.rb +161 -0
  15. data/ext/map/rubymain.cpp +500 -0
  16. data/ext/splaytree/extconf.rb +161 -0
  17. data/ext/splaytree/swiftcore/rubymain.cpp +580 -0
  18. data/ext/splaytree/swiftcore/splay_map.h +635 -0
  19. data/ext/splaytree/swiftcore/splay_set.h +575 -0
  20. data/ext/splaytree/swiftcore/splay_tree.h +1127 -0
  21. data/external/httpclient.rb +231 -0
  22. data/external/package.rb +13 -13
  23. data/setup.rb +18 -2
  24. data/src/swiftcore/Swiftiply.rb +417 -773
  25. data/src/swiftcore/Swiftiply/backend_protocol.rb +213 -0
  26. data/src/swiftcore/Swiftiply/cache_base.rb +49 -0
  27. data/src/swiftcore/Swiftiply/cache_base_mixin.rb +52 -0
  28. data/src/swiftcore/Swiftiply/cluster_managers/rest_based_cluster_manager.rb +9 -0
  29. data/src/swiftcore/Swiftiply/cluster_protocol.rb +70 -0
  30. data/src/swiftcore/Swiftiply/config.rb +370 -0
  31. data/src/swiftcore/Swiftiply/config/rest_updater.rb +26 -0
  32. data/src/swiftcore/Swiftiply/constants.rb +101 -0
  33. data/src/swiftcore/Swiftiply/content_cache_entry.rb +44 -0
  34. data/src/swiftcore/Swiftiply/content_response.rb +45 -0
  35. data/src/swiftcore/Swiftiply/control_protocol.rb +49 -0
  36. data/src/swiftcore/Swiftiply/dynamic_request_cache.rb +41 -0
  37. data/src/swiftcore/Swiftiply/etag_cache.rb +64 -0
  38. data/src/swiftcore/Swiftiply/file_cache.rb +46 -0
  39. data/src/swiftcore/Swiftiply/hash_cache_base.rb +22 -0
  40. data/src/swiftcore/Swiftiply/http_recognizer.rb +267 -0
  41. data/src/swiftcore/Swiftiply/loggers/Analogger.rb +21 -0
  42. data/src/swiftcore/Swiftiply/loggers/stderror.rb +13 -0
  43. data/src/swiftcore/Swiftiply/mocklog.rb +10 -0
  44. data/src/swiftcore/Swiftiply/proxy.rb +15 -0
  45. data/src/swiftcore/Swiftiply/proxy_backends/keepalive.rb +286 -0
  46. data/src/swiftcore/Swiftiply/proxy_backends/traditional.rb +286 -0
  47. data/src/swiftcore/Swiftiply/proxy_backends/traditional/redis_directory.rb +87 -0
  48. data/src/swiftcore/Swiftiply/proxy_backends/traditional/static_directory.rb +69 -0
  49. data/src/swiftcore/Swiftiply/proxy_bag.rb +716 -0
  50. data/src/swiftcore/Swiftiply/rest_based_cluster_manager.rb +15 -0
  51. data/src/swiftcore/Swiftiply/splay_cache_base.rb +21 -0
  52. data/src/swiftcore/Swiftiply/support_pagecache.rb +6 -3
  53. data/src/swiftcore/Swiftiply/swiftiply_2_http_proxy.rb +7 -0
  54. data/src/swiftcore/Swiftiply/swiftiply_client.rb +20 -5
  55. data/src/swiftcore/Swiftiply/version.rb +5 -0
  56. data/src/swiftcore/evented_mongrel.rb +26 -8
  57. data/src/swiftcore/hash.rb +43 -0
  58. data/src/swiftcore/method_builder.rb +28 -0
  59. data/src/swiftcore/streamer.rb +46 -0
  60. data/src/swiftcore/swiftiplied_mongrel.rb +91 -23
  61. data/src/swiftcore/types.rb +20 -3
  62. data/swiftiply.gemspec +14 -8
  63. data/test/TC_Deque.rb +152 -0
  64. data/test/TC_ProxyBag.rb +147 -166
  65. data/test/TC_Swiftiply.rb +576 -169
  66. data/test/TC_Swiftiply/mongrel/evented_hello.rb +1 -1
  67. data/test/TC_Swiftiply/mongrel/swiftiplied_hello.rb +1 -1
  68. data/test/TC_Swiftiply/test_serve_static_file_xsendfile/sendfile_client.rb +27 -0
  69. data/test/TC_Swiftiply/test_ssl/bin/validate_ssl_capability.rb +21 -0
  70. data/test/TC_Swiftiply/test_ssl/test.cert +16 -0
  71. data/test/TC_Swiftiply/test_ssl/test.key +15 -0
  72. data/{bin → test/bin}/echo_client +0 -0
  73. metadata +136 -94
  74. data/README +0 -126
  75. data/ext/swiftiply_parse/parse.rl +0 -90
@@ -0,0 +1,161 @@
1
+ # $Id: extconf.rb 4526 2007-07-03 18:04:34Z francis $
2
+ #
3
+ #----------------------------------------------------------------------------
4
+ #
5
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
6
+ # Gmail: garbagecat10
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify
9
+ # it under the terms of either: 1) the GNU General Public License
10
+ # as published by the Free Software Foundation; either version 2 of the
11
+ # License, or (at your option) any later version; or 2) Ruby's License.
12
+ #
13
+ # See the file COPYING for complete licensing information.
14
+ #
15
+ #---------------------------------------------------------------------------
16
+ #
17
+ # extconf.rb for Fast File Reader
18
+ # We have to munge LDSHARED because this code needs a C++ link.
19
+ #
20
+
21
+ require 'mkmf'
22
+
23
+ flags = []
24
+
25
+ case RUBY_PLATFORM.split('-',2)[1]
26
+ when 'mswin32', 'mingw32', 'bccwin32'
27
+ unless have_header('windows.h') and
28
+ have_header('winsock.h') and
29
+ have_library('kernel32') and
30
+ have_library('rpcrt4') and
31
+ have_library('gdi32')
32
+ exit
33
+ end
34
+
35
+ flags << "-D OS_WIN32"
36
+ flags << '-D BUILD_FOR_RUBY'
37
+ flags << "-EHs"
38
+ flags << "-GR"
39
+
40
+ # dir_config('ssl')
41
+ # if have_library('ssleay32') and
42
+ # have_library('libeay32') and
43
+ # have_header('openssl/ssl.h') and
44
+ # have_header('openssl/err.h')
45
+ # flags << '-D WITH_SSL'
46
+ # else
47
+ # flags << '-D WITHOUT_SSL'
48
+ # end
49
+
50
+ when /solaris/
51
+ # unless have_library('pthread') and
52
+ # have_library('nsl') and
53
+ # have_library('socket')
54
+ # exit
55
+ # end
56
+
57
+ flags << '-D OS_UNIX'
58
+ flags << '-D OS_SOLARIS8'
59
+ flags << '-D BUILD_FOR_RUBY'
60
+
61
+ # dir_config('ssl')
62
+ # if have_library('ssl') and
63
+ # have_library('crypto') and
64
+ # have_header('openssl/ssl.h') and
65
+ # have_header('openssl/err.h')
66
+ # flags << '-D WITH_SSL'
67
+ # else
68
+ # flags << '-D WITHOUT_SSL'
69
+ # end
70
+
71
+ # on Unix we need a g++ link, not gcc.
72
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
73
+
74
+ when /darwin/
75
+ flags << '-DOS_UNIX'
76
+ flags << '-DBUILD_FOR_RUBY'
77
+
78
+ # dir_config('ssl')
79
+ # if have_library('ssl') and
80
+ # have_library('crypto') and
81
+ # have_library('C') and
82
+ # have_header('openssl/ssl.h') and
83
+ # have_header('openssl/err.h')
84
+ # flags << '-DWITH_SSL'
85
+ # else
86
+ # flags << '-DWITHOUT_SSL'
87
+ # end
88
+ # on Unix we need a g++ link, not gcc.
89
+ # Ff line contributed by Daniel Harple.
90
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
91
+
92
+ when /linux/
93
+ unless have_library('pthread')
94
+ exit
95
+ end
96
+
97
+ flags << '-DOS_UNIX'
98
+ flags << '-DBUILD_FOR_RUBY'
99
+
100
+ # Original epoll test is inadequate because 2.4 kernels have the header
101
+ # but not the code.
102
+ # #flags << '-DHAVE_EPOLL' if have_header('sys/epoll.h')
103
+ # if have_header('sys/epoll.h')
104
+ # File.open("hasEpollTest.c", "w") {|f|
105
+ # f.puts "#include <sys/epoll.h>"
106
+ # f.puts "int main() { epoll_create(1024); return 0;}"
107
+ # }
108
+ # (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
109
+ # `rm -f hasEpollTest.c hasEpollTest`
110
+ # flags << '-DHAVE_EPOLL' if e == 0
111
+ # end
112
+ #
113
+ # dir_config('ssl')
114
+ # if have_library('ssl') and
115
+ # have_library('crypto') and
116
+ # have_header('openssl/ssl.h') and
117
+ # have_header('openssl/err.h')
118
+ # flags << '-DWITH_SSL'
119
+ # else
120
+ # flags << '-DWITHOUT_SSL'
121
+ # end
122
+ # on Unix we need a g++ link, not gcc.
123
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
124
+
125
+ # Modify the mkmf constant LINK_SO so the generated shared object is stripped.
126
+ # You might think modifying CONFIG['LINK_SO'] would be a better way to do this,
127
+ # but it doesn't work because mkmf doesn't look at CONFIG['LINK_SO'] again after
128
+ # it initializes.
129
+ #linkso = Object.send :remove_const, "LINK_SO"
130
+ #LINK_SO = linkso + "; strip $@"
131
+
132
+ else
133
+ # unless have_library('pthread')
134
+ # exit
135
+ # end
136
+
137
+ flags << '-DOS_UNIX'
138
+ flags << '-DBUILD_FOR_RUBY'
139
+
140
+ # dir_config('ssl')
141
+ # if have_library('ssl') and
142
+ # have_library('crypto') and
143
+ # have_header('openssl/ssl.h') and
144
+ # have_header('openssl/err.h')
145
+ # flags << '-DWITH_SSL'
146
+ # else
147
+ # flags << '-DWITHOUT_SSL'
148
+ # end
149
+ # on Unix we need a g++ link, not gcc.
150
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
151
+
152
+ end
153
+
154
+ if $CPPFLAGS
155
+ $CPPFLAGS += ' ' + flags.join(' ')
156
+ else
157
+ $CFLAGS += ' ' + flags.join(' ')
158
+ end
159
+
160
+
161
+ create_makefile "map"
@@ -0,0 +1,500 @@
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 SwiftcoreModule;
10
+ static VALUE MapClass;
11
+
12
+ struct classcomp {
13
+ bool operator() (const char *s1, const char *s2) const
14
+ {
15
+ if ( strcmp(s1,s2) < 0) {
16
+ return true;
17
+ } else {
18
+ return false;
19
+ }
20
+ }
21
+ };
22
+
23
+ typedef std::map<char *,VALUE,classcomp> rb_map;
24
+ typedef std::map<char *,VALUE,classcomp>::iterator rb_map_iterator;
25
+
26
+ static void sptm_mark (rb_map* st)
27
+ {
28
+ rb_map_iterator q_iterator;
29
+ if (st) {
30
+ for ( q_iterator = (*st).begin(); q_iterator != (*st).end(); q_iterator++ ) {
31
+ rb_gc_mark(q_iterator->second);
32
+ }
33
+ }
34
+ }
35
+
36
+ static void sptm_free (rb_map* st)
37
+ {
38
+ if (st)
39
+ delete st;
40
+ }
41
+
42
+ static VALUE sptm_new (VALUE self)
43
+ {
44
+ rb_map* st = new rb_map;
45
+ VALUE v = Data_Wrap_Struct (MapClass, sptm_mark, sptm_free, st);
46
+ return v;
47
+ }
48
+
49
+ /*
50
+ static VALUE sptm_parent (VALUE self)
51
+ {
52
+ rb_map* st = NULL;
53
+ Data_Get_Struct(self, rb_map, st);
54
+ if (!st)
55
+ rb_raise (rb_eException, "No Map Object");
56
+
57
+ if ((*st).empty()) {
58
+ return Qnil;
59
+ } else {
60
+ rb_map_iterator parent = (*st).parent();
61
+ VALUE r = rb_ary_new();
62
+
63
+ rb_ary_push(r,rb_str_new2(parent->first));
64
+ rb_ary_push(r,parent->second);
65
+ return r;
66
+ }
67
+ }
68
+ */
69
+
70
+ static VALUE sptm_pop_front (VALUE self)
71
+ {
72
+ rb_map* st = NULL;
73
+ Data_Get_Struct(self, rb_map, st);
74
+ if (!st)
75
+ rb_raise (rb_eException, "No Map Object");
76
+
77
+ if ((*st).empty()) {
78
+ return Qnil;
79
+ } else {
80
+ rb_map_iterator front = (*st).begin();
81
+ VALUE r = rb_ary_new();
82
+
83
+ rb_ary_push(r,rb_str_new2(front->first));
84
+ rb_ary_push(r,front->second);
85
+ (*st).erase(front);
86
+ return r;
87
+ }
88
+ }
89
+
90
+ static VALUE sptm_pop_back (VALUE self)
91
+ {
92
+ rb_map* st = NULL;
93
+ Data_Get_Struct(self, rb_map, st);
94
+ if (!st)
95
+ rb_raise (rb_eException, "No Map Object");
96
+
97
+ if ((*st).empty()) {
98
+ return Qnil;
99
+ } else {
100
+ rb_map_iterator back = (*st).end();
101
+ back--;
102
+ VALUE r = rb_ary_new();
103
+ rb_ary_push(r,rb_str_new2(back->first));
104
+ rb_ary_push(r,back->second);
105
+ (*st).erase(back);
106
+ return r;
107
+ }
108
+ }
109
+
110
+
111
+ static VALUE sptm_size (VALUE self)
112
+ {
113
+ rb_map* st = NULL;
114
+ Data_Get_Struct(self, rb_map, st);
115
+ if (!st)
116
+ rb_raise (rb_eException, "No Map Object");
117
+
118
+ return INT2NUM((*st).size());
119
+ }
120
+
121
+
122
+ static VALUE sptm_max_size (VALUE self)
123
+ {
124
+ rb_map* st = NULL;
125
+ Data_Get_Struct(self, rb_map, st);
126
+ if (!st)
127
+ rb_raise (rb_eException, "No Map Object");
128
+
129
+ return INT2NUM((*st).max_size());
130
+ }
131
+
132
+ static VALUE sptm_clear (VALUE self)
133
+ {
134
+ rb_map* st = NULL;
135
+ Data_Get_Struct(self, rb_map, st);
136
+ if (!st)
137
+ rb_raise (rb_eException, "No Map Object");
138
+
139
+ (*st).clear();
140
+ return self;
141
+ }
142
+
143
+ static VALUE sptm_empty (VALUE self)
144
+ {
145
+ rb_map* st = NULL;
146
+ Data_Get_Struct(self, rb_map, st);
147
+ if (!st)
148
+ rb_raise (rb_eException, "No Map Object");
149
+
150
+ if ((*st).empty()) {
151
+ return Qtrue;
152
+ } else {
153
+ return Qfalse;
154
+ }
155
+ }
156
+
157
+ static VALUE sptm_to_s (VALUE self)
158
+ {
159
+ VALUE s = rb_str_new2("");
160
+
161
+ rb_map* st = NULL;
162
+ rb_map_iterator q_iterator;
163
+ Data_Get_Struct(self, rb_map, st);
164
+ if (!st)
165
+ rb_raise (rb_eException, "No Map Object");
166
+
167
+ for ( q_iterator = (*st).begin(); q_iterator != (*st).end(); q_iterator++ ) {
168
+ rb_str_concat(s,rb_str_new2(q_iterator->first));
169
+ rb_str_concat(s,rb_convert_type(q_iterator->second, T_STRING, "String", "to_str"));
170
+ }
171
+
172
+ return rb_str_to_str(s);
173
+ }
174
+
175
+ static VALUE sptm_to_a (VALUE self)
176
+ {
177
+ VALUE ary = rb_ary_new();
178
+
179
+ rb_map* st = NULL;
180
+ rb_map_iterator q_iterator;
181
+ Data_Get_Struct(self, rb_map, st);
182
+ if (!st)
183
+ rb_raise (rb_eException, "No Map Object");
184
+
185
+ for ( q_iterator = (*st).begin(); q_iterator != (*st).end(); q_iterator++ ) {
186
+ rb_ary_push(ary,rb_str_new2(q_iterator->first));
187
+ rb_ary_push(ary,q_iterator->second);
188
+ }
189
+
190
+ return ary;
191
+ }
192
+
193
+ static VALUE sptm_inspect (VALUE self)
194
+ {
195
+ VALUE s = rb_str_new2("{");
196
+ VALUE arrow = rb_str_new2("=>");
197
+ VALUE comma = rb_str_new2(",");
198
+
199
+ cout << "*1\n";
200
+
201
+ rb_map* st = NULL;
202
+ rb_map_iterator q_iterator;
203
+ rb_map_iterator last_q_iterator;
204
+ rb_map_iterator before_last_q_iterator;
205
+ Data_Get_Struct(self, rb_map, st);
206
+ if (!st)
207
+ rb_raise (rb_eException, "No Map Object");
208
+
209
+ cout << "*1\n";
210
+ if (!((*st).end() == (*st).begin())) {
211
+ before_last_q_iterator = last_q_iterator = (*st).end();
212
+ before_last_q_iterator--;
213
+
214
+ cout << "*1\n";
215
+ for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
216
+ cout << "*1\n";
217
+ rb_str_concat(s,rb_inspect(rb_str_new2((*q_iterator).first)));
218
+ rb_str_concat(s,arrow);
219
+ rb_str_concat(s,rb_inspect((*q_iterator).second));
220
+ if (q_iterator != before_last_q_iterator)
221
+ rb_str_concat(s,comma);
222
+ }
223
+ }
224
+
225
+ rb_str_concat(s,rb_str_new2("}"));
226
+
227
+ return rb_str_to_str(s);
228
+ }
229
+
230
+ static VALUE sptm_first (VALUE self)
231
+ {
232
+ rb_map* st = NULL;
233
+ Data_Get_Struct(self, rb_map, st);
234
+ if (!st)
235
+ rb_raise (rb_eException, "No Map Object");
236
+
237
+ if ((*st).empty()) {
238
+ return Qnil;
239
+ } else {
240
+ rb_map_iterator front = (*st).begin();
241
+ VALUE r = rb_ary_new();
242
+ rb_ary_push(r,rb_str_new2(front->first));
243
+ rb_ary_push(r,front->second);
244
+ return r;
245
+ }
246
+ }
247
+
248
+ static VALUE sptm_last (VALUE self)
249
+ {
250
+ rb_map* st = NULL;
251
+ Data_Get_Struct(self, rb_map, st);
252
+ if (!st)
253
+ rb_raise (rb_eException, "No Map Object");
254
+
255
+ if ((*st).empty()) {
256
+ return Qnil;
257
+ } else {
258
+ rb_map_iterator back = (*st).end();
259
+ back--;
260
+ VALUE r = rb_ary_new();
261
+ rb_ary_push(r,rb_str_new2(back->first));
262
+ rb_ary_push(r,back->second);
263
+ return r;
264
+ }
265
+ }
266
+
267
+ /*
268
+ static VALUE sptm_replace (VALUE self, VALUE new_st)
269
+ {
270
+ rb_map* st = NULL;
271
+ rb_map* nst = NULL;
272
+ rb_map_iterator q_iterator;
273
+ Data_Get_Struct(self, rb_map, st);
274
+ Data_Get_Struct(new_st, rb_map, nst);
275
+ if (!st)
276
+ rb_raise (rb_eException, "No Map Object");
277
+
278
+ if (!nst)
279
+ rb_raise (rb_eException, "No Map object to copy");
280
+
281
+ (*st).clear();
282
+ for ( q_iterator = (*nst).begin(); q_iterator != (*nst).end(); q_iterator++ ) {
283
+ (*st).push_back(*q_iterator);
284
+ }
285
+
286
+ return self;
287
+ }
288
+ */
289
+
290
+
291
+ static VALUE sptm_insert (VALUE self, VALUE key, VALUE val)
292
+ {
293
+ rb_map* st = NULL;
294
+ std::pair<rb_map_iterator, bool> rv;
295
+ std::pair<char *,VALUE> sp;
296
+ char * skey;
297
+ char * svp;
298
+
299
+ svp = StringValuePtr(key);
300
+ skey = new char[strlen(svp)+1];
301
+ strcpy(skey,svp);
302
+
303
+ Data_Get_Struct(self, rb_map, st);
304
+
305
+ if (!st)
306
+ rb_raise (rb_eException, "No Map Object");
307
+
308
+ sp = make_pair(skey,val);
309
+ rv = (*st).insert(sp);
310
+ if (!rv.second) {
311
+ (*st).erase(rv.first);
312
+ (*st).insert(sp);
313
+ }
314
+
315
+ return self;
316
+ }
317
+
318
+ static VALUE sptm_at (VALUE self, VALUE key)
319
+ {
320
+ rb_map* st = NULL;
321
+ rb_map_iterator q_iterator;
322
+
323
+ char * skey = StringValuePtr(key);
324
+
325
+ Data_Get_Struct(self, rb_map, st);
326
+
327
+ if (!st)
328
+ rb_raise (rb_eException, "No Map Object");
329
+
330
+ q_iterator = (*st).find(skey);
331
+ if (q_iterator == (*st).end()) {
332
+ return Qnil;
333
+ } else {
334
+ return q_iterator->second;
335
+ }
336
+ }
337
+
338
+
339
+ static VALUE sptm_delete (VALUE self, VALUE key)
340
+ {
341
+ rb_map* st = NULL;
342
+ rb_map_iterator q_iterator;
343
+
344
+ char * skey = StringValuePtr(key);
345
+
346
+ Data_Get_Struct(self, rb_map, st);
347
+
348
+ if (!st)
349
+ rb_raise (rb_eException, "No Map Object");
350
+
351
+ q_iterator = (*st).find(skey);
352
+ if (q_iterator == (*st).end()) {
353
+ return Qnil;
354
+ } else {
355
+ (*st).erase(q_iterator);
356
+ }
357
+
358
+ return self;
359
+ }
360
+
361
+ /*
362
+ static VALUE sptm_delete_value (VALUE self, VALUE obj)
363
+ {
364
+ rb_map* st = NULL;
365
+ rb_map_iterator q_iterator;
366
+ rb_map_iterator last_q_iterator;
367
+
368
+ Data_Get_Struct(self, rb_map, st);
369
+
370
+ if (!st)
371
+ rb_raise (rb_eException, "No Map Object");
372
+
373
+ last_q_iterator = (*st).end();
374
+ for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
375
+ if (rb_equal(q_iterator->second, obj)) {
376
+ (*st).erase(q_iterator);
377
+ break;
378
+ }
379
+ }
380
+
381
+ return self;
382
+ }
383
+ */
384
+
385
+ static VALUE sptm_each (VALUE self)
386
+ {
387
+ rb_map* st = NULL;
388
+ rb_map_iterator q_iterator;
389
+ rb_map_iterator last_q_iterator;
390
+
391
+ Data_Get_Struct(self, rb_map, st);
392
+
393
+ if (!st)
394
+ rb_raise (rb_eException, "No Map Object");
395
+
396
+ last_q_iterator = (*st).end();
397
+ for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
398
+ rb_yield_values(2,rb_str_new2(q_iterator->first),q_iterator->second);
399
+ }
400
+
401
+ return self;
402
+ }
403
+
404
+ static VALUE sptm_index (VALUE self, VALUE match_obj)
405
+ {
406
+ rb_map* st = NULL;
407
+ rb_map_iterator q_iterator;
408
+ rb_map_iterator last_q_iterator;
409
+
410
+ Data_Get_Struct(self, rb_map, st);
411
+
412
+ if (!st)
413
+ rb_raise (rb_eException, "No Map Object");
414
+
415
+ last_q_iterator = (*st).end();
416
+ for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
417
+ if (rb_equal(q_iterator->second, match_obj)) {
418
+ return rb_str_new2(q_iterator->first);
419
+ }
420
+ }
421
+ return Qnil;
422
+ }
423
+
424
+ static VALUE sptm_keys (VALUE self)
425
+ {
426
+ rb_map* st = NULL;
427
+ rb_map_iterator q_iterator;
428
+ rb_map_iterator last_q_iterator;
429
+
430
+ Data_Get_Struct(self, rb_map, st);
431
+
432
+ if (!st)
433
+ rb_raise (rb_eException, "No Map Object");
434
+
435
+ last_q_iterator = (*st).end();
436
+ VALUE r = rb_ary_new();
437
+ for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
438
+ rb_ary_push(r,rb_str_new2(q_iterator->first));
439
+ }
440
+
441
+ return r;
442
+ }
443
+
444
+ static VALUE sptm_values (VALUE self)
445
+ {
446
+ rb_map* st = NULL;
447
+ rb_map_iterator q_iterator;
448
+ rb_map_iterator last_q_iterator;
449
+
450
+ Data_Get_Struct(self, rb_map, st);
451
+
452
+ if (!st)
453
+ rb_raise (rb_eException, "No Map Object");
454
+
455
+ last_q_iterator = (*st).end();
456
+ VALUE r = rb_ary_new();
457
+ for ( q_iterator = (*st).begin(); q_iterator != last_q_iterator; q_iterator++ ) {
458
+ rb_ary_push(r,q_iterator->second);
459
+ }
460
+
461
+ return r;
462
+ }
463
+
464
+ /**********************
465
+ Init_sptm
466
+ **********************/
467
+
468
+ extern "C" void Init_map()
469
+ {
470
+ SwiftcoreModule = rb_define_module ("Swiftcore");
471
+ MapClass = rb_define_class_under (SwiftcoreModule, "Map", rb_cObject);
472
+
473
+ rb_define_module_function (MapClass, "new", (VALUE(*)(...))sptm_new, 0);
474
+ rb_define_method (MapClass, "shift", (VALUE(*)(...))sptm_pop_front,0);
475
+ rb_define_method (MapClass, "pop", (VALUE(*)(...))sptm_pop_back,0);
476
+ rb_define_method (MapClass, "size", (VALUE(*)(...))sptm_size,0);
477
+ rb_define_method (MapClass, "length", (VALUE(*)(...))sptm_size,0);
478
+ rb_define_method (MapClass, "max_size", (VALUE(*)(...))sptm_max_size,0);
479
+ rb_define_method (MapClass, "clear", (VALUE(*)(...))sptm_clear,0);
480
+ rb_define_method (MapClass, "empty?", (VALUE(*)(...))sptm_empty,0);
481
+ rb_define_method (MapClass, "to_s", (VALUE(*)(...))sptm_to_s,0);
482
+ rb_define_method (MapClass, "to_a", (VALUE(*)(...))sptm_to_a,0);
483
+ rb_define_method (MapClass, "first", (VALUE(*)(...))sptm_first,0);
484
+ rb_define_method (MapClass, "last", (VALUE(*)(...))sptm_last,0);
485
+ //rb_define_method (MapClass, "parent", (VALUE(*)(...))sptm_parent,0);
486
+ //rb_define_method (MapClass, "replace", (VALUE(*)(...))sptm_replace,1);
487
+ rb_define_method (MapClass, "inspect", (VALUE(*)(...))sptm_inspect,0);
488
+ rb_define_method (MapClass, "at", (VALUE(*)(...))sptm_at,1);
489
+ rb_define_method (MapClass, "[]", (VALUE(*)(...))sptm_at,1);
490
+ rb_define_method (MapClass, "delete", (VALUE(*)(...))sptm_delete,1);
491
+ rb_define_method (MapClass, "insert", (VALUE(*)(...))sptm_insert,2);
492
+ rb_define_method (MapClass, "[]=", (VALUE(*)(...))sptm_insert,2);
493
+ rb_define_method (MapClass, "each", (VALUE(*)(...))sptm_each,0);
494
+ rb_define_method (MapClass, "index", (VALUE(*)(...))sptm_index,1);
495
+ rb_define_method (MapClass, "keys", (VALUE(*)(...))sptm_keys,0);
496
+ rb_define_method (MapClass, "values", (VALUE(*)(...))sptm_values,0);
497
+
498
+ /* == [] [] []= clear default default= default_proc delete delete_if each each_key each_pair each_value empty? fetch has_key? has_value? include? index indexes indices initialize_copy inspect invert key? keys length member? merge merge! new pretty_print pretty_print_cycle rehash reject reject! replace select shift size sort store to_a to_hash to_s to_yaml update value? values values_at */
499
+ // rb_include_module (MapClass, rb_mEnumerable);
500
+ }