tatara 0.2.0 → 0.3.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +17 -1
  3. data/.gitignore +1 -0
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +0 -2
  6. data/Makefile +11 -73
  7. data/README.md +2 -1
  8. data/docs/tatara/float_array.md +65 -0
  9. data/docs/tatara/float_vector.md +64 -0
  10. data/docs/tatara/integer_array.md +64 -0
  11. data/docs/tatara/integer_vector.md +64 -0
  12. data/docs/tatara/string_array.md +64 -0
  13. data/docs/tatara/string_vector.md +64 -0
  14. data/ext/tatara/array/array.hpp +5 -119
  15. data/ext/tatara/array/float/float_array.hpp +132 -0
  16. data/ext/tatara/array/integer/int_array.hpp +132 -0
  17. data/ext/tatara/array/string/string_array.hpp +133 -0
  18. data/ext/tatara/extconf.rb +1 -1
  19. data/ext/tatara/float/float.hpp +148 -0
  20. data/ext/tatara/integer/integer.hpp +164 -0
  21. data/ext/tatara/map/float/float_float_map.hpp +66 -0
  22. data/ext/tatara/map/float/float_int_map.hpp +66 -0
  23. data/ext/tatara/map/float/float_string_map.hpp +67 -0
  24. data/ext/tatara/map/integer/int_float_map.hpp +66 -0
  25. data/ext/tatara/map/integer/int_int_map.hpp +66 -0
  26. data/ext/tatara/map/integer/int_string_map.hpp +67 -0
  27. data/ext/tatara/map/map.hpp +14 -27
  28. data/ext/tatara/map/string/string_float_map.hpp +67 -0
  29. data/ext/tatara/map/string/string_int_map.hpp +67 -0
  30. data/ext/tatara/map/string/string_string_map.hpp +67 -0
  31. data/ext/tatara/string/string.hpp +105 -0
  32. data/ext/tatara/tatara.cpp +245 -244
  33. data/ext/tatara/vector/float/float_vector.hpp +132 -0
  34. data/ext/tatara/vector/integer/int_vector.hpp +132 -0
  35. data/ext/tatara/vector/string/string_vector.hpp +133 -0
  36. data/ext/tatara/vector/vector.hpp +4 -0
  37. data/lib/tatara/array/array.rb +73 -0
  38. data/lib/tatara/vector/vector.rb +77 -0
  39. data/lib/tatara/version.rb +1 -1
  40. data/tatara.gemspec +1 -0
  41. metadata +31 -2
@@ -243,6 +243,58 @@ Reverse value's.
243
243
  # => [4, 1, 9]
244
244
  ```
245
245
 
246
+ ### Tatara::IntVector#uniq
247
+
248
+ Remove duplicate in `Tatara::IntVector`.
249
+
250
+ ```ruby
251
+ @i = Tatara::IntVector.new
252
+ [1, 3, 4, 1].each{|i| @i << i}
253
+ @i = @i.uniq
254
+ # => Remove duplicate!
255
+ @i.each{|i| puts i }
256
+ # => 1, 3, 4
257
+ ```
258
+
259
+ ### Tatara::IntVector#uniq!
260
+
261
+ Remove destructive duplicate in `Tatara::IntVector`.
262
+
263
+ ```ruby
264
+ @i = Tatara::IntVector.new
265
+ [1, 3, 4, 1].each{|i| @i << i}
266
+ @i.uniq!
267
+ # => Remove duplicate!
268
+ @i.each{|i| puts i }
269
+ # => 1, 3, 4
270
+ ```
271
+
272
+ ### Tatara::IntVector#slice
273
+
274
+ Slice value's' in `Tatara::IntVector`.
275
+
276
+ ```ruby
277
+ @i = Tatara::IntVector.new
278
+ [1, 2, 3, 4, 5].each{|i| @i << i}
279
+ @i = @i.slice(1, 3)
280
+ # => Slice value
281
+ @i.each{|i| puts i }
282
+ # => 2, 3, 4
283
+ ```
284
+
285
+ ### Tatara::IntVector#slice!
286
+
287
+ Destructive Slice value's' in `Tatara::IntVector`.
288
+
289
+ ```ruby
290
+ @i = Tatara::IntVector.new
291
+ [1, 2, 3, 4, 5].each{|i| @i << i}
292
+ @i.slice!(1, 3)
293
+ # => Slice value
294
+ @i.each{|i| puts i }
295
+ # => 2, 3, 4
296
+ ```
297
+
246
298
  ### Tatara::IntVector#first
247
299
 
248
300
  Get first value of `Tatara::IntVector`.
@@ -265,4 +317,16 @@ Get last value of `Tatara::IntVector`.
265
317
  # => Set new value's
266
318
  puts @i.last
267
319
  # => 3
320
+ ```
321
+
322
+ ### Tatara::IntVector#to_array
323
+
324
+ Convert to `Array` from `Tatara::IntVector`.
325
+
326
+ ```ruby
327
+ @i = Tatara::IntVector.new
328
+ (1..3).each{|i| @i << i }
329
+ # => Set new value's
330
+ puts @i.to_array
331
+ # => 1, 2, 3
268
332
  ```
@@ -229,6 +229,58 @@ Reverse value's.
229
229
  # => ["4", "1", "9"]
230
230
  ```
231
231
 
232
+ ### Tatara::StringArray#uniq
233
+
234
+ Remove duplicate in `Tatara::StringArray`.
235
+
236
+ ```ruby
237
+ @s = Tatara::StringArray.new
238
+ ["1", "3", "4", "1"].each{|s| @s << s }
239
+ @s = @s.uniq
240
+ # => Remove duplicate!
241
+ @s.each{|s| puts s }
242
+ # => 1, 3, 4
243
+ ```
244
+
245
+ ### Tatara::StringArray#uniq!
246
+
247
+ Remove destructive duplicate in `Tatara::StringArray`.
248
+
249
+ ```ruby
250
+ @s = Tatara::StringArray.new
251
+ ["1", "3", "4", "1"].each{|s| @s << s }
252
+ @s.uniq!
253
+ # => Remove duplicate!
254
+ @s.each{|s| puts s }
255
+ # => 1, 3, 4
256
+ ```
257
+
258
+ ### Tatara::StringArray#slice
259
+
260
+ Slice value's' in `Tatara::StringArray`.
261
+
262
+ ```ruby
263
+ @s = Tatara::StringArray.new
264
+ ["1", "2", "3", "4", "5"].each{|s| @s << s}
265
+ @s = @s.slice(1, 3)
266
+ # => Slice value
267
+ @s.each{|s| puts s }
268
+ # => 2, 3, 4
269
+ ```
270
+
271
+ ### Tatara::StringArray#slice!
272
+
273
+ Destructive Slice value's' in `Tatara::StringArray`.
274
+
275
+ ```ruby
276
+ @s = Tatara::StringArray.new
277
+ ["1", "2", "3", "4", "5"].each{|s| @s << s}
278
+ @s.slice!(1, 3)
279
+ # => Slice value
280
+ @s.each{|s| puts s }
281
+ # => 2, 3, 4
282
+ ```
283
+
232
284
  ### Tatara::StringArray#first
233
285
 
234
286
  Get first value of `Tatara::StringArray`.
@@ -251,4 +303,16 @@ Get last value of `Tatara::StringArray`.
251
303
  # => Set new value's
252
304
  puts @s.last
253
305
  # => "C"
306
+ ```
307
+
308
+ ### Tatara::StringArray#to_array
309
+
310
+ Convert to `Array` from `Tatara::StringArray`.
311
+
312
+ ```ruby
313
+ @s = Tatara::StringArray.new
314
+ ("A".."C").each{|s| @s << s }
315
+ # => Set new value's
316
+ puts @i.to_array
317
+ # => A, B, C
254
318
  ```
@@ -245,6 +245,58 @@ Reverse value's.
245
245
  # => ["4", "1", "9"]
246
246
  ```
247
247
 
248
+ ### Tatara::StringVector#uniq
249
+
250
+ Remove duplicate in `Tatara::StringVector`.
251
+
252
+ ```ruby
253
+ @s = Tatara::StringVector.new
254
+ ["1", "3", "4", "1"].each{|s| @s << s }
255
+ @s = @s.uniq
256
+ # => Remove duplicate!
257
+ @s.each{|s| puts s }
258
+ # => 1, 3, 4
259
+ ```
260
+
261
+ ### Tatara::StringVector#uniq!
262
+
263
+ Remove destructive duplicate in `Tatara::StringVector`.
264
+
265
+ ```ruby
266
+ @s = Tatara::StringVector.new
267
+ ["1", "3", "4", "1"].each{|s| @s << s }
268
+ @s.uniq!
269
+ # => Remove duplicate!
270
+ @s.each{|s| puts s }
271
+ # => 1, 3, 4
272
+ ```
273
+
274
+ ### Tatara::StringVector#slice
275
+
276
+ Slice value's' in `Tatara::StringVector`.
277
+
278
+ ```ruby
279
+ @s = Tatara::StringVector.new
280
+ ["1", "2", "3", "4", "5"].each{|s| @s << s}
281
+ @s = @s.slice(1, 3)
282
+ # => Slice value
283
+ @s.each{|s| puts s }
284
+ # => 2, 3, 4
285
+ ```
286
+
287
+ ### Tatara::StringVector#slice!
288
+
289
+ Destructive Slice value's' in `Tatara::StringVector`.
290
+
291
+ ```ruby
292
+ @s = Tatara::StringVector.new
293
+ ["1", "2", "3", "4", "5"].each{|s| @s << s}
294
+ @s.slice!(1, 3)
295
+ # => Slice value
296
+ @s.each{|s| puts s }
297
+ # => 2, 3, 4
298
+ ```
299
+
248
300
  ### Tatara::StringVector#first
249
301
 
250
302
  Get first value of `Tatara::StringVector`.
@@ -267,4 +319,16 @@ Get last value of `Tatara::StringVector`.
267
319
  # => Set new value's
268
320
  puts @s.last
269
321
  # => "C"
322
+ ```
323
+
324
+ ### Tatara::StringVector#to_array
325
+
326
+ Convert to `Array` from `Tatara::StringVector`.
327
+
328
+ ```ruby
329
+ @s = Tatara::StringVector.new
330
+ ("A".."C").each{|s| @s << s }
331
+ # => Set new value's
332
+ puts @s.to_array
333
+ # => A, B, C
270
334
  ```
@@ -1,122 +1,8 @@
1
- #ifndef ARRAY__TEMPLATE_H_
2
- #define ARRAY__TEMPLATE_H_
1
+ #ifndef TATARA_ARRAY_HPP_
2
+ #define TATARA_ARRAY_HPP_
3
3
 
4
- #include <algorithm>
5
- #include <iterator>
6
- #include <vector>
7
-
8
- template <class T>
9
- class CppArray {
10
- std::vector<T> container;
11
- public:
12
- constexpr CppArray();
13
- ~CppArray();
14
- constexpr T first();
15
- constexpr T last();
16
- constexpr T bracket(const int index);
17
- constexpr T bracket_equal(const int index, const T var);
18
- constexpr void emplace_back(const T var);
19
- constexpr int size();
20
- constexpr void clear();
21
- constexpr CppArray<T>& push_back_object(const T var);
22
- constexpr CppArray<T> intersection(const CppArray<T> array);
23
- constexpr CppArray<T> sort();
24
- constexpr CppArray<T>& destructive_sort();
25
- constexpr CppArray<T> reverse();
26
- constexpr CppArray<T>& destructive_reverse();
27
- };
28
-
29
- template <class T>
30
- constexpr CppArray<T>::CppArray() {}
31
-
32
- template <class T>
33
- CppArray<T>::~CppArray() {}
34
-
35
- template <class T>
36
- constexpr T CppArray<T>::first() {
37
- return this->container.front();
38
- }
39
-
40
- template <class T>
41
- constexpr T CppArray<T>::last(){
42
- return this->container.back();
43
- }
44
-
45
- template <class T>
46
- constexpr T CppArray<T>::bracket(const int index) {
47
- return this->container[index];
48
- }
49
-
50
- template <class T>
51
- constexpr T CppArray<T>::bracket_equal(const int index, const T var) {
52
- return this->container[index] = var;
53
- }
54
-
55
- template <class T>
56
- constexpr void CppArray<T>::emplace_back(const T var) {
57
- this->container.emplace_back(var);
58
- }
59
-
60
- template <class T>
61
- constexpr int CppArray<T>::size() {
62
- return this->container.size();
63
- }
64
-
65
- template <class T>
66
- constexpr void CppArray<T>::clear() {
67
- this->container.clear();
68
- }
69
-
70
- template <class T>
71
- constexpr CppArray<T>& CppArray<T>::push_back_object(const T var) {
72
- this->container.emplace_back(std::move(var));
73
- return *this;
74
- }
75
-
76
- template <class T>
77
- constexpr CppArray<T> CppArray<T>::intersection(const CppArray<T> array) {
78
-
79
- std::vector<T> result;
80
-
81
- std::set_intersection(
82
- this->container.begin(), this->container.end(),
83
- array.container.begin(), array.container.end(),
84
- std::inserter(result, result.end())
85
- );
86
-
87
- CppArray<T> object;
88
-
89
- object.container = std::move(result);
90
-
91
- return object;
92
- }
93
-
94
- template <class T>
95
- constexpr CppArray<T> CppArray<T>::sort() {
96
- CppArray<T> object;
97
- object.container = this->container;
98
- std::sort(object.container.begin(), object.container.end());
99
- return object;
100
- }
101
-
102
- template <class T>
103
- constexpr CppArray<T>& CppArray<T>::destructive_sort() {
104
- std::sort(this->container.begin(), this->container.end());
105
- return *this;
106
- }
107
-
108
- template <class T>
109
- constexpr CppArray<T> CppArray<T>::reverse() {
110
- CppArray<T> object;
111
- object.container = this->container;
112
- std::reverse(object.container.begin(), object.container.end());
113
- return object;
114
- }
115
-
116
- template <class T>
117
- constexpr CppArray<T>& CppArray<T>::destructive_reverse() {
118
- std::reverse(this->container.begin(), this->container.end());
119
- return *this;
120
- }
4
+ #include "string/string_array.hpp"
5
+ #include "float/float_array.hpp"
6
+ #include "integer/int_array.hpp"
121
7
 
122
8
  #endif
@@ -0,0 +1,132 @@
1
+ #ifndef FLOAT_ARRAY_HPP_
2
+ #define FLOAT_ARRAY_HPP_
3
+
4
+ #include <ruby.h>
5
+ #include <vector>
6
+
7
+ class FloatArray {
8
+ std::vector<double> container;
9
+
10
+ public:
11
+ FloatArray();
12
+ ~FloatArray();
13
+ double first();
14
+ double last();
15
+ double bracket(const int index);
16
+ double bracket_equal(const int index, const double var);
17
+ void emplace_back(const double var);
18
+ int size();
19
+ void clear();
20
+ FloatArray& push_back_object(const double var);
21
+ };
22
+
23
+ FloatArray::FloatArray() {}
24
+
25
+ FloatArray::~FloatArray() {}
26
+
27
+ double FloatArray::first() {
28
+ return this->container.front();
29
+ }
30
+
31
+ double FloatArray::last() {
32
+ return this->container.back();
33
+ }
34
+
35
+ double FloatArray::bracket(const int index) {
36
+ return this->container[index];
37
+ }
38
+
39
+ double FloatArray::bracket_equal(const int index, const double var) {
40
+ return this->container[index] = var;
41
+ }
42
+
43
+ void FloatArray::emplace_back(const double var) {
44
+ this->container.emplace_back(var);
45
+ }
46
+
47
+ int FloatArray::size() {
48
+ return this->container.size();
49
+ }
50
+
51
+ void FloatArray::clear() {
52
+ this->container.clear();
53
+ }
54
+
55
+ FloatArray &FloatArray::push_back_object(const double var) {
56
+ this->container.emplace_back(std::move(var));
57
+ return *this;
58
+ }
59
+
60
+ static FloatArray *getFloatArray(VALUE self) {
61
+ FloatArray *ptr;
62
+ Data_Get_Struct(self, FloatArray, ptr);
63
+ return ptr;
64
+ }
65
+
66
+ static void wrap_float_array_free(FloatArray *ptr) {
67
+ ptr->~FloatArray();
68
+ ruby_xfree(ptr);
69
+ }
70
+
71
+ static VALUE wrap_float_array_alloc(VALUE klass) {
72
+ void *p = ruby_xmalloc(sizeof(FloatArray));
73
+ p = new FloatArray;
74
+ return Data_Wrap_Struct(klass, NULL, wrap_float_array_free, p);
75
+ }
76
+
77
+ static VALUE wrap_float_array_init(VALUE self) {
78
+ FloatArray *p = getFloatArray(self);
79
+ p = new FloatArray;
80
+ return Qnil;
81
+ }
82
+
83
+ static VALUE wrap_float_array_first(VALUE self) {
84
+ const double value = getFloatArray(self)->first();
85
+ VALUE result = DBL2NUM(value);
86
+ return result;
87
+ }
88
+
89
+ static VALUE wrap_float_array_last(VALUE self) {
90
+ const double value = getFloatArray(self)->last();
91
+ VALUE result = DBL2NUM(value);
92
+ return result;
93
+ }
94
+
95
+ static VALUE wrap_float_array_bracket(VALUE self, VALUE index) {
96
+ const int i = NUM2INT(index);
97
+ const double value = getFloatArray(self)->bracket(i);
98
+ VALUE result = DBL2NUM(value);
99
+ return result;
100
+ }
101
+
102
+ static VALUE wrap_float_array_bracket_equal(VALUE self, VALUE index, VALUE value) {
103
+ const int i = NUM2INT(index);
104
+ const double v = NUM2DBL(value);
105
+ getFloatArray(self)->bracket_equal(i, v);
106
+ return value;
107
+ }
108
+
109
+ static VALUE wrap_float_array_emplace_back(VALUE self, VALUE value) {
110
+ const double v = NUM2DBL(value);
111
+ getFloatArray(self)->emplace_back(v);
112
+ return Qnil;
113
+ }
114
+
115
+ static VALUE wrap_float_array_size(VALUE self) {
116
+ const int size = getFloatArray(self)->size();
117
+ VALUE result = INT2NUM(size);
118
+ return result;
119
+ }
120
+
121
+ static VALUE wrap_float_array_clear(VALUE self) {
122
+ getFloatArray(self)->clear();
123
+ return Qnil;
124
+ }
125
+
126
+ static VALUE wrap_float_array_push_back_object(VALUE self, VALUE value) {
127
+ const double v = NUM2DBL(value);
128
+ getFloatArray(self)->push_back_object(v);
129
+ return self;
130
+ }
131
+
132
+ #endif