hamster 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/History.rdoc +16 -0
  2. data/README.rdoc +10 -10
  3. data/lib/hamster/core_ext/enumerable.rb +1 -1
  4. data/lib/hamster/core_ext/enumerable.rbc +481 -0
  5. data/lib/hamster/core_ext/io.rb +0 -1
  6. data/lib/hamster/core_ext/io.rbc +604 -0
  7. data/lib/hamster/hash.rb +6 -6
  8. data/lib/hamster/hash.rbc +3117 -0
  9. data/lib/hamster/list.rb +50 -14
  10. data/lib/hamster/list.rbc +7274 -0
  11. data/lib/hamster/set.rb +8 -7
  12. data/lib/hamster/set.rbc +3152 -0
  13. data/lib/hamster/stack.rbc +1358 -0
  14. data/lib/hamster/trie.rbc +3416 -0
  15. data/lib/hamster/version.rb +1 -1
  16. data/spec/hamster/core_ext/enumerable_spec.rb +1 -1
  17. data/spec/hamster/core_ext/enumerable_spec.rbc +747 -0
  18. data/spec/hamster/core_ext/io_spec.rbc +409 -0
  19. data/spec/hamster/hash/all_spec.rbc +1214 -0
  20. data/spec/hamster/hash/any_spec.rbc +1495 -0
  21. data/spec/hamster/hash/construction_spec.rbc +742 -0
  22. data/spec/hamster/hash/copying_spec.rbc +519 -0
  23. data/spec/hamster/hash/each_spec.rbc +908 -0
  24. data/spec/hamster/hash/empty_spec.rbc +517 -0
  25. data/spec/hamster/hash/eql_spec.rb +1 -1
  26. data/spec/hamster/hash/eql_spec.rbc +1702 -0
  27. data/spec/hamster/hash/filter_spec.rbc +1433 -0
  28. data/spec/hamster/hash/get_spec.rbc +791 -0
  29. data/spec/hamster/hash/has_key_spec.rbc +719 -0
  30. data/spec/hamster/hash/map_spec.rbc +1454 -0
  31. data/spec/hamster/hash/none_spec.rbc +1399 -0
  32. data/spec/hamster/hash/put_spec.rbc +1334 -0
  33. data/spec/hamster/hash/reduce_spec.rbc +1234 -0
  34. data/spec/hamster/hash/reject_spec.rbc +1445 -0
  35. data/spec/hamster/hash/remove_spec.rbc +1135 -0
  36. data/spec/hamster/hash/size_spec.rbc +596 -0
  37. data/spec/hamster/list/all_spec.rb +12 -4
  38. data/spec/hamster/list/all_spec.rbc +1760 -0
  39. data/spec/hamster/list/any_spec.rb +12 -4
  40. data/spec/hamster/list/any_spec.rbc +1888 -0
  41. data/spec/hamster/list/append_spec.rb +12 -5
  42. data/spec/hamster/list/append_spec.rbc +1555 -0
  43. data/spec/hamster/list/cadr_spec.rb +1 -1
  44. data/spec/hamster/list/cadr_spec.rbc +855 -0
  45. data/spec/hamster/list/cons_spec.rbc +848 -0
  46. data/spec/hamster/list/construction_spec.rbc +1732 -0
  47. data/spec/hamster/list/copying_spec.rbc +555 -0
  48. data/spec/hamster/list/drop_spec.rb +12 -4
  49. data/spec/hamster/list/drop_spec.rbc +1081 -0
  50. data/spec/hamster/list/drop_while_spec.rb +12 -4
  51. data/spec/hamster/list/drop_while_spec.rbc +1286 -0
  52. data/spec/hamster/list/each_spec.rb +13 -5
  53. data/spec/hamster/list/each_spec.rbc +1365 -0
  54. data/spec/hamster/list/empty_spec.rb +1 -1
  55. data/spec/hamster/list/empty_spec.rbc +571 -0
  56. data/spec/hamster/list/eql_spec.rb +15 -5
  57. data/spec/hamster/list/eql_spec.rbc +1819 -0
  58. data/spec/hamster/list/filter_spec.rb +13 -5
  59. data/spec/hamster/list/filter_spec.rbc +1595 -0
  60. data/spec/hamster/list/find_spec.rb +12 -4
  61. data/spec/hamster/list/find_spec.rbc +1456 -0
  62. data/spec/hamster/list/head_spec.rb +1 -1
  63. data/spec/hamster/list/head_spec.rbc +575 -0
  64. data/spec/hamster/list/include_spec.rb +12 -4
  65. data/spec/hamster/list/include_spec.rbc +1173 -0
  66. data/spec/hamster/list/inspect_spec.rb +13 -5
  67. data/spec/hamster/list/inspect_spec.rbc +995 -0
  68. data/spec/hamster/list/map_spec.rb +12 -4
  69. data/spec/hamster/list/map_spec.rbc +1545 -0
  70. data/spec/hamster/list/maximum_spec.rb +83 -0
  71. data/spec/hamster/list/minimum_spec.rb +83 -0
  72. data/spec/hamster/list/none_spec.rb +11 -3
  73. data/spec/hamster/list/none_spec.rbc +1788 -0
  74. data/spec/hamster/list/one_spec.rb +83 -0
  75. data/spec/hamster/list/partition_spec.rb +37 -9
  76. data/spec/hamster/list/partition_spec.rbc +2715 -0
  77. data/spec/hamster/list/reduce_spec.rb +12 -4
  78. data/spec/hamster/list/reduce_spec.rbc +2081 -0
  79. data/spec/hamster/list/reject_spec.rb +12 -4
  80. data/spec/hamster/list/reject_spec.rbc +1590 -0
  81. data/spec/hamster/list/reverse_spec.rb +12 -4
  82. data/spec/hamster/list/reverse_spec.rbc +1061 -0
  83. data/spec/hamster/list/size_spec.rb +13 -5
  84. data/spec/hamster/list/size_spec.rbc +1063 -0
  85. data/spec/hamster/list/tail_spec.rb +1 -1
  86. data/spec/hamster/list/tail_spec.rbc +595 -0
  87. data/spec/hamster/list/take_spec.rb +12 -4
  88. data/spec/hamster/list/take_spec.rbc +1075 -0
  89. data/spec/hamster/list/take_while_spec.rb +12 -4
  90. data/spec/hamster/list/take_while_spec.rbc +1446 -0
  91. data/spec/hamster/list/to_a_spec.rb +31 -19
  92. data/spec/hamster/list/to_a_spec.rbc +961 -0
  93. data/spec/hamster/list/to_ary_spec.rb +11 -3
  94. data/spec/hamster/list/to_ary_spec.rbc +1080 -0
  95. data/spec/hamster/list/to_list_spec.rb +31 -0
  96. data/spec/hamster/set/add_spec.rbc +1039 -0
  97. data/spec/hamster/set/all_spec.rbc +1316 -0
  98. data/spec/hamster/set/any_spec.rbc +1444 -0
  99. data/spec/hamster/set/construction_spec.rbc +422 -0
  100. data/spec/hamster/set/copying_spec.rbc +469 -0
  101. data/spec/hamster/set/each_spec.rbc +820 -0
  102. data/spec/hamster/set/empty_spec.rbc +452 -0
  103. data/spec/hamster/set/eql_spec.rb +1 -1
  104. data/spec/hamster/set/eql_spec.rbc +1309 -0
  105. data/spec/hamster/set/filter_spec.rbc +1272 -0
  106. data/spec/hamster/set/include_spec.rbc +657 -0
  107. data/spec/hamster/set/map_spec.rbc +1285 -0
  108. data/spec/hamster/set/none_spec.rbc +1344 -0
  109. data/spec/hamster/set/reduce_spec.rbc +1177 -0
  110. data/spec/hamster/set/reject_spec.rbc +1273 -0
  111. data/spec/hamster/set/remove_spec.rbc +947 -0
  112. data/spec/hamster/set/size_spec.rbc +531 -0
  113. data/spec/hamster/set/to_a_spec.rb +16 -12
  114. data/spec/hamster/set/to_a_spec.rbc +559 -0
  115. data/spec/hamster/stack/construction_spec.rbc +862 -0
  116. data/spec/hamster/stack/copying_spec.rbc +555 -0
  117. data/spec/hamster/stack/empty_spec.rb +1 -1
  118. data/spec/hamster/stack/empty_spec.rbc +571 -0
  119. data/spec/hamster/stack/eql_spec.rb +1 -1
  120. data/spec/hamster/stack/eql_spec.rbc +1281 -0
  121. data/spec/hamster/stack/inspect_spec.rb +1 -1
  122. data/spec/hamster/stack/inspect_spec.rbc +586 -0
  123. data/spec/hamster/stack/pop_spec.rbc +1099 -0
  124. data/spec/hamster/stack/push_spec.rbc +848 -0
  125. data/spec/hamster/stack/size_spec.rb +1 -1
  126. data/spec/hamster/stack/size_spec.rbc +650 -0
  127. data/spec/hamster/stack/top_spec.rbc +676 -0
  128. data/spec/hamster/trie/remove_spec.rbc +40 -0
  129. data/spec/spec_helper.rbc +163 -0
  130. data/tasks/spec.rbc +201 -0
  131. metadata +90 -2
@@ -1,3 +1,19 @@
1
+ === 0.1.16 / 2009-12-30
2
+
3
+ * Ensure streams cache results.
4
+
5
+ * Ensure lists don't blow the stack.
6
+
7
+ * List#entries is now an alias for List#to_a.
8
+
9
+ * Implement List#to_list.
10
+
11
+ * Implement List#one?.
12
+
13
+ * Set#to_a is now aliased as #entries.
14
+
15
+ * Implement List#minimum (aliased as #min) and List#maximum (aliased as #max).
16
+
1
17
  === 0.1.15 / 2009-12-15
2
18
 
3
19
  * Implemented IO#to_list.
@@ -1,6 +1,6 @@
1
1
  = Hamster
2
2
 
3
- Hamster started out as an implementation of Hash Array Mapped Hashes (HAMT) for Ruby (see http://lamp.epfl.ch/papers/idealhashtrees.pdf) and has since expanded to include implementations of other Persistent Data Structures (see http://en.wikipedia.org/wiki/Persistent_data_structure) such as Sets, Lists, Stacks, etc.
3
+ Hamster started out as an implementation of Hash Array Mapped Trees (HAMT) for Ruby (see http://lamp.epfl.ch/papers/idealhashtrees.pdf) and has since expanded to include implementations of other Persistent Data Structures (see http://en.wikipedia.org/wiki/Persistent_data_structure) such as Sets, Lists, Stacks, etc.
4
4
 
5
5
  == Huh?
6
6
 
@@ -73,9 +73,9 @@ versus
73
73
 
74
74
  (1..10000).each { |i| hash[i] } # => 0.001s
75
75
 
76
- Impressive huh? What's even better is--or worse depending on your perspective--is that after all that, the native <tt>Hash</tt> version still isn't thread-safe and still requires some synchronisation around it slowing it down even further!
76
+ Impressive huh? What's even better is--or worse depending on your perspective--is that after all that, the native <tt>Hash</tt> version still isn't thread-safe and still requires some synchronisation around it slowing it down even further.
77
77
 
78
- The <tt>Hamster::Hash</tt> version on the other hand was unchanged from the original whilst remaining inherently thread-safe, and 3 orders of magnitude faster!
78
+ The <tt>Hamster::Hash</tt> version on the other hand was unchanged from the original whilst remaining inherently thread-safe, and 3 orders of magnitude faster.
79
79
 
80
80
  == Sure, but as you say, you still need synchronisation so why bother with the copying?
81
81
 
@@ -129,9 +129,9 @@ Besides <tt>Hamster.list</tt> there are other ways to construct lists:
129
129
 
130
130
  You also get <tt>Enumerable#to_list</tt> so you can slowly transition from built-in collection classes to Hamster.
131
131
 
132
- And finally, you also <tt>IO#to_list</tt> allowing you to lazily processes huge files. For example, imagine the following code to process a 10MB file:
132
+ And finally, you get <tt>IO#to_list</tt> allowing you to lazily processes huge files. For example, imagine the following code to process a 100MB file:
133
133
 
134
- File.open("my_10_mb_file.txt") do |io|
134
+ File.open("my_100_mb_file.txt") do |io|
135
135
  lines = []
136
136
  io.each_line do |line|
137
137
  break if lines.size == 10
@@ -141,14 +141,14 @@ And finally, you also <tt>IO#to_list</tt> allowing you to lazily processes huge
141
141
 
142
142
  How many times/how long did you read the code before it became apparent what the code actually did? Now compare that to the following:
143
143
 
144
- File.open("my_10_mb_file.txt") do |io|
145
- io.map(&:chomp).map(&:downcase).map(&:reverse)[0, 10]
144
+ File.open("my_100_mb_file.txt") do |io|
145
+ io.map(&:chomp).map(&:downcase).map(&:reverse).take(10)
146
146
  end
147
147
 
148
- Unfortunately, though the second example reads nicely, it takes around 3 seconds to run--compared with 0.033 seconds for the first--even though we're only interested in the first 10 lines! However, using a little <tt>#to_list</tt> magic, we can get the running time down to 0.033 seconds!
148
+ Unfortunately, though the second example reads nicely, it takes around 13 seconds to run (compared with 0.033 seconds for the first) even though we're only interested in the first 10 lines! However, using a little <tt>#to_list</tt> magic, we can get the running time back down to 0.033 seconds!
149
149
 
150
- File.open("my_10_mb_file.txt") do |io|
151
- puts io.to_list.map(&:chomp).map(&:downcase).map(&:reverse).take(10)
150
+ File.open("my_100_mb_file.txt") do |io|
151
+ io.to_list.map(&:chomp).map(&:downcase).map(&:reverse).take(10)
152
152
  end
153
153
 
154
154
  How is this even possible? It's possible because <tt>IO#to_list</tt> creates a lazy list whereby each line is only ever read and processed as needed, in effect converting it to the first example without all the syntactic, imperative, noise.
@@ -7,7 +7,7 @@ module Hamster
7
7
  module Enumerable
8
8
 
9
9
  def to_list
10
- Hamster.list(self)
10
+ Hamster.list(*self)
11
11
  end
12
12
 
13
13
  end
@@ -0,0 +1,481 @@
1
+ !RBIX
2
+ 0
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 69
13
+ 5
14
+ 7
15
+ 0
16
+ 60
17
+ 44
18
+ 46
19
+ 1
20
+ 1
21
+ 14
22
+ 42
23
+ 2
24
+ 3
25
+ 7
26
+ 4
27
+ 61
28
+ 46
29
+ 5
30
+ 2
31
+ 13
32
+ 42
33
+ 2
34
+ 6
35
+ 12
36
+ 7
37
+ 7
38
+ 12
39
+ 7
40
+ 8
41
+ 12
42
+ 61
43
+ 12
44
+ 46
45
+ 9
46
+ 4
47
+ 14
48
+ 45
49
+ 7
50
+ 14
51
+ 42
52
+ 2
53
+ 10
54
+ 7
55
+ 11
56
+ 61
57
+ 46
58
+ 5
59
+ 2
60
+ 13
61
+ 42
62
+ 2
63
+ 12
64
+ 12
65
+ 7
66
+ 7
67
+ 12
68
+ 7
69
+ 13
70
+ 12
71
+ 61
72
+ 12
73
+ 46
74
+ 9
75
+ 4
76
+ 14
77
+ 45
78
+ 7
79
+ 14
80
+ 2
81
+ 11
82
+ I
83
+ 6
84
+ I
85
+ 0
86
+ I
87
+ 0
88
+ I
89
+ 0
90
+ n
91
+ p
92
+ 14
93
+ s
94
+ 12
95
+ hamster/list
96
+ x
97
+ 7
98
+ require
99
+ x
100
+ 8
101
+ Rubinius
102
+ n
103
+ x
104
+ 7
105
+ Hamster
106
+ x
107
+ 11
108
+ open_module
109
+ n
110
+ x
111
+ 15
112
+ __module_init__
113
+ M
114
+ 1
115
+ n
116
+ n
117
+ x
118
+ 7
119
+ Hamster
120
+ i
121
+ 31
122
+ 5
123
+ 62
124
+ 42
125
+ 0
126
+ 1
127
+ 7
128
+ 2
129
+ 61
130
+ 46
131
+ 3
132
+ 2
133
+ 13
134
+ 42
135
+ 0
136
+ 4
137
+ 12
138
+ 7
139
+ 5
140
+ 12
141
+ 7
142
+ 6
143
+ 12
144
+ 61
145
+ 12
146
+ 46
147
+ 7
148
+ 4
149
+ 14
150
+ 45
151
+ 5
152
+ 11
153
+ I
154
+ 6
155
+ I
156
+ 0
157
+ I
158
+ 0
159
+ I
160
+ 0
161
+ n
162
+ p
163
+ 8
164
+ x
165
+ 8
166
+ Rubinius
167
+ n
168
+ x
169
+ 7
170
+ CoreExt
171
+ x
172
+ 11
173
+ open_module
174
+ n
175
+ x
176
+ 15
177
+ __module_init__
178
+ M
179
+ 1
180
+ n
181
+ n
182
+ x
183
+ 7
184
+ CoreExt
185
+ i
186
+ 31
187
+ 5
188
+ 62
189
+ 42
190
+ 0
191
+ 1
192
+ 7
193
+ 2
194
+ 61
195
+ 46
196
+ 3
197
+ 2
198
+ 13
199
+ 42
200
+ 0
201
+ 4
202
+ 12
203
+ 7
204
+ 5
205
+ 12
206
+ 7
207
+ 6
208
+ 12
209
+ 61
210
+ 12
211
+ 46
212
+ 7
213
+ 4
214
+ 14
215
+ 45
216
+ 5
217
+ 11
218
+ I
219
+ 6
220
+ I
221
+ 0
222
+ I
223
+ 0
224
+ I
225
+ 0
226
+ n
227
+ p
228
+ 8
229
+ x
230
+ 8
231
+ Rubinius
232
+ n
233
+ x
234
+ 10
235
+ Enumerable
236
+ x
237
+ 11
238
+ open_module
239
+ n
240
+ x
241
+ 15
242
+ __module_init__
243
+ M
244
+ 1
245
+ n
246
+ n
247
+ x
248
+ 10
249
+ Enumerable
250
+ i
251
+ 17
252
+ 5
253
+ 62
254
+ 42
255
+ 0
256
+ 1
257
+ 7
258
+ 2
259
+ 7
260
+ 3
261
+ 61
262
+ 63
263
+ 45
264
+ 4
265
+ 46
266
+ 5
267
+ 4
268
+ 11
269
+ I
270
+ 5
271
+ I
272
+ 0
273
+ I
274
+ 0
275
+ I
276
+ 0
277
+ n
278
+ p
279
+ 6
280
+ x
281
+ 8
282
+ Rubinius
283
+ n
284
+ x
285
+ 7
286
+ to_list
287
+ M
288
+ 1
289
+ n
290
+ n
291
+ x
292
+ 7
293
+ to_list
294
+ i
295
+ 10
296
+ 42
297
+ 0
298
+ 1
299
+ 5
300
+ 33
301
+ 1
302
+ 48
303
+ 2
304
+ 0
305
+ 11
306
+ I
307
+ 3
308
+ I
309
+ 0
310
+ I
311
+ 0
312
+ I
313
+ 0
314
+ n
315
+ p
316
+ 3
317
+ x
318
+ 7
319
+ Hamster
320
+ n
321
+ x
322
+ 4
323
+ list
324
+ p
325
+ 5
326
+ I
327
+ 0
328
+ I
329
+ 9
330
+ I
331
+ 0
332
+ I
333
+ a
334
+ I
335
+ a
336
+ x
337
+ 72
338
+ /Users/haruki_zaemon/Projects/hamster/lib/hamster/core_ext/enumerable.rb
339
+ p
340
+ 0
341
+ x
342
+ 17
343
+ method_visibility
344
+ x
345
+ 15
346
+ add_defn_method
347
+ p
348
+ 3
349
+ I
350
+ 2
351
+ I
352
+ 9
353
+ I
354
+ 11
355
+ x
356
+ 72
357
+ /Users/haruki_zaemon/Projects/hamster/lib/hamster/core_ext/enumerable.rb
358
+ p
359
+ 0
360
+ x
361
+ 13
362
+ attach_method
363
+ p
364
+ 3
365
+ I
366
+ 2
367
+ I
368
+ 7
369
+ I
370
+ 1f
371
+ x
372
+ 72
373
+ /Users/haruki_zaemon/Projects/hamster/lib/hamster/core_ext/enumerable.rb
374
+ p
375
+ 0
376
+ x
377
+ 13
378
+ attach_method
379
+ p
380
+ 3
381
+ I
382
+ 2
383
+ I
384
+ 5
385
+ I
386
+ 1f
387
+ x
388
+ 72
389
+ /Users/haruki_zaemon/Projects/hamster/lib/hamster/core_ext/enumerable.rb
390
+ p
391
+ 0
392
+ x
393
+ 13
394
+ attach_method
395
+ n
396
+ x
397
+ 10
398
+ Enumerable
399
+ n
400
+ M
401
+ 1
402
+ n
403
+ n
404
+ x
405
+ 10
406
+ Enumerable
407
+ i
408
+ 15
409
+ 5
410
+ 62
411
+ 5
412
+ 42
413
+ 0
414
+ 1
415
+ 40
416
+ 2
417
+ 40
418
+ 3
419
+ 44
420
+ 46
421
+ 4
422
+ 1
423
+ 11
424
+ I
425
+ 2
426
+ I
427
+ 0
428
+ I
429
+ 0
430
+ I
431
+ 0
432
+ n
433
+ p
434
+ 5
435
+ x
436
+ 7
437
+ Hamster
438
+ n
439
+ x
440
+ 7
441
+ CoreExt
442
+ x
443
+ 10
444
+ Enumerable
445
+ x
446
+ 7
447
+ include
448
+ p
449
+ 3
450
+ I
451
+ 2
452
+ I
453
+ 15
454
+ I
455
+ f
456
+ x
457
+ 72
458
+ /Users/haruki_zaemon/Projects/hamster/lib/hamster/core_ext/enumerable.rb
459
+ p
460
+ 0
461
+ p
462
+ 7
463
+ I
464
+ 0
465
+ I
466
+ 1
467
+ I
468
+ 9
469
+ I
470
+ 3
471
+ I
472
+ 26
473
+ I
474
+ 13
475
+ I
476
+ 45
477
+ x
478
+ 72
479
+ /Users/haruki_zaemon/Projects/hamster/lib/hamster/core_ext/enumerable.rb
480
+ p
481
+ 0