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
@@ -0,0 +1,132 @@
1
+ #ifndef FLOAT_VECTOR_HPP_
2
+ #define FLOAT_VECTOR_HPP_
3
+
4
+ #include <ruby.h>
5
+ #include <vector>
6
+
7
+ class FloatVector {
8
+ std::vector<double> container;
9
+
10
+ public:
11
+ FloatVector();
12
+ ~FloatVector();
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
+ FloatVector& push_back_object(const double var);
21
+ };
22
+
23
+ FloatVector::FloatVector() {}
24
+
25
+ FloatVector::~FloatVector() {}
26
+
27
+ double FloatVector::first() {
28
+ return this->container.front();
29
+ }
30
+
31
+ double FloatVector::last() {
32
+ return this->container.back();
33
+ }
34
+
35
+ double FloatVector::bracket(const int index) {
36
+ return this->container[index];
37
+ }
38
+
39
+ double FloatVector::bracket_equal(const int index, const double var) {
40
+ return this->container[index] = var;
41
+ }
42
+
43
+ void FloatVector::emplace_back(const double var) {
44
+ this->container.emplace_back(var);
45
+ }
46
+
47
+ int FloatVector::size() {
48
+ return this->container.size();
49
+ }
50
+
51
+ void FloatVector::clear() {
52
+ this->container.clear();
53
+ }
54
+
55
+ FloatVector &FloatVector::push_back_object(const double var) {
56
+ this->container.emplace_back(std::move(var));
57
+ return *this;
58
+ }
59
+
60
+ static FloatVector *getFloatVector(VALUE self) {
61
+ FloatVector *ptr;
62
+ Data_Get_Struct(self, FloatVector, ptr);
63
+ return ptr;
64
+ }
65
+
66
+ static void wrap_float_vector_free(FloatVector *ptr) {
67
+ ptr->~FloatVector();
68
+ ruby_xfree(ptr);
69
+ }
70
+
71
+ static VALUE wrap_float_vector_alloc(VALUE klass) {
72
+ void *p = ruby_xmalloc(sizeof(FloatVector));
73
+ p = new FloatVector;
74
+ return Data_Wrap_Struct(klass, NULL, wrap_float_vector_free, p);
75
+ }
76
+
77
+ static VALUE wrap_float_vector_init(VALUE self) {
78
+ FloatVector *p = getFloatVector(self);
79
+ p = new FloatVector;
80
+ return Qnil;
81
+ }
82
+
83
+ static VALUE wrap_float_vector_first(VALUE self) {
84
+ const double value = getFloatVector(self)->first();
85
+ VALUE result = DBL2NUM(value);
86
+ return result;
87
+ }
88
+
89
+ static VALUE wrap_float_vector_last(VALUE self) {
90
+ const double value = getFloatVector(self)->last();
91
+ VALUE result = DBL2NUM(value);
92
+ return result;
93
+ }
94
+
95
+ static VALUE wrap_float_vector_bracket(VALUE self, VALUE index) {
96
+ const int i = NUM2INT(index);
97
+ const double value = getFloatVector(self)->bracket(i);
98
+ VALUE result = DBL2NUM(value);
99
+ return result;
100
+ }
101
+
102
+ static VALUE wrap_float_vector_bracket_equal(VALUE self, VALUE index, VALUE value) {
103
+ const int i = NUM2INT(index);
104
+ const double v = NUM2DBL(value);
105
+ getFloatVector(self)->bracket_equal(i, v);
106
+ return value;
107
+ }
108
+
109
+ static VALUE wrap_float_vector_emplace_back(VALUE self, VALUE value) {
110
+ const double v = NUM2DBL(value);
111
+ getFloatVector(self)->emplace_back(v);
112
+ return Qnil;
113
+ }
114
+
115
+ static VALUE wrap_float_vector_size(VALUE self) {
116
+ const int size = getFloatVector(self)->size();
117
+ VALUE result = INT2NUM(size);
118
+ return result;
119
+ }
120
+
121
+ static VALUE wrap_float_vector_clear(VALUE self) {
122
+ getFloatVector(self)->clear();
123
+ return Qnil;
124
+ }
125
+
126
+ static VALUE wrap_float_vector_push_back_object(VALUE self, VALUE value) {
127
+ const double v = NUM2DBL(value);
128
+ getFloatVector(self)->push_back_object(v);
129
+ return self;
130
+ }
131
+
132
+ #endif
@@ -0,0 +1,132 @@
1
+ #ifndef INT_VECTOR_HPP_
2
+ #define INT_VECTOR_HPP_
3
+
4
+ #include <ruby.h>
5
+ #include <vector>
6
+
7
+ class IntVector {
8
+ std::vector<int> container;
9
+
10
+ public:
11
+ IntVector();
12
+ ~IntVector();
13
+ int first();
14
+ int last();
15
+ int bracket(const int index);
16
+ int bracket_equal(const int index, const int var);
17
+ void emplace_back(const int var);
18
+ int size();
19
+ void clear();
20
+ IntVector& push_back_object(const int var);
21
+ };
22
+
23
+ IntVector::IntVector() {}
24
+
25
+ IntVector::~IntVector() {}
26
+
27
+ int IntVector::first() {
28
+ return this->container.front();
29
+ }
30
+
31
+ int IntVector::last() {
32
+ return this->container.back();
33
+ }
34
+
35
+ int IntVector::bracket(const int index) {
36
+ return this->container[index];
37
+ }
38
+
39
+ int IntVector::bracket_equal(const int index, const int var) {
40
+ return this->container[index] = var;
41
+ }
42
+
43
+ void IntVector::emplace_back(const int var) {
44
+ this->container.emplace_back(var);
45
+ }
46
+
47
+ int IntVector::size() {
48
+ return this->container.size();
49
+ }
50
+
51
+ void IntVector::clear() {
52
+ this->container.clear();
53
+ }
54
+
55
+ IntVector &IntVector::push_back_object(const int var) {
56
+ this->container.emplace_back(std::move(var));
57
+ return *this;
58
+ }
59
+
60
+ static IntVector *getIntVector(VALUE self) {
61
+ IntVector *ptr;
62
+ Data_Get_Struct(self, IntVector, ptr);
63
+ return ptr;
64
+ }
65
+
66
+ static void wrap_int_vector_free(IntVector *ptr) {
67
+ ptr->~IntVector();
68
+ ruby_xfree(ptr);
69
+ }
70
+
71
+ static VALUE wrap_int_vector_alloc(VALUE klass) {
72
+ void *p = ruby_xmalloc(sizeof(IntVector));
73
+ p = new IntVector;
74
+ return Data_Wrap_Struct(klass, NULL, wrap_int_vector_free, p);
75
+ }
76
+
77
+ static VALUE wrap_int_vector_init(VALUE self) {
78
+ IntVector *p = getIntVector(self);
79
+ p = new IntVector;
80
+ return Qnil;
81
+ }
82
+
83
+ static VALUE wrap_int_vector_first(VALUE self) {
84
+ const int value = getIntVector(self)->first();
85
+ VALUE result = INT2NUM(value);
86
+ return result;
87
+ }
88
+
89
+ static VALUE wrap_int_vector_last(VALUE self) {
90
+ const int value = getIntVector(self)->last();
91
+ VALUE result = INT2NUM(value);
92
+ return result;
93
+ }
94
+
95
+ static VALUE wrap_int_vector_bracket(VALUE self, VALUE index) {
96
+ const int i = NUM2INT(index);
97
+ const int value = getIntVector(self)->bracket(i);
98
+ VALUE result = INT2NUM(value);
99
+ return result;
100
+ }
101
+
102
+ static VALUE wrap_int_vector_bracket_equal(VALUE self, VALUE index, VALUE value) {
103
+ const int i = NUM2INT(index);
104
+ const int v = NUM2INT(value);
105
+ getIntVector(self)->bracket_equal(i, v);
106
+ return value;
107
+ }
108
+
109
+ static VALUE wrap_int_vector_emplace_back(VALUE self, VALUE value) {
110
+ const int v = NUM2INT(value);
111
+ getIntVector(self)->emplace_back(v);
112
+ return Qnil;
113
+ }
114
+
115
+ static VALUE wrap_int_vector_size(VALUE self) {
116
+ const int size = getIntVector(self)->size();
117
+ VALUE result = INT2NUM(size);
118
+ return result;
119
+ }
120
+
121
+ static VALUE wrap_int_vector_clear(VALUE self) {
122
+ getIntVector(self)->clear();
123
+ return Qnil;
124
+ }
125
+
126
+ static VALUE wrap_int_vector_push_back_object(VALUE self, VALUE value) {
127
+ const int v = NUM2INT(value);
128
+ getIntVector(self)->push_back_object(v);
129
+ return self;
130
+ }
131
+
132
+ #endif
@@ -0,0 +1,133 @@
1
+ #ifndef STRING_VECTOR_HPP_
2
+ #define STRING_VECTOR_HPP_
3
+
4
+ #include <ruby.h>
5
+ #include <vector>
6
+ #include <string>
7
+
8
+ class StringVector {
9
+ std::vector<std::string> container;
10
+
11
+ public:
12
+ StringVector();
13
+ ~StringVector();
14
+ std::string first();
15
+ std::string last();
16
+ std::string bracket(const int index);
17
+ std::string bracket_equal(const int index, const std::string var);
18
+ void emplace_back(const std::string var);
19
+ int size();
20
+ void clear();
21
+ StringVector& push_back_object(const std::string var);
22
+ };
23
+
24
+ StringVector::StringVector() {}
25
+
26
+ StringVector::~StringVector() {}
27
+
28
+ std::string StringVector::first() {
29
+ return this->container.front();
30
+ }
31
+
32
+ std::string StringVector::last() {
33
+ return this->container.back();
34
+ }
35
+
36
+ std::string StringVector::bracket(const int index) {
37
+ return this->container[index];
38
+ }
39
+
40
+ std::string StringVector::bracket_equal(const int index, const std::string var) {
41
+ return this->container[index] = var;
42
+ }
43
+
44
+ void StringVector::emplace_back(const std::string var) {
45
+ this->container.emplace_back(var);
46
+ }
47
+
48
+ int StringVector::size() {
49
+ return this->container.size();
50
+ }
51
+
52
+ void StringVector::clear() {
53
+ this->container.clear();
54
+ }
55
+
56
+ StringVector &StringVector::push_back_object(const std::string var) {
57
+ this->container.emplace_back(std::move(var));
58
+ return *this;
59
+ }
60
+
61
+ static StringVector *getStringVector(VALUE self) {
62
+ StringVector *ptr;
63
+ Data_Get_Struct(self, StringVector, ptr);
64
+ return ptr;
65
+ }
66
+
67
+ static void wrap_string_vector_free(StringVector *ptr) {
68
+ ptr->~StringVector();
69
+ ruby_xfree(ptr);
70
+ }
71
+
72
+ static VALUE wrap_string_vector_alloc(VALUE klass) {
73
+ void *p = ruby_xmalloc(sizeof(StringVector));
74
+ p = new StringVector;
75
+ return Data_Wrap_Struct(klass, NULL, wrap_string_vector_free, p);
76
+ }
77
+
78
+ static VALUE wrap_string_vector_init(VALUE self) {
79
+ StringVector *p = getStringVector(self);
80
+ p = new StringVector;
81
+ return Qnil;
82
+ }
83
+
84
+ static VALUE wrap_string_vector_first(VALUE self) {
85
+ const std::string value = getStringVector(self)->first();
86
+ VALUE result = rb_str_new(value.data(), value.size());
87
+ return result;
88
+ }
89
+
90
+ static VALUE wrap_string_vector_last(VALUE self) {
91
+ const std::string value = getStringVector(self)->last();
92
+ VALUE result = rb_str_new(value.data(), value.size());
93
+ return result;
94
+ }
95
+
96
+ static VALUE wrap_string_vector_bracket(VALUE self, VALUE index) {
97
+ const int i = NUM2INT(index);
98
+ const std::string value = getStringVector(self)->bracket(i);
99
+ VALUE result = rb_str_new(value.data(), value.size());
100
+ return result;
101
+ }
102
+
103
+ static VALUE wrap_string_vector_bracket_equal(VALUE self, VALUE index, VALUE value) {
104
+ const int i = NUM2INT(index);
105
+ const std::string v = {StringValueCStr(value)};
106
+ getStringVector(self)->bracket_equal(i, v);
107
+ return value;
108
+ }
109
+
110
+ static VALUE wrap_string_vector_emplace_back(VALUE self, VALUE value) {
111
+ const std::string v = {StringValueCStr(value)};
112
+ getStringVector(self)->emplace_back(v);
113
+ return Qnil;
114
+ }
115
+
116
+ static VALUE wrap_string_vector_size(VALUE self) {
117
+ const int size = getStringVector(self)->size();
118
+ VALUE result = INT2NUM(size);
119
+ return result;
120
+ }
121
+
122
+ static VALUE wrap_string_vector_clear(VALUE self) {
123
+ getStringVector(self)->clear();
124
+ return Qnil;
125
+ }
126
+
127
+ static VALUE wrap_string_vector_push_back_object(VALUE self, VALUE value) {
128
+ const std::string v = {StringValueCStr(value)};
129
+ getStringVector(self)->push_back_object(v);
130
+ return self;
131
+ }
132
+
133
+ #endif
@@ -1,6 +1,10 @@
1
1
  #ifndef VEC_TEMPLATE_H_
2
2
  #define VEC_TEMPLATE_H_
3
3
 
4
+ #include "integer/int_vector.hpp"
5
+ #include "float/float_vector.hpp"
6
+ #include "string/string_vector.hpp"
7
+
4
8
  #include <algorithm>
5
9
  #include <iterator>
6
10
  #include <vector>
@@ -18,9 +18,82 @@ module Tatara
18
18
  (0...(self.size)).each{|i| block.call(self[i], i)}
19
19
  end
20
20
 
21
+ def intersection(other)
22
+ copy = self.dup
23
+ result = self.to_array & other.to_array
24
+ copy.clear
25
+ result.map(&copy.method(:<<))
26
+ return copy
27
+ end
28
+
21
29
  def &(other)
22
30
  self.intersection other
23
31
  end
32
+
33
+ def sort
34
+ copy = self.dup
35
+ result = self.to_array.sort
36
+ copy.clear
37
+ result.each{|v| copy << v}
38
+ return copy
39
+ end
40
+
41
+ def sort!
42
+ result = self.to_array.sort
43
+ self.clear
44
+ result.each{|v| self << v}
45
+ return self
46
+ end
47
+
48
+ def uniq
49
+ copy = self.dup
50
+ result = self.to_array.uniq
51
+ copy.clear
52
+ result.map(&copy.method(:<<))
53
+ return copy
54
+ end
55
+
56
+ def uniq!
57
+ result = self.to_array.uniq
58
+ self.clear
59
+ result.each{|v| self << v}
60
+ return self
61
+ end
62
+
63
+ def reverse
64
+ copy = self.dup
65
+ result = self.to_array.reverse
66
+ result.each{|v| copy << v }
67
+ return copy
68
+ end
69
+
70
+ def reverse!
71
+ result = self.to_array.reverse
72
+ self.clear
73
+ result.each{|v| self << v }
74
+ return self
75
+ end
76
+
77
+ def slice(start, length)
78
+ copy = self.dup
79
+ result = self.to_array.slice(start, length)
80
+ copy.clear
81
+ result.each{|v| copy << v }
82
+ return copy
83
+ end
84
+
85
+ def slice!(start, length)
86
+ result = self.to_array.slice(start, length)
87
+ self.clear
88
+ result.each{|v| self << v }
89
+ return self
90
+ end
91
+
92
+ def to_array
93
+ result = []
94
+ self.map{|v| result << v}
95
+ result
96
+ end
24
97
  end
25
98
 
26
99
  class IntArray