rb_lovely 0.3.5 → 0.3.6

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rb_lovely/sorted_hash.cpp +15 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa291ad84cd1fa7db1a13c62a7647e49adb0b265
4
- data.tar.gz: 7bfa34a4ee273bfdfd429a7709092df5bf8bdada
3
+ metadata.gz: a5aaffcb2aeeca73c556c9a29b3c6800bd03994e
4
+ data.tar.gz: c6b933b7ded2d336418e50423c5c30df9cd2db0b
5
5
  SHA512:
6
- metadata.gz: f998f792864a6cf390f002c71828531b83b1e5cc81464e8ea8101022c41c178475faee730f69376b4b01c2acecc2b131d4d6089d491c60aad11d06098acc1737
7
- data.tar.gz: c531ac60d13661fd9192403d60b0faf1aebf1f224c4b66200e0ed2b5550a327b1ce6cc89549158f46602cfb76d31c392afe27102b6f7c1138002758850fee6b6
6
+ metadata.gz: 65328353f0bffd687d74626f3a9c40f70f916d3d0160c046dc671daf3cda1e76959a2c6dc4d9e60e6ed3ab2eebfe5e259854f8722ac53f48cdf106d4904ea5b6
7
+ data.tar.gz: ebc183484d5e723d7aebcdcae5738e1d2c28d38aaf8102d39236f75ca823aed2ac7ee3fa41b661b68959283b5cf2f26256e563473b870a49be4a96c329da0e7f
@@ -94,7 +94,6 @@ VALUE hashInitialize(int argc, VALUE *argv, VALUE self) {
94
94
 
95
95
  VALUE hashUpdate(VALUE self, VALUE key, VALUE val) {
96
96
  Hash* hash = rubyCast<Hash>(self);
97
- // TODO: overwrite value
98
97
  auto it = hash->container.find(key);
99
98
  if (it != hash->container.end())
100
99
  hash->container.replace(it, member(hash->compareProc, key, val));
@@ -103,6 +102,20 @@ VALUE hashUpdate(VALUE self, VALUE key, VALUE val) {
103
102
  return self;
104
103
  }
105
104
 
105
+ VALUE hashReplace(VALUE self, VALUE key, VALUE val) {
106
+ Hash* hash = rubyCast<Hash>(self);
107
+ auto it = hash->container.find(key);
108
+ if (it != hash->container.end()) {
109
+ auto valBackup = it->val;
110
+ hash->container.replace(it, member(hash->compareProc, key, val));
111
+ return valBackup;
112
+ }
113
+ else {
114
+ hash->container.insert(member(hash->compareProc, key, val));
115
+ return Qnil;
116
+ }
117
+ }
118
+
106
119
  VALUE hashGet(VALUE self, VALUE key) {
107
120
  Hash* hash = rubyCast<Hash>(self);
108
121
  auto it = hash->container.find(key);
@@ -220,7 +233,7 @@ extern "C" {
220
233
  rb_define_method(rbHash, "length", RUBY_METHOD_FUNC(hashLength), 0);
221
234
  rb_define_method(rbHash, "[]=", RUBY_METHOD_FUNC(hashUpdate), 2);
222
235
  // like []= but return previous value if there was one
223
- // rb_define_method(rbHash, "set", RUBY_METHOD_FUNC(hashGetAndUpdate), 2);
236
+ rb_define_method(rbHash, "replace", RUBY_METHOD_FUNC(hashReplace), 2);
224
237
  rb_define_method(rbHash, "[]", RUBY_METHOD_FUNC(hashGet), 1);
225
238
  rb_define_method(rbHash, "each", RUBY_METHOD_FUNC(hashEach), 0);
226
239
  rb_define_method(rbHash, "to_s", RUBY_METHOD_FUNC(hashToString), 0);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_lovely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pike