binary_search 0.2.0 → 0.3.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.
- data/ext/binary_search.c +35 -0
 - data/ext/extconf.rb +1 -1
 - data/lib/binary_search/native.rb +1 -1
 - metadata +23 -38
 
    
        data/ext/binary_search.c
    ADDED
    
    | 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include <ruby.h>
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #ifndef RARRAY_PTR
         
     | 
| 
      
 4 
     | 
    
         
            +
            #define RARRAY_PTR(ary) RARRAY(ary)->ptr
         
     | 
| 
      
 5 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 6 
     | 
    
         
            +
            #ifndef RARRAY_LEN
         
     | 
| 
      
 7 
     | 
    
         
            +
            #define RARRAY_LEN(ary) RARRAY(ary)->len
         
     | 
| 
      
 8 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            static ID id_cmp;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            static VALUE rb_array_binary_index(VALUE self, VALUE value) {
         
     | 
| 
      
 13 
     | 
    
         
            +
              int lower = 0;
         
     | 
| 
      
 14 
     | 
    
         
            +
              int upper = RARRAY_LEN(self) - 1;
         
     | 
| 
      
 15 
     | 
    
         
            +
              int i, comp;
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              while(lower <= upper) {
         
     | 
| 
      
 18 
     | 
    
         
            +
                i = lower + (upper - lower) / 2;
         
     | 
| 
      
 19 
     | 
    
         
            +
                comp = FIX2INT(rb_funcall(value, id_cmp, 1, RARRAY_PTR(self)[i]));
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                if(comp == 0) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                  return LONG2NUM(i);
         
     | 
| 
      
 23 
     | 
    
         
            +
                } else if(comp == 1) {
         
     | 
| 
      
 24 
     | 
    
         
            +
                  lower = i + 1;
         
     | 
| 
      
 25 
     | 
    
         
            +
                } else {
         
     | 
| 
      
 26 
     | 
    
         
            +
                  upper = i - 1;
         
     | 
| 
      
 27 
     | 
    
         
            +
                };
         
     | 
| 
      
 28 
     | 
    
         
            +
              }
         
     | 
| 
      
 29 
     | 
    
         
            +
              return Qnil;
         
     | 
| 
      
 30 
     | 
    
         
            +
            }
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            void Init_binary_search_ext() {
         
     | 
| 
      
 33 
     | 
    
         
            +
              id_cmp = rb_intern("<=>");
         
     | 
| 
      
 34 
     | 
    
         
            +
              rb_define_method(rb_cArray, "binary_index", rb_array_binary_index, 1);
         
     | 
| 
      
 35 
     | 
    
         
            +
            }
         
     | 
    
        data/ext/extconf.rb
    CHANGED
    
    | 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mkmf'
         
     | 
| 
       2 
     | 
    
         
            -
            create_makefile ' 
     | 
| 
      
 2 
     | 
    
         
            +
            create_makefile 'binary_search_ext'
         
     | 
    
        data/lib/binary_search/native.rb
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
      
 1 
     | 
    
         
            +
            require 'binary_search_ext'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,68 +1,53 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            --- !ruby/object:Gem::Specification 
     | 
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: binary_search
         
     | 
| 
       3 
     | 
    
         
            -
            version: !ruby/object:Gem::Version 
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
              - 0
         
     | 
| 
       7 
     | 
    
         
            -
              - 2
         
     | 
| 
       8 
     | 
    
         
            -
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              version: 0.2.0
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
       10 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
     | 
    
         
            -
            authors: 
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
       12 
8 
     | 
    
         
             
            - Tyler McMullen
         
     | 
| 
       13 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       14 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            date: 2008-12-29 00:00:00 -08:00
         
     | 
| 
       18 
     | 
    
         
            -
            default_executable: 
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2008-12-29 00:00:00.000000000 Z
         
     | 
| 
       19 
13 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
14 
     | 
    
         
             
            description: Binary search and index methods for Ruby Arrays.
         
     | 
| 
       22 
15 
     | 
    
         
             
            email: tbmcmullen@gmail.com
         
     | 
| 
       23 
16 
     | 
    
         
             
            executables: []
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            extensions: 
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions:
         
     | 
| 
       26 
18 
     | 
    
         
             
            - ext/extconf.rb
         
     | 
| 
       27 
19 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
            files: 
         
     | 
| 
      
 20 
     | 
    
         
            +
            files:
         
     | 
| 
       30 
21 
     | 
    
         
             
            - README.textile
         
     | 
| 
       31 
22 
     | 
    
         
             
            - VERSION.yml
         
     | 
| 
       32 
23 
     | 
    
         
             
            - ext/extconf.rb
         
     | 
| 
      
 24 
     | 
    
         
            +
            - ext/binary_search.c
         
     | 
| 
       33 
25 
     | 
    
         
             
            - lib/binary_search/native.rb
         
     | 
| 
       34 
26 
     | 
    
         
             
            - lib/binary_search/pure.rb
         
     | 
| 
       35 
27 
     | 
    
         
             
            - lib/binary_search.rb
         
     | 
| 
       36 
     | 
    
         
            -
            has_rdoc: true
         
     | 
| 
       37 
28 
     | 
    
         
             
            homepage: http://github.com/tyler/binary_search
         
     | 
| 
       38 
29 
     | 
    
         
             
            licenses: []
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
30 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       41 
31 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
            require_paths: 
         
     | 
| 
      
 32 
     | 
    
         
            +
            require_paths:
         
     | 
| 
       44 
33 
     | 
    
         
             
            - lib
         
     | 
| 
       45 
34 
     | 
    
         
             
            - ext
         
     | 
| 
       46 
     | 
    
         
            -
            required_ruby_version: !ruby/object:Gem::Requirement 
     | 
| 
       47 
     | 
    
         
            -
               
     | 
| 
       48 
     | 
    
         
            -
               
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                   
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
              requirements: 
     | 
| 
       55 
     | 
    
         
            -
              - -  
     | 
| 
       56 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       57 
     | 
    
         
            -
                   
     | 
| 
       58 
     | 
    
         
            -
                  - 0
         
     | 
| 
       59 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
      
 35 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 36 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 37 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 39 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 42 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 44 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 45 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 46 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
       60 
47 
     | 
    
         
             
            requirements: []
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
48 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       63 
     | 
    
         
            -
            rubygems_version: 1. 
     | 
| 
      
 49 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
       64 
50 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       65 
51 
     | 
    
         
             
            specification_version: 2
         
     | 
| 
       66 
52 
     | 
    
         
             
            summary: Binary search and index methods for Ruby Arrays.
         
     | 
| 
       67 
53 
     | 
    
         
             
            test_files: []
         
     | 
| 
       68 
     | 
    
         
            -
             
     |