fastsort 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +42 -0
- data/Rakefile +4 -0
- data/fastsort.gemspec +39 -0
- data/lib/fastsort/version.rb +5 -0
- data/lib/fastsort.rb +43 -0
- data/main.rb +15 -0
- data/sig/fastsort.rbs +4 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 12702d25d0475df203ee081b543e8a9d715b086fd561b0f5c550cf0848fa4de2
|
4
|
+
data.tar.gz: 8fba45cfd6374245cde79cac4c26f7856a726d5a35081cbbf67e749da589d863
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d45f75d7834d313ea818cb70ba2d0d329257fe91700f30f090daace3d00b8478f15a29276b4ae5794e6777bb292be7f54cdb62cba9b426a5e829ffb71d1e4615
|
7
|
+
data.tar.gz: 83ae98469a47a75ef41c80c0ec14ec24b065c055419f189ff454e3fc843568185499caed3776941251e88173eff46668580e79ef552e9162ba38f6d71e93fe5b
|
data/README.md
ADDED
@@ -0,0 +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
|
+
# Gemfile
|
15
|
+
|
16
|
+
gem 'fastsort'
|
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
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dants0/fastsort.
|
data/Rakefile
ADDED
data/fastsort.gemspec
ADDED
@@ -0,0 +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
|
data/lib/fastsort.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fastsort
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
class Quicksort
|
7
|
+
attr_accessor :array
|
8
|
+
|
9
|
+
def initialize(array)
|
10
|
+
@array = array
|
11
|
+
end
|
12
|
+
|
13
|
+
def sort_array(from_idx = 0, to_idx = array.length - 1)
|
14
|
+
if from_idx < to_idx
|
15
|
+
pivot_idx = partition_and_get_pivot_idx(from_idx, to_idx)
|
16
|
+
sort_array(from_idx, pivot_idx - 1)
|
17
|
+
sort_array(pivot_idx + 1, to_idx)
|
18
|
+
end
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def partition_and_get_pivot_idx(from_idx, to_idx)
|
25
|
+
pivot_value = array[to_idx]
|
26
|
+
pointer_a_idx = pointer_b_idx = from_idx
|
27
|
+
|
28
|
+
while pointer_a_idx < to_idx
|
29
|
+
if array[pointer_a_idx] <= pivot_value
|
30
|
+
swap_values(pointer_a_idx, pointer_b_idx)
|
31
|
+
pointer_b_idx += 1
|
32
|
+
end
|
33
|
+
pointer_a_idx += 1
|
34
|
+
end
|
35
|
+
swap_values(pointer_b_idx, to_idx)
|
36
|
+
pointer_b_idx
|
37
|
+
end
|
38
|
+
|
39
|
+
def swap_values(idx_a, idx_b)
|
40
|
+
array[idx_a], array[idx_b] = array[idx_b], array[idx_a]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/main.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './lib/fastsort'
|
2
|
+
|
3
|
+
arr = [
|
4
|
+
75, 79, 21, 30, 12, 85, 24, 6, 66, 69,
|
5
|
+
92, 98, 18, 57, 40, 71, 92, 14, 1, 79,
|
6
|
+
15, 21, 55, 83, 45, 34, 25, 67, 9, 75,
|
7
|
+
83, 75, 99, 10, 41, 63, 79, 22, 80, 7,
|
8
|
+
38, 87, 31, 93, 60, 53, 39, 59, 67, 97
|
9
|
+
]
|
10
|
+
|
11
|
+
sorter = Fastsort::Quicksort.new(arr)
|
12
|
+
|
13
|
+
sorter.sort_array
|
14
|
+
|
15
|
+
puts "Sorted Array: #{sorter.array}"
|
data/sig/fastsort.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastsort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dants0
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Designed to efficiently organize the elements of an array in a specific
|
14
|
+
order. Sorting is a fundamental operation in computer science and data processing,
|
15
|
+
and the performance of a sorting algorithm is crucial.
|
16
|
+
email:
|
17
|
+
- gui.dg1@hotmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- fastsort.gemspec
|
25
|
+
- lib/fastsort.rb
|
26
|
+
- lib/fastsort/version.rb
|
27
|
+
- main.rb
|
28
|
+
- sig/fastsort.rbs
|
29
|
+
homepage: https://rubygems.org/gems/fastsort
|
30
|
+
licenses: []
|
31
|
+
metadata:
|
32
|
+
allowed_push_host: https://rubygems.org
|
33
|
+
homepage_uri: https://rubygems.org/gems/fastsort
|
34
|
+
source_code_uri: https://github.com/Dants0/fastsort
|
35
|
+
changelog_uri: https://github.com/Dants0/fastsort
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.6.0
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubygems_version: 3.5.3
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: a fast array sorter
|
55
|
+
test_files: []
|