searchractor 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/searchractor.rb +53 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c214730fc323757a97bb2bf3c7760dac861ae0f5f5bcf1aedd8656552a31b9ce
4
+ data.tar.gz: 784c9987987134e1b8c72d9edd5368b77f3b7ee0574194b03d680d6449fbfe64
5
+ SHA512:
6
+ metadata.gz: c01be6db48044ac64ba9e551d373c3e3c95eb8d509f1841b973d474c22418da742747bf8536cbbc51c0e5a9501bd0a6d7bb0a0bc17befab45fe179fa219a5934
7
+ data.tar.gz: 535aa5e228fe6a8407a104228003f88e654a4fe3e998154b9ad0256de11cbaef072c8f26e82fc76653aa08ec07859f5fa5d10a098cae789568800c7850685685
@@ -0,0 +1,53 @@
1
+ # Public: Searchractor's methods.
2
+ module Searchractor
3
+ # Internal: Add Searchractor's behaviour in the including class.
4
+ def self.included(base)
5
+ base.class_eval do
6
+ # Public: Defines an initialized @list as readable in the including class.
7
+ # Same as doing the following in the calling class:
8
+ #
9
+ # class CallingClass
10
+ # attr_reader :list
11
+ #
12
+ # def initialize(list)
13
+ # @list = list
14
+ # end
15
+ # end
16
+ attr_reader :list
17
+
18
+ include InstanceMethods
19
+ end
20
+ end
21
+
22
+ # Internal: Searchractor's instance methods
23
+ module InstanceMethods
24
+ # Public: Search for a given element in an initialized list of sorted elements.
25
+ #
26
+ # Examples
27
+ #
28
+ # searchable = SearchractorClass.new([1, 2, 3, 5, 8])
29
+ #
30
+ # searchable.b_search(5) => 3
31
+ #
32
+ # searchable.b_search(10) => nil
33
+ #
34
+ # Returns either the index of the searched element or nil if the element is not found
35
+ # in the sorted list
36
+ def b_search(element)
37
+ i = 0
38
+ j = list.length - 1
39
+
40
+ while i <= j
41
+ middle = (i + j) / 2
42
+
43
+ return middle if element == list[middle]
44
+
45
+ if element < list[middle]
46
+ j = middle - 1
47
+ else
48
+ i = middle + 1
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: searchractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Henrique Caltram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/searchractor.rb
20
+ homepage:
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubygems_version: 3.4.10
39
+ signing_key:
40
+ specification_version: 4
41
+ summary: A module dedicated to search algorithms studies in Ruby base on interactor's
42
+ architecture
43
+ test_files: []