fast_filter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35b0ac4af3d4e37606fd35dc4a7a5003f85c03c9
4
+ data.tar.gz: f39cc49a2bcdfc8fa11ee53bee81bc9401bbf8e0
5
+ SHA512:
6
+ metadata.gz: 3d3e077f82d061514d14c040dc3b3d68c734a217a12049c8622710c5d2bedf5854770be8395b8cf733922f338459a557507c61911bd7f968aed8efd42ae1c23b
7
+ data.tar.gz: 392efb557560a0e514a4b50e222a5e6af1fcd9e839c02e3f54343f4611e23fc395bb11a76d48a92180d6d744b91728319dbfeb477b4ef615905341c7b6700e10
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ sudo: required
2
+ language: ruby
3
+ matrix:
4
+ include:
5
+ - rvm: 2.0.0
6
+ - rvm: 2.1.10
7
+ - rvm: 2.2.6
8
+ - rvm: 2.3.3
9
+ - rvm: 2.4.1
10
+ - rvm: ruby-head
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ before_install:
14
+ - sudo apt-get update -qq
15
+ - sudo apt-get install -y build-essential cmake libpopt-dev libbz2-dev libruby ruby-dev
16
+ - gem install bundler -v 1.12.5
17
+ install:
18
+ - bundle install --jobs=3 --retry=3
19
+ - bundle exec rake compile
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at dave@daveallie.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fast_filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dave Allie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Fast Filter
2
+
3
+ [![Build Status](https://travis-ci.org/TandaHQ/fast_filter.svg?branch=master)](https://travis-ci.org/TandaHQ/fast_filter)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fast_filter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fast_filter
20
+
21
+ ## Usage
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/TandaHQ/fast_filter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/extensiontask'
4
+
5
+ Rake::ExtensionTask.new 'fast_filter' do |ext|
6
+ ext.lib_dir = 'lib/fast_filter'
7
+ end
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'fast_filter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+ rake compile
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile('fast_filter/fast_filter')
@@ -0,0 +1,177 @@
1
+ #include <ruby.h>
2
+ #include <stdlib.h>
3
+
4
+ VALUE FastFilter = Qnil;
5
+
6
+ // ============== HELPER FUNCTIONS ==============
7
+
8
+ static int asc_comp_fn(const void *a, const void *b) {
9
+ return ((*(int **)a)[0] - (*(int **)b)[0]);
10
+ }
11
+
12
+ static int bin_lower_bound(long **a, int lo, int hi, long x) {
13
+ if (lo > hi) {
14
+ return lo;
15
+ }
16
+
17
+ int mid = lo + (hi - lo) / 2;
18
+ if (a[mid][0] == x) {
19
+ return bin_lower_bound(a, lo, mid - 1, x);
20
+ } else if (a[mid][0] > x) {
21
+ return bin_lower_bound(a, lo, mid - 1, x);
22
+ } else {
23
+ return bin_lower_bound(a, mid + 1, hi, x);
24
+ }
25
+ }
26
+
27
+ static int bin_upper_bound(long **a, int lo, int hi, long x) {
28
+ if (lo > hi) {
29
+ return lo;
30
+ }
31
+
32
+ int mid = lo + (hi - lo) / 2;
33
+ if (a[mid][0] == x) {
34
+ return bin_upper_bound(a, mid + 1, hi, x);
35
+ } else if (a[mid][0] > x) {
36
+ return bin_upper_bound(a, lo, mid - 1, x);
37
+ } else {
38
+ return bin_upper_bound(a, mid + 1, hi, x);
39
+ }
40
+ }
41
+
42
+ // ============== BUILD AND FREE FUNCTIONS ==============
43
+
44
+ static void build_c_arr(long ***c_arr, VALUE *rb_array, int *len) {
45
+ *len = (int) rb_array_len(*rb_array);
46
+ *c_arr = (long **) malloc(*len * sizeof(long *));
47
+ for (int i = 0; i < *len; i++) {
48
+ (*c_arr)[i] = (long *) malloc(2 * sizeof(long));
49
+ (*c_arr)[i][0] = FIX2LONG(rb_ary_entry(*rb_array, i));
50
+ (*c_arr)[i][1] = i;
51
+ }
52
+
53
+ qsort(*c_arr, *len, sizeof(long), asc_comp_fn);
54
+ }
55
+
56
+ static void free_c_arr(long **c_arr, int len) {
57
+ for (int i = 0; i < len; i++) {
58
+ free(c_arr[i]);
59
+ }
60
+ free(c_arr);
61
+ }
62
+
63
+ static void build_rb_arr(VALUE *r_arr, long **c_arr, int start, int finish, int index_mode) {
64
+ *r_arr = rb_ary_new2(finish - start);
65
+ int c_arr_index = index_mode;
66
+
67
+ for (int ci = start, ri = 0; ci < finish; ci++, ri++) {
68
+ rb_ary_store(*r_arr, ri, LONG2FIX(c_arr[ci][c_arr_index]));
69
+ }
70
+ }
71
+
72
+ // ============== PRIVATE FILTER FUNCTIONS ==============
73
+ // Handles both index and value mode functions, called by
74
+ // public filter functions
75
+
76
+ static void lt_filter_with_mode(VALUE *input_rb_array, VALUE *max_value, int index_mode, VALUE *output_rb_array) {
77
+ int len;
78
+ long **c_arr;
79
+ build_c_arr(&c_arr, input_rb_array, &len);
80
+
81
+ int last = bin_lower_bound(c_arr, 0, len - 1, FIX2LONG(*max_value));
82
+ build_rb_arr(output_rb_array, c_arr, 0, last, index_mode);
83
+ free_c_arr(c_arr, len);
84
+ }
85
+
86
+ static void lte_filter_with_mode(VALUE *input_rb_array, VALUE *max_value, int index_mode, VALUE *output_rb_array) {
87
+ int len;
88
+ long **c_arr;
89
+ build_c_arr(&c_arr, input_rb_array, &len);
90
+
91
+ int last = bin_upper_bound(c_arr, 0, len - 1, FIX2LONG(*max_value));
92
+ build_rb_arr(output_rb_array, c_arr, 0, last, index_mode);
93
+ free_c_arr(c_arr, len);
94
+ }
95
+
96
+ static void gt_filter_with_mode(VALUE *input_rb_array, VALUE *max_value, int index_mode, VALUE *output_rb_array) {
97
+ int len;
98
+ long **c_arr;
99
+ build_c_arr(&c_arr, input_rb_array, &len);
100
+
101
+ int first = bin_upper_bound(c_arr, 0, len - 1, FIX2LONG(*max_value));
102
+ build_rb_arr(output_rb_array, c_arr, first, len, index_mode);
103
+ free_c_arr(c_arr, len);
104
+ }
105
+
106
+ static void gte_filter_with_mode(VALUE *input_rb_array, VALUE *max_value, int index_mode, VALUE *output_rb_array) {
107
+ int len;
108
+ long **c_arr;
109
+ build_c_arr(&c_arr, input_rb_array, &len);
110
+
111
+ int first = bin_lower_bound(c_arr, 0, len - 1, FIX2LONG(*max_value));
112
+ build_rb_arr(output_rb_array, c_arr, first, len, index_mode);
113
+ free_c_arr(c_arr, len);
114
+ }
115
+
116
+ // ============== PUBLIC FILTER FUNCTIONS ==============
117
+ // Calls to the private filter functions
118
+
119
+ static VALUE fast_filter_lt(VALUE self, VALUE rb_array, VALUE max_value) {
120
+ VALUE output_rb_array;
121
+ lt_filter_with_mode(&rb_array, &max_value, 0, &output_rb_array);
122
+ return output_rb_array;
123
+ }
124
+
125
+ static VALUE fast_filter_lte(VALUE self, VALUE rb_array, VALUE max_value) {
126
+ VALUE output_rb_array;
127
+ lte_filter_with_mode(&rb_array, &max_value, 0, &output_rb_array);
128
+ return output_rb_array;
129
+ }
130
+
131
+ static VALUE fast_filter_gt(VALUE self, VALUE rb_array, VALUE max_value) {
132
+ VALUE output_rb_array;
133
+ gt_filter_with_mode(&rb_array, &max_value, 0, &output_rb_array);
134
+ return output_rb_array;
135
+ }
136
+
137
+ static VALUE fast_filter_gte(VALUE self, VALUE rb_array, VALUE max_value) {
138
+ VALUE output_rb_array;
139
+ gte_filter_with_mode(&rb_array, &max_value, 0, &output_rb_array);
140
+ return output_rb_array;
141
+ }
142
+
143
+ static VALUE fast_filter_lt_index(VALUE self, VALUE rb_array, VALUE max_value) {
144
+ VALUE output_rb_array;
145
+ lt_filter_with_mode(&rb_array, &max_value, 1, &output_rb_array);
146
+ return output_rb_array;
147
+ }
148
+
149
+ static VALUE fast_filter_lte_index(VALUE self, VALUE rb_array, VALUE max_value) {
150
+ VALUE output_rb_array;
151
+ lte_filter_with_mode(&rb_array, &max_value, 1, &output_rb_array);
152
+ return output_rb_array;
153
+ }
154
+
155
+ static VALUE fast_filter_gt_index(VALUE self, VALUE rb_array, VALUE max_value) {
156
+ VALUE output_rb_array;
157
+ gt_filter_with_mode(&rb_array, &max_value, 1, &output_rb_array);
158
+ return output_rb_array;
159
+ }
160
+
161
+ static VALUE fast_filter_gte_index(VALUE self, VALUE rb_array, VALUE max_value) {
162
+ VALUE output_rb_array;
163
+ gte_filter_with_mode(&rb_array, &max_value, 1, &output_rb_array);
164
+ return output_rb_array;
165
+ }
166
+
167
+ void Init_fast_filter() {
168
+ FastFilter = rb_define_module("FastFilter");
169
+ rb_define_singleton_method(FastFilter, "filter_lt", fast_filter_lt, 2);
170
+ rb_define_singleton_method(FastFilter, "filter_gt", fast_filter_gt, 2);
171
+ rb_define_singleton_method(FastFilter, "filter_lte", fast_filter_lte, 2);
172
+ rb_define_singleton_method(FastFilter, "filter_gte", fast_filter_gte, 2);
173
+ rb_define_singleton_method(FastFilter, "filter_lt_index", fast_filter_lt_index, 2);
174
+ rb_define_singleton_method(FastFilter, "filter_gt_index", fast_filter_gt_index, 2);
175
+ rb_define_singleton_method(FastFilter, "filter_lte_index", fast_filter_lte_index, 2);
176
+ rb_define_singleton_method(FastFilter, "filter_gte_index", fast_filter_gte_index, 2);
177
+ }
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fast_filter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fast_filter'
8
+ spec.version = FastFilter::VERSION
9
+ spec.authors = ['Dave Allie']
10
+ spec.email = ['dave@tanda.co']
11
+
12
+ spec.summary = 'Native Ruby extension to filter a list quickly.'
13
+ spec.description = 'Native Ruby extension to filter a list quickly.'
14
+ spec.homepage = 'https://github.com/TandaHQ/fast_filter'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ spec.extensions = ['ext/fast_filter/extconf.rb']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.12'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake-compiler', '~> 1.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,3 @@
1
+ module FastFilter
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'fast_filter/version'
2
+ require 'fast_filter/fast_filter'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fast_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Allie
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Native Ruby extension to filter a list quickly.
70
+ email:
71
+ - dave@tanda.co
72
+ executables: []
73
+ extensions:
74
+ - ext/fast_filter/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - ext/fast_filter/extconf.rb
88
+ - ext/fast_filter/fast_filter.c
89
+ - fast_filter.gemspec
90
+ - lib/fast_filter.rb
91
+ - lib/fast_filter/version.rb
92
+ homepage: https://github.com/TandaHQ/fast_filter
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Native Ruby extension to filter a list quickly.
116
+ test_files: []