fast_slice 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 +7 -0
- data/ext/fast_slice/extconf.rb +5 -0
- data/ext/fast_slice/fast_slice.c +62 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 76c299152c97820445861f419759fef22f36cd79
|
4
|
+
data.tar.gz: c1ab82924be78c347b0be49fa06053c8637ef7e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9fdb9db080a35d97169ec64f5b78a97086f5678e01d0262728928bccccb632b5fa4f0bab68a9300200ad0c27c0dc2299aec6556b1710170a6bcb3a002956fdd
|
7
|
+
data.tar.gz: 4cbdd2934cec23b7d1ea3db75ce4a8dc81a4bf00aabbc07ea3efd99f762c6249a172090ea8e32588afa9315f45a1d1cb7854ca982856b55daf5c0c75f36f1346
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
// Effectively a copy and paste from hash.c
|
4
|
+
// but replacing RHASH(hash)->tbl with RHASH_TBL (RHASH is not public)
|
5
|
+
VALUE
|
6
|
+
__rb_hash_has_key(VALUE hash, VALUE key)
|
7
|
+
{
|
8
|
+
if (!RHASH_TBL(hash))
|
9
|
+
return Qfalse;
|
10
|
+
if (st_lookup(RHASH_TBL(hash), key, 0)) {
|
11
|
+
return Qtrue;
|
12
|
+
}
|
13
|
+
return Qfalse;
|
14
|
+
}
|
15
|
+
|
16
|
+
VALUE
|
17
|
+
rb_fast_slice(int argc, VALUE *argv, VALUE self)
|
18
|
+
{
|
19
|
+
VALUE hash, args;
|
20
|
+
rb_scan_args(argc, argv, "1*", &hash, &args);
|
21
|
+
|
22
|
+
if (TYPE(hash) != T_HASH) {
|
23
|
+
rb_raise(rb_eTypeError, "expected a Hash");
|
24
|
+
return Qfalse;
|
25
|
+
}
|
26
|
+
|
27
|
+
if (!RHASH_EMPTY_P(hash)) {
|
28
|
+
VALUE result;
|
29
|
+
result = rb_hash_new();
|
30
|
+
|
31
|
+
int i;
|
32
|
+
for (i=0; i < RARRAY_LEN(args); i++) {
|
33
|
+
VALUE arg;
|
34
|
+
arg = rb_ary_entry(args, i);
|
35
|
+
if(__rb_hash_has_key(hash, arg) == Qtrue) {
|
36
|
+
rb_hash_aset(result, arg, rb_hash_aref(hash, arg));
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
return result;
|
41
|
+
}
|
42
|
+
|
43
|
+
return rb_hash_dup(hash);
|
44
|
+
}
|
45
|
+
|
46
|
+
// Add the `slice` instance method to Hash
|
47
|
+
// TODO figure out how to do this
|
48
|
+
VALUE rb_define_hash_slice(int argc, VALUE *argv, VALUE self)
|
49
|
+
{
|
50
|
+
rb_define_method(rb_cHash, "slice", rb_fast_slice, -1);
|
51
|
+
|
52
|
+
return Qtrue;
|
53
|
+
}
|
54
|
+
|
55
|
+
void Init_fast_slice( void )
|
56
|
+
{
|
57
|
+
VALUE FastSlice = Qnil;
|
58
|
+
FastSlice = rb_define_class_under(rb_cObject, "FastSlice", rb_cObject);
|
59
|
+
|
60
|
+
rb_define_singleton_method(FastSlice, "slice", rb_fast_slice, -1);
|
61
|
+
// rb_define_singleton_method(FastSlice, "define_on_hash", rb_define_hash_slice, 0);
|
62
|
+
}
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_slice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Cook
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions:
|
45
|
+
- ext/fast_slice/extconf.rb
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ext/fast_slice/extconf.rb
|
49
|
+
- ext/fast_slice/fast_slice.c
|
50
|
+
homepage:
|
51
|
+
licenses: []
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.6.13
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Hash#slice implemented in C
|
73
|
+
test_files: []
|