fastsort 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -41
- data/Rakefile +4 -4
- data/fastsort-0.1.0.gem +0 -0
- data/fastsort.gemspec +39 -39
- data/lib/fastsort/version.rb +5 -5
- data/lib/fastsort.rb +41 -0
- data/main.rb +8 -5
- data/sig/fastsort.rbs +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d86a8ff31ddc7b969d1a9b917813710b69f8ad0f2aef649f7faba7afcfd751a
|
4
|
+
data.tar.gz: 3eca0655b2567839b287a05b322b51862409a2a62c5ce2b0f79afcd0df3729d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 380b01d08738b1293bec578ffee49a64e73298d63bcdcd1b35524b1949a85a4dc743e08da69326429cb6591cad71bc48a09510914e0f7b4f2e88d107e67a9af0
|
7
|
+
data.tar.gz: b1ba27cb343db13bc6fd87b7296f7f41d021cc47fac0031213c30256de567ffa7f512dd2a8d4a9955adfb0e761e66031ddad44ab288845158b82b40909061485
|
data/README.md
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
# Fastsort
|
2
|
-
|
3
|
-
Fastsort is a Ruby gem that provides an efficient sorting algorithm for arrays.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
$ gem install 'fastsort'
|
11
|
-
$ bundle install
|
12
|
-
```
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
## Example usage
|
19
|
-
|
20
|
-
```bash
|
21
|
-
require 'fastsort'
|
22
|
-
|
23
|
-
arr = [
|
24
|
-
75, 79, 21, 30, 12, 85, 24, 6, 66, 69,
|
25
|
-
92, 98, 18, 57, 40, 71, 92, 14, 1, 79,
|
26
|
-
15, 21, 55, 83, 45, 34, 25, 67, 9, 75,
|
27
|
-
83, 75, 99, 10, 41, 63, 79, 22, 80, 7,
|
28
|
-
38, 87, 31, 93, 60, 53, 39, 59, 67, 97
|
29
|
-
]
|
30
|
-
|
31
|
-
sorter = Fastsort::Quicksort.new(arr)
|
32
|
-
|
33
|
-
sorter.sort_array
|
34
|
-
|
35
|
-
puts "Sorted Array: #{sorter.array}"
|
36
|
-
```
|
37
|
-
|
38
|
-
## Development
|
39
|
-
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
|
40
|
-
|
41
|
-
## Contributing
|
1
|
+
# Fastsort
|
2
|
+
|
3
|
+
Fastsort is a Ruby gem that provides an efficient sorting algorithm for arrays.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
$ gem install 'fastsort'
|
11
|
+
$ bundle install
|
12
|
+
```
|
13
|
+
|
14
|
+
## TODO
|
15
|
+
Add more efficient sorting algorithms for arrays and arrays of objects...
|
16
|
+
|
17
|
+
|
18
|
+
## Example usage
|
19
|
+
|
20
|
+
```bash
|
21
|
+
require 'fastsort'
|
22
|
+
|
23
|
+
arr = [
|
24
|
+
75, 79, 21, 30, 12, 85, 24, 6, 66, 69,
|
25
|
+
92, 98, 18, 57, 40, 71, 92, 14, 1, 79,
|
26
|
+
15, 21, 55, 83, 45, 34, 25, 67, 9, 75,
|
27
|
+
83, 75, 99, 10, 41, 63, 79, 22, 80, 7,
|
28
|
+
38, 87, 31, 93, 60, 53, 39, 59, 67, 97
|
29
|
+
]
|
30
|
+
|
31
|
+
sorter = Fastsort::Quicksort.new(arr)
|
32
|
+
|
33
|
+
sorter.sort_array
|
34
|
+
|
35
|
+
puts "Sorted Array: #{sorter.array}"
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
## Contributing
|
42
42
|
Bug reports and pull requests are welcome on GitHub at https://github.com/dants0/fastsort.
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
task default: %i[]
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
task default: %i[]
|
data/fastsort-0.1.0.gem
ADDED
Binary file
|
data/fastsort.gemspec
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/fastsort/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "fastsort"
|
7
|
-
spec.version = Fastsort::VERSION
|
8
|
-
spec.authors = ["Dants0"]
|
9
|
-
spec.email = ["gui.dg1@hotmail.com"]
|
10
|
-
|
11
|
-
spec.summary = "a fast array sorter"
|
12
|
-
spec.description = "Designed to efficiently organize the elements of an array in a specific order. Sorting is a fundamental operation in computer science and data processing, and the performance of a sorting algorithm is crucial."
|
13
|
-
spec.homepage = "https://rubygems.org/gems/fastsort"
|
14
|
-
spec.required_ruby_version = ">= 2.6.0"
|
15
|
-
|
16
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
-
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/Dants0/fastsort"
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/Dants0/fastsort"
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(__dir__) do
|
25
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
(File.expand_path(f) == __FILE__) ||
|
27
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
spec.bindir = "exe"
|
31
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ["lib"]
|
33
|
-
|
34
|
-
# Uncomment to register a new dependency of your gem
|
35
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
-
|
37
|
-
# For more information and examples about making a new gem, check out our
|
38
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/fastsort/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fastsort"
|
7
|
+
spec.version = Fastsort::VERSION
|
8
|
+
spec.authors = ["Dants0"]
|
9
|
+
spec.email = ["gui.dg1@hotmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "a fast array sorter"
|
12
|
+
spec.description = "Designed to efficiently organize the elements of an array in a specific order. Sorting is a fundamental operation in computer science and data processing, and the performance of a sorting algorithm is crucial."
|
13
|
+
spec.homepage = "https://rubygems.org/gems/fastsort"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/Dants0/fastsort"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/Dants0/fastsort"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
data/lib/fastsort/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Fastsort
|
4
|
-
VERSION = "0.1.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fastsort
|
4
|
+
VERSION = "0.1.1"
|
5
|
+
end
|
data/lib/fastsort.rb
CHANGED
@@ -40,4 +40,45 @@ module Fastsort
|
|
40
40
|
array[idx_a], array[idx_b] = array[idx_b], array[idx_a]
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
class Mergesort
|
45
|
+
attr_accessor :array
|
46
|
+
|
47
|
+
def initialize(array)
|
48
|
+
@array = array
|
49
|
+
end
|
50
|
+
|
51
|
+
def sort_array
|
52
|
+
return array if array.length <= 1
|
53
|
+
|
54
|
+
middle = array.length / 2
|
55
|
+
left_half = array[0...middle]
|
56
|
+
right_half = array[middle..-1]
|
57
|
+
|
58
|
+
left_half = Mergesort.new(left_half).sort_array
|
59
|
+
right_half = Mergesort.new(right_half).sort_array
|
60
|
+
|
61
|
+
merge(left_half, right_half)
|
62
|
+
end
|
63
|
+
|
64
|
+
def merge(left, right)
|
65
|
+
result = []
|
66
|
+
left_idx = right_idx = 0
|
67
|
+
|
68
|
+
while left_idx < left.length && right_idx < right.length
|
69
|
+
if left[left_idx] < right[right_idx]
|
70
|
+
result << left[left_idx]
|
71
|
+
left_idx += 1
|
72
|
+
else
|
73
|
+
result << right[right_idx]
|
74
|
+
right_idx += 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
result.concat(left[left_idx..-1]) if left_idx < left.length
|
79
|
+
result.concat(right[right_idx..-1]) if right_idx < right.length
|
80
|
+
|
81
|
+
result
|
82
|
+
end
|
83
|
+
end
|
43
84
|
end
|
data/main.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "./lib/fastsort"
|
2
2
|
|
3
3
|
arr = [
|
4
4
|
75, 79, 21, 30, 12, 85, 24, 6, 66, 69,
|
5
5
|
92, 98, 18, 57, 40, 71, 92, 14, 1, 79,
|
6
6
|
15, 21, 55, 83, 45, 34, 25, 67, 9, 75,
|
7
7
|
83, 75, 99, 10, 41, 63, 79, 22, 80, 7,
|
8
|
-
38, 87, 31, 93, 60, 53, 39, 59, 67, 97
|
8
|
+
38, 87, 31, 93, 60, 53, 39, 59, 67, 97,
|
9
9
|
]
|
10
10
|
|
11
|
-
|
11
|
+
sorter_001 = Fastsort::Quicksort.new(arr)
|
12
|
+
sorter_002 = Fastsort::Mergesort.new(arr)
|
12
13
|
|
13
|
-
|
14
|
+
sorter_001.sort_array
|
15
|
+
sorter_002.sort_array
|
14
16
|
|
15
|
-
puts "Sorted Array: #{
|
17
|
+
# puts "Sorted Array: #{sorter_001.array}"
|
18
|
+
puts "Sorted Array: #{sorter_002.array}"
|
data/sig/fastsort.rbs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Fastsort
|
2
|
-
VERSION: String
|
3
|
-
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
4
|
-
end
|
1
|
+
module Fastsort
|
2
|
+
VERSION: String
|
3
|
+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
4
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastsort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dants0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Designed to efficiently organize the elements of an array in a specific
|
14
14
|
order. Sorting is a fundamental operation in computer science and data processing,
|
@@ -21,6 +21,7 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
+
- fastsort-0.1.0.gem
|
24
25
|
- fastsort.gemspec
|
25
26
|
- lib/fastsort.rb
|
26
27
|
- lib/fastsort/version.rb
|