s_matrix 0.0.3 → 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.
- checksums.yaml +4 -4
- data/README.md +36 -20
- data/README_for_contributor.md +22 -0
- data/ext/s_matrix/gmatx.cpp +2 -1
- data/ext/s_matrix/gmatx.h +1 -0
- data/ext/s_matrix/matx_content.cpp +2 -0
- data/ext/s_matrix/matx_content.h +1 -0
- data/ext/s_matrix/s_matrix.cpp +5 -5
- data/lib/s_matrix/version.rb +1 -1
- data/lib/s_matrix.rb +2 -2
- data/s_matrix.gemspec +2 -2
- data/spec/smatrix_spec.rb +10 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8531538924a03ba311631db046c9297191ae0d
|
4
|
+
data.tar.gz: 16ac09c06c0106317814bb73553fce502fdf8746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9424d88c77864237d2f7a41dc6bc5ae01f2a339bf3302c0749386abaafb968908cc21c421e8a2f752924b5e1c46f19faf960968737c0677dca04010d9f3eefc5
|
7
|
+
data.tar.gz: 46c2d3de7e6f9227a8b5a583d0bce41928b3fb2ee10851f108a8513816649c95da7326a8651f7d453260fb9a9efd1f0a2f96d339fd6797e980e62d139e15178b
|
data/README.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
Current version 1.0.0
|
2
|
+
Latest stable version is 1.0.0
|
3
|
+
|
4
|
+
### Matrix reduce memory usage for large Hash.
|
5
|
+
Matrix store the hash like this: <br>
|
6
|
+
# {<br>
|
7
|
+
# '234234' => {'id' => '23232', 'name' => 'haha'},<br>
|
8
|
+
# '234235' => {'id' => '23235', 'name' => 'haha2', 'hp' => '232'}<br>
|
9
|
+
# '234236' => {'id' => '23235', 'name' => 'haha2', 'attack' => '2322'}<br>
|
10
|
+
# }<br>
|
11
|
+
For example, loading a game config ./spec/equipment\_strengthen.plist will use 480M when using ruby Hash like this:<br>
|
12
|
+
# {'234232' => {id: '23423', name: 'haha'}}<br>
|
13
|
+
Because there are about 1440000 ruby String objects when loading to memory.<br>
|
14
|
+
And it will use 5M when using SMatrix.<br>
|
15
|
+
Result from test: rspec ./spec/performance\_spec.rb<br>
|
5
16
|
|
6
17
|
## Installation
|
7
18
|
|
@@ -17,20 +28,25 @@ Or install it yourself as:
|
|
17
28
|
|
18
29
|
$ gem install s_matrix
|
19
30
|
|
20
|
-
## Usage
|
21
|
-
|
22
|
-
TODO: Write usage instructions here
|
23
|
-
|
24
|
-
## Contributing
|
25
|
-
1. Fork it ( https://github.com/libinzhangyuan/s_matrix/fork )
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create a new Pull Request
|
30
|
-
|
31
|
-
gem build s_matrix.gemspec
|
32
|
-
|
33
|
-
gem install ./s_matrix-0.0.1.gem # please change version number to current one.
|
34
|
-
|
35
|
-
gem push s_matrix-0.0.1.gem
|
36
31
|
|
32
|
+
## Usage
|
33
|
+
### initialize the config const
|
34
|
+
# every thing will change to string (.to\_s) when saving to SMatrix<br>
|
35
|
+
EQUIPMENTS = SMatrix.new<br>
|
36
|
+
EQUIPMENTS.add\_row('10001', {'id' => '10001', 'name' => 'wood sword', 'attack' => '342'})<br>
|
37
|
+
EQUIPMENTS.add\_row('20002', {id: 10002, name: 'shoe', speed: 5})<br>
|
38
|
+
|
39
|
+
### use the config const
|
40
|
+
# everything get back will be string<br>
|
41
|
+
EQUIPMENTS\['10001'].should == {'id' => '10001', 'name' => 'wood sword', 'attack' => '342''}<br>
|
42
|
+
EQUIPMENTS\['10001']['id'].should == '10001'<br>
|
43
|
+
EQUIPMENTS\['10001'][:id].should == '10001'<br>
|
44
|
+
EQUIPMENTS\['20002'].should == {'id' => '10002', 'name' => 'shoe', 'speed' => '5'}<br>
|
45
|
+
EQUIPMENTS\['20002']['attack'].should == '552'<br>
|
46
|
+
EQUIPMENTS.size.should == 2
|
47
|
+
# or you can use get\_row instead of []<br>
|
48
|
+
EQUIPMENTS.get\_row('20002')<br>
|
49
|
+
# each
|
50
|
+
EQUIPMENTS.each {|k, v| k == '10001', v == {'id' => '10001', 'name' => 'sword', ...} }
|
51
|
+
# for debug
|
52
|
+
puts EQUIPMENTS.to_s
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SMatrix
|
2
|
+
Please coding following the 'Code Compelte' book.
|
3
|
+
And please write the rspec test.
|
4
|
+
|
5
|
+
## Contributing
|
6
|
+
1. Fork it ( https://github.com/libinzhangyuan/s_matrix/fork )
|
7
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
8
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
9
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
10
|
+
5. Create a new Pull Request
|
11
|
+
|
12
|
+
## Compile
|
13
|
+
rake clean
|
14
|
+
rake compile
|
15
|
+
|
16
|
+
## Test
|
17
|
+
rspec ./spec
|
18
|
+
|
19
|
+
# how to build gem
|
20
|
+
gem build s_matrix.gemspec
|
21
|
+
gem install ./s_matrix-0.0.1.gem # please change version number to current one. Find version at lib/s_matrix/version.rb.
|
22
|
+
gem push s_matrix-0.0.1.gem
|
data/ext/s_matrix/gmatx.cpp
CHANGED
@@ -12,6 +12,7 @@ GMatx::GMatx(void)
|
|
12
12
|
void GMatx::add_row(const std::string& id, const t_key_value_hash& row_content)
|
13
13
|
{
|
14
14
|
// 处理新增的title
|
15
|
+
// deal the new title
|
15
16
|
//
|
16
17
|
for (t_key_value_hash::const_iterator iter = row_content.begin();
|
17
18
|
iter != row_content.end(); ++iter)
|
@@ -21,7 +22,7 @@ void GMatx::add_row(const std::string& id, const t_key_value_hash& row_content)
|
|
21
22
|
m_titles.add_title(title);
|
22
23
|
}
|
23
24
|
|
24
|
-
// 加到content中
|
25
|
+
// 加到content中 add this row to content.
|
25
26
|
//
|
26
27
|
m_contents.set_row_with_order(id, row_content, m_titles.get_titles());
|
27
28
|
}
|
data/ext/s_matrix/gmatx.h
CHANGED
@@ -13,6 +13,7 @@ public:
|
|
13
13
|
void add_row(const std::string& id, const t_key_value_hash& row_content);
|
14
14
|
|
15
15
|
// 当找不到id所对应的行时,返回的t_key_value_hash数据的size=0
|
16
|
+
// size of t_key_value_hash will be zero when couldn't find the row.
|
16
17
|
t_key_value_hash get_row(const std::string& id) const;
|
17
18
|
std::string to_s(void) const;
|
18
19
|
size_t size(void) const;
|
@@ -63,6 +63,7 @@ std::string MatxContent::to_s(const std::vector<std::string>& titles) const
|
|
63
63
|
void MatxContent::set_row_with_order(const std::string& id, const t_key_value_hash& row_content, const std::vector<std::string>& titles_for_order)
|
64
64
|
{
|
65
65
|
// 根据titles_for_order的顺序,组装出value
|
66
|
+
// assemble the values following the order of titles_for_order.
|
66
67
|
std::vector<std::string> values;
|
67
68
|
for (std::vector<std::string>::const_iterator iter = titles_for_order.begin();
|
68
69
|
iter != titles_for_order.end(); ++iter)
|
@@ -78,5 +79,6 @@ void MatxContent::set_row_with_order(const std::string& id, const t_key_value_ha
|
|
78
79
|
}
|
79
80
|
|
80
81
|
// 保存行
|
82
|
+
// save row.
|
81
83
|
m_rows[id] = MatxRow(values);
|
82
84
|
}
|
data/ext/s_matrix/matx_content.h
CHANGED
@@ -12,6 +12,7 @@ public:
|
|
12
12
|
MatxContent(void);
|
13
13
|
|
14
14
|
// 按照titles_for_order中的顺序,格式化row_content中的内容,来设置新行
|
15
|
+
// set new row following the order of titles_for_order.
|
15
16
|
void set_row_with_order(const std::string& id, const t_key_value_hash& row_content, const std::vector<std::string>& titles_for_order);
|
16
17
|
|
17
18
|
const MatxRow& get_row(const std::string& id) const;
|
data/ext/s_matrix/s_matrix.cpp
CHANGED
@@ -70,7 +70,7 @@ static VALUE t_add_row(VALUE self, VALUE id, VALUE row)
|
|
70
70
|
Check_Type(row, T_HASH);
|
71
71
|
|
72
72
|
|
73
|
-
// 处理id
|
73
|
+
// 处理id deal with id
|
74
74
|
//
|
75
75
|
VALUE id_str = rb_funcall(id, rb_intern("to_s"), 0);
|
76
76
|
char* p_id_c_str = StringValuePtr(id_str);
|
@@ -78,12 +78,12 @@ static VALUE t_add_row(VALUE self, VALUE id, VALUE row)
|
|
78
78
|
if (p_id_c_str[0] == 0)
|
79
79
|
rb_raise(rb_eTypeError, "id can't be blank!");
|
80
80
|
|
81
|
-
// 处理row
|
81
|
+
// 处理row deal with row
|
82
82
|
//
|
83
83
|
t_key_value_hash row_hash;
|
84
84
|
rb_hash_foreach(row, (int (*)(ANYARGS))t_add_row_hash_iter_func, (VALUE)&row_hash);
|
85
85
|
|
86
|
-
// 存数据
|
86
|
+
// 存数据 store data
|
87
87
|
//
|
88
88
|
class GMatx* pMatx = NULL;
|
89
89
|
Data_Get_Struct(self, class GMatx, pMatx);
|
@@ -110,11 +110,11 @@ static VALUE row_hash_to_ruby_hash(const t_key_value_hash& row_hash)
|
|
110
110
|
|
111
111
|
static VALUE t_get_row(VALUE self, VALUE id)
|
112
112
|
{
|
113
|
-
// 处理id
|
113
|
+
// 处理id deal with id
|
114
114
|
//
|
115
115
|
VALUE id_str = rb_funcall(id, rb_intern("to_s"), 0);
|
116
116
|
char* p_id_c_str = StringValuePtr(id_str);
|
117
|
-
// id 为空字符串
|
117
|
+
// id 为空字符串 check whether id blank
|
118
118
|
if (p_id_c_str[0] == 0)
|
119
119
|
rb_raise(rb_eTypeError, "id can't be blank!");
|
120
120
|
|
data/lib/s_matrix/version.rb
CHANGED
data/lib/s_matrix.rb
CHANGED
data/s_matrix.gemspec
CHANGED
data/spec/smatrix_spec.rb
CHANGED
@@ -85,6 +85,16 @@ describe SMatrix do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
describe '[]' do
|
89
|
+
it '' do
|
90
|
+
a = SMatrix.new
|
91
|
+
a.add_row('2', {a: 2})
|
92
|
+
a.add_row('2', {b: 3})
|
93
|
+
expect(a['2']).to eq({'a' => nil, 'b' => '3'})
|
94
|
+
expect(a['2'][:a]).to eq nil
|
95
|
+
expect(a['2']['b']).to eq '3'
|
96
|
+
end
|
97
|
+
end
|
88
98
|
|
89
99
|
end
|
90
100
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s_matrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhangyuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.1
|
75
|
+
version: '3.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.1
|
82
|
+
version: '3.1'
|
83
83
|
description: not finish
|
84
84
|
email:
|
85
85
|
- libinzhangyuan@gmail.com
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- Gemfile
|
93
93
|
- LICENSE
|
94
94
|
- README.md
|
95
|
+
- README_for_contributor.md
|
95
96
|
- Rakefile
|
96
97
|
- ext/s_matrix/Makefile
|
97
98
|
- ext/s_matrix/extconf.rb
|