tatara 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +23 -0
- data/Gemfile.lock +2 -2
- data/README.md +4 -0
- data/docs/_config.yml +1 -0
- data/docs/index.md +100 -0
- data/docs/tatara/float.md +425 -0
- data/docs/tatara/float_array.md +256 -0
- data/docs/tatara/float_float_map.md +52 -0
- data/docs/tatara/float_integer_map.md +52 -0
- data/docs/tatara/float_string_map.md +52 -0
- data/docs/tatara/float_vector.md +269 -0
- data/docs/tatara/integer.md +480 -0
- data/docs/tatara/integer_array.md +256 -0
- data/docs/tatara/integer_float_map.md +52 -0
- data/docs/tatara/integer_integer_map.md +52 -0
- data/docs/tatara/integer_string_map.md +52 -0
- data/docs/tatara/integer_vector.md +268 -0
- data/docs/tatara/string.md +223 -0
- data/docs/tatara/string_array.md +254 -0
- data/docs/tatara/string_float_map.md +56 -0
- data/docs/tatara/string_int_map.md +55 -0
- data/docs/tatara/string_string_map.md +55 -0
- data/docs/tatara/string_vector.md +270 -0
- data/ext/tatara/array/array.hpp +60 -0
- data/ext/tatara/float/float.hpp +51 -0
- data/ext/tatara/integer/integer.hpp +67 -0
- data/ext/tatara/string/string.hpp +28 -0
- data/ext/tatara/tatara.cpp +138 -9
- data/ext/tatara/vector/vector.hpp +60 -0
- data/lib/tatara.rb +2 -0
- data/lib/tatara/array/array.rb +37 -0
- data/lib/tatara/tatara_ext.rb +6 -0
- data/lib/tatara/vector/vector.rb +37 -0
- data/lib/tatara/version.rb +1 -1
- metadata +27 -3
@@ -0,0 +1,56 @@
|
|
1
|
+
# Tatara::StringFloatMap
|
2
|
+
## About
|
3
|
+
|
4
|
+
`Tatara::StringFloatMap` is `Map` class like `static type programming lang`.
|
5
|
+
|
6
|
+
`Tatara::StringFloatMap` used by `String` key, and `Float` value.
|
7
|
+
But, you can not use `Float` and `Integer` for value.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
@f = Tatara::StringFloatMap.new
|
11
|
+
@f["A"] = 4.2
|
12
|
+
# => Key: "A", Value: 4.2
|
13
|
+
@f["B"] = 8
|
14
|
+
# => Key: "B", Value: 8.0
|
15
|
+
```
|
16
|
+
|
17
|
+
But, can not use `Integer` & `Float` for key.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
@f = Tatara::StringFloatMap.new
|
21
|
+
@f[0] = 4.2
|
22
|
+
# => Error!
|
23
|
+
@f[4.2] = 4.2
|
24
|
+
# => Error!
|
25
|
+
```
|
26
|
+
|
27
|
+
## Methods
|
28
|
+
### Tatara::StringFloatMap#new
|
29
|
+
|
30
|
+
Create new `Tatara::StringFloatMap` instance.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
@f = Tatara::StringFloatMap.new
|
34
|
+
```
|
35
|
+
|
36
|
+
### Tatara::StringFloatMap#\[\]
|
37
|
+
|
38
|
+
Access by key.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
@f = Tatara::StringFloatMap.new
|
42
|
+
@f["A"] = 4.2
|
43
|
+
puts @f["A"]
|
44
|
+
# => 4.2
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
### Tatara::StringFloatMap#\[\]=
|
49
|
+
|
50
|
+
Set value by key.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
@f = Tatara::StringFloatMap.new
|
54
|
+
@f["A"] = 4.2
|
55
|
+
# => Set value is 4.2
|
56
|
+
```
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Tatara::StringIntMap
|
2
|
+
## About
|
3
|
+
|
4
|
+
`Tatara::StringIntMap` is `Map` class like `static type programming lang`.
|
5
|
+
|
6
|
+
`Tatara::StringIntMap` used by `String` key, and `Integer` value.
|
7
|
+
But, you can use `Float` and `Integer` for value.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
@i = Tatara::StringIntMap.new
|
11
|
+
@i["A"] = 42
|
12
|
+
# => Key: "A", Value: 42.
|
13
|
+
@i["B"] = 8.4
|
14
|
+
# => Key: "B", Value: 8.
|
15
|
+
```
|
16
|
+
|
17
|
+
But, can not use `Integer` & `Float` for key.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
@i = Tatara::StringIntMap.new
|
21
|
+
@i[42] = 42
|
22
|
+
# => Error!
|
23
|
+
@i[4.2] = 4.2
|
24
|
+
# => Error!
|
25
|
+
```
|
26
|
+
|
27
|
+
## Methods
|
28
|
+
### Tatara::StringIntMap#new
|
29
|
+
|
30
|
+
Create new `Tatara::StringIntMap` instance.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
@i = Tatara::StringIntMap.new
|
34
|
+
```
|
35
|
+
|
36
|
+
### Tatara::StringIntMap#\[\]
|
37
|
+
|
38
|
+
Access by key.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
@i = Tatara::StringIntMap.new
|
42
|
+
@i["A"] = 42
|
43
|
+
puts @i["A"]
|
44
|
+
# => 42
|
45
|
+
```
|
46
|
+
|
47
|
+
### Tatara::StringIntMap#\[\]=
|
48
|
+
|
49
|
+
Set value by key.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
@i = Tatara::StringIntMap.new
|
53
|
+
@i["A"] = 42
|
54
|
+
# => Set value is 42.
|
55
|
+
```
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Tatara::StringStringMap
|
2
|
+
## About
|
3
|
+
|
4
|
+
`Tatara::StringStringMap` is `Map` class like `static type programming lang`.
|
5
|
+
|
6
|
+
`Tatara::StringStringMap` used by `String` key, and `String` value.
|
7
|
+
But, you can not use `Float` and `Integer` for key & value.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
@s = Tatara::StringStringMap.new
|
11
|
+
@s["A"] = "42"
|
12
|
+
# => Key: "A", Value: "42".
|
13
|
+
@s["B"] = "8"
|
14
|
+
# => Key: "B", Value: "8".
|
15
|
+
```
|
16
|
+
|
17
|
+
But, can not set `Integer` & `Float`.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
@s = Tatara::StringStringMap.new
|
21
|
+
@s["A"] = 42
|
22
|
+
# => Error!
|
23
|
+
@s["B"] = 4.2
|
24
|
+
# => Error!
|
25
|
+
```
|
26
|
+
|
27
|
+
## Methods
|
28
|
+
### Tatara::StringStringMap#new
|
29
|
+
|
30
|
+
Create new `Tatara::StringStringMap` instance.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
@s = Tatara::StringStringMap.new
|
34
|
+
```
|
35
|
+
|
36
|
+
### Tatara::StringStringMap#\[\]
|
37
|
+
|
38
|
+
Access by key.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
@s = Tatara::StringStringMap.new
|
42
|
+
@s["A"] = "42"
|
43
|
+
puts @i["A"]
|
44
|
+
# => "42"
|
45
|
+
```
|
46
|
+
|
47
|
+
### Tatara::StringStringMap#\[\]=
|
48
|
+
|
49
|
+
Set value by key.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
@s = Tatara::StringStringMap.new
|
53
|
+
@s["A"] = "42"
|
54
|
+
# => Set value is "42".
|
55
|
+
```
|
@@ -0,0 +1,270 @@
|
|
1
|
+
# Tatara::StringVector
|
2
|
+
## About
|
3
|
+
|
4
|
+
`Tatara::StringVector` is `Vector` class like `static type programming lang`.
|
5
|
+
|
6
|
+
`Tatara::StringVector` use `String` value.
|
7
|
+
But, you can not use `Integer` & `Float` for value.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
@s = Tatara::StringVector.new
|
11
|
+
@s[0] = "42"
|
12
|
+
# => Set value "42" for index of 0.
|
13
|
+
@s[1] = "8.4"
|
14
|
+
# => Set value "8.4" for index of 1.
|
15
|
+
```
|
16
|
+
|
17
|
+
But, can not use `Integer` & `Float` for value.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
@s = Tatara::StringVector.new
|
21
|
+
@s[0] = 42
|
22
|
+
# => Error!
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
## Methods
|
27
|
+
### Tatara::StringVector#new
|
28
|
+
|
29
|
+
Create new `Tatara::StringVector` instance.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
@s = Tatara::StringVector.new
|
33
|
+
```
|
34
|
+
|
35
|
+
### Tatara::StringVector#\[\]
|
36
|
+
|
37
|
+
Access by index.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
@s = Tatara::StringVector.new
|
41
|
+
@s[0] = "42"
|
42
|
+
puts @s[0]
|
43
|
+
# => "42"
|
44
|
+
```
|
45
|
+
|
46
|
+
### Tatara::StringVector#\[\]=
|
47
|
+
|
48
|
+
Set value by index.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
@s = Tatara::StringVector.new
|
52
|
+
@s[0] = "42"
|
53
|
+
# => Set value "42" for index of 0.
|
54
|
+
```
|
55
|
+
|
56
|
+
### Tatara::StringVector#emplace_back
|
57
|
+
|
58
|
+
Create new value on end of `Tatara::StringVector`.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
@s = Tatara::StringVector.new
|
62
|
+
@s.emplace_back("42")
|
63
|
+
# => Set value "42" on end of `Tatara::StringVector`
|
64
|
+
```
|
65
|
+
|
66
|
+
### Tatara::StringVector#size
|
67
|
+
|
68
|
+
Size of `Tatara::StringVector`.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
@s = Tatara::StringVector.new
|
72
|
+
puts @s.size
|
73
|
+
# => 0
|
74
|
+
@s.emplace_back("42")
|
75
|
+
puts @s.size
|
76
|
+
# => 1
|
77
|
+
```
|
78
|
+
|
79
|
+
### Tatara::StringVector#clear
|
80
|
+
|
81
|
+
Clear `Tatara::StringVector`.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
@s = Tatara::StringVector.new
|
85
|
+
@s.emplace_back("42")
|
86
|
+
puts @s.size
|
87
|
+
# => 1
|
88
|
+
@s.clear
|
89
|
+
puts @s.size
|
90
|
+
# => 0
|
91
|
+
```
|
92
|
+
|
93
|
+
### Tatara::StringVector#sum
|
94
|
+
|
95
|
+
Sum value's for `Tatara::StringVector`.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
@s = Tatara::StringVector.new
|
99
|
+
("A".."C").each{|s|
|
100
|
+
@s.emplace_back(s)
|
101
|
+
}
|
102
|
+
puts @s.sum
|
103
|
+
# => "ABC"
|
104
|
+
```
|
105
|
+
|
106
|
+
### Tatara::StringVector#operator<<
|
107
|
+
|
108
|
+
Create new value on end of `Tatara::StringVector`.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
@s = Tatara::StringVector.new
|
112
|
+
@s << "42"
|
113
|
+
# => Set value "42" on end of `Tatara::StringVector`
|
114
|
+
```
|
115
|
+
|
116
|
+
### Tatara::StringVector#map
|
117
|
+
|
118
|
+
`map` method for `Tatara::StringVector`.
|
119
|
+
It's likes `Array#map`
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
@s = Tatara::StringVector.new
|
123
|
+
("A".."C").each{|s| @s << s }
|
124
|
+
# => Set new value's
|
125
|
+
@s.map{|s|
|
126
|
+
puts s
|
127
|
+
}
|
128
|
+
# => A B C
|
129
|
+
```
|
130
|
+
|
131
|
+
### Tatara::StringVector#map!
|
132
|
+
|
133
|
+
`map!` method for `Tatara::StringVector`.
|
134
|
+
It's likes `Array#map!`
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
@s = Tatara::StringVector.new
|
138
|
+
("A".."C").each{|s| @s << s }
|
139
|
+
# => Set new value's
|
140
|
+
@s.map!{|s| s.succ }
|
141
|
+
@s.map{|s|
|
142
|
+
puts s
|
143
|
+
}
|
144
|
+
# => B C D
|
145
|
+
```
|
146
|
+
|
147
|
+
### Tatara::StringVector#each
|
148
|
+
|
149
|
+
`each` method for `Tatara::StringVector`.
|
150
|
+
It's likes `Array#each`
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
@s = Tatara::StringVector.new
|
154
|
+
("A".."C").each{|s| @s << s }
|
155
|
+
# => Set new value's
|
156
|
+
@s.each{|s|
|
157
|
+
puts s
|
158
|
+
}
|
159
|
+
# => A B C
|
160
|
+
```
|
161
|
+
|
162
|
+
|
163
|
+
### Tatara::StringVector#each_with_index
|
164
|
+
|
165
|
+
`each_with_index` method for `Tatara::StringVector`.
|
166
|
+
It's likes `Array#each_with_index`
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
@s = Tatara::StringVector.new
|
170
|
+
("A".."C").each{|s| @s << s }
|
171
|
+
# => Set new value's
|
172
|
+
@s.each_with_index{|v, i|
|
173
|
+
puts "#{i}:#{v}"
|
174
|
+
}
|
175
|
+
# => 1:A 2:B 3:C
|
176
|
+
```
|
177
|
+
|
178
|
+
### Tatara::Stringvector#intersection
|
179
|
+
|
180
|
+
Intersection value's
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
@s1 = Tatara::StringVector.new
|
184
|
+
("A".."C").each{|s| @s1 << s}
|
185
|
+
@s2 = Tatara::StringVector.new
|
186
|
+
("C".."F").each{|s| @s2 << s}
|
187
|
+
@s = @s1.intersection @s2
|
188
|
+
# => ["C"]
|
189
|
+
```
|
190
|
+
|
191
|
+
### Tatara::StringVector#operator&
|
192
|
+
|
193
|
+
Intersection value's
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
@s1 = Tatara::StringVector.new
|
197
|
+
("A".."C").each{|s| @s1 << s}
|
198
|
+
@s2 = Tatara::StringVector.new
|
199
|
+
("C".."F").each{|s| @s2 << s}
|
200
|
+
@s = @s1 & @s2
|
201
|
+
# => ["C"]
|
202
|
+
```
|
203
|
+
|
204
|
+
### Tatara::StringVector#sort
|
205
|
+
|
206
|
+
Sort value's.
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
@s = Tatara::StringVector.new
|
210
|
+
["9", "1", "4"].each{|s| @s << s }
|
211
|
+
@s = @s.sort
|
212
|
+
# => ["1", "4", "9"]
|
213
|
+
```
|
214
|
+
|
215
|
+
### Tatara::StringVector#sort!
|
216
|
+
|
217
|
+
Sort value's.
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
@s = Tatara::StringVector.new
|
221
|
+
["9", "1", "4"].each{|s| @s << s }
|
222
|
+
@s.sort!
|
223
|
+
# => ["1", "4", "9"]
|
224
|
+
```
|
225
|
+
|
226
|
+
### Tatara::StringVector#reverse
|
227
|
+
|
228
|
+
Reverse value's.
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
@s = Tatara::StringVector.new
|
232
|
+
["9", "1", "4"].each{|s| @s << s }
|
233
|
+
@s = @s.reverse
|
234
|
+
# => ["4", "1", "9"]
|
235
|
+
```
|
236
|
+
|
237
|
+
### Tatara::StringVector#reverse!
|
238
|
+
|
239
|
+
Reverse value's.
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
@s = Tatara::StringVector.new
|
243
|
+
["9", "1", "4"].each{|s| @s << s }
|
244
|
+
@s.reverse!
|
245
|
+
# => ["4", "1", "9"]
|
246
|
+
```
|
247
|
+
|
248
|
+
### Tatara::StringVector#first
|
249
|
+
|
250
|
+
Get first value of `Tatara::StringVector`.
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
@s = Tatara::StringVector.new
|
254
|
+
("A".."C").each{|s| @s << s }
|
255
|
+
# => Set new value's
|
256
|
+
puts @s.first
|
257
|
+
# => A
|
258
|
+
```
|
259
|
+
|
260
|
+
### Tatara::StringVector#last
|
261
|
+
|
262
|
+
Get last value of `Tatara::StringVector`.
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
@s = Tatara::StringVector.new
|
266
|
+
("A".."C").each{|s| @s << s }
|
267
|
+
# => Set new value's
|
268
|
+
puts @s.last
|
269
|
+
# => "C"
|
270
|
+
```
|
data/ext/tatara/array/array.hpp
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#ifndef ARRAY__TEMPLATE_H_
|
2
2
|
#define ARRAY__TEMPLATE_H_
|
3
3
|
|
4
|
+
#include <algorithm>
|
5
|
+
#include <iterator>
|
4
6
|
#include <vector>
|
5
7
|
|
6
8
|
template <class T>
|
@@ -16,6 +18,12 @@ class CppArray {
|
|
16
18
|
constexpr void emplace_back(const T var);
|
17
19
|
constexpr int size();
|
18
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();
|
19
27
|
};
|
20
28
|
|
21
29
|
template <class T>
|
@@ -59,4 +67,56 @@ constexpr void CppArray<T>::clear() {
|
|
59
67
|
this->container.clear();
|
60
68
|
}
|
61
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
|
+
}
|
121
|
+
|
62
122
|
#endif
|