rb_lovely 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rb_lovely/sorted_hash.cpp +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5aaffcb2aeeca73c556c9a29b3c6800bd03994e
|
4
|
+
data.tar.gz: c6b933b7ded2d336418e50423c5c30df9cd2db0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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);
|