nmaximal 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rvmrc +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/nmax +28 -0
- data/bin/setup +8 -0
- data/lib/nmax.rb +28 -0
- data/lib/nmax/version.rb +3 -0
- data/nmax.gemspec +30 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 355a540a87db14385cbd13006c0db981065b498b
|
4
|
+
data.tar.gz: 9a03632cfa5c9fec5dbc52ad06f3345fd3103e1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d15c2892cb118441af0c6d1a146a06d168c5853c4b901033af0d080de92c3158c6220da4286bb641bc235b91340958370a6c7519e6d83aad9e090c78668b54c0
|
7
|
+
data.tar.gz: 6689cb09b46b6ee9de6beefacedb2a6884145c87bb60460c968333a0facc2591d579849d4e301d5ac5ad32229fc060abc05cd2fd510048f4e10a0850dbe8cabd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Aleksei Kosorotov
|
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,30 @@
|
|
1
|
+
[](https://travis-ci.org/kosorotov/nmaximal)
|
2
|
+
|
3
|
+
# Nmax
|
4
|
+
|
5
|
+
Prints 'N' maximal integers from text stream.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nmaximal'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nmaximal
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ cat sample_data_40GB.txt | nmax 10000
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
30
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nmax"
|
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(__FILE__)
|
data/bin/nmax
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'nmax'
|
4
|
+
|
5
|
+
command = Cri::Command.define do
|
6
|
+
name 'nmax'
|
7
|
+
usage 'nmax n'
|
8
|
+
summary 'Returns n maximal integers from stdin'
|
9
|
+
description 'Returns n maximal integers from stdin'
|
10
|
+
|
11
|
+
flag :h, :help, 'show help for this command' do |_value, cmd|
|
12
|
+
puts cmd.help
|
13
|
+
exit 0
|
14
|
+
end
|
15
|
+
|
16
|
+
run do |_opts, args, _cmd|
|
17
|
+
n = args[0].to_i || 0
|
18
|
+
if n > 0
|
19
|
+
nmax = Nmax.get_nmax_from_stream($stdin, n)
|
20
|
+
Nmax.print(nmax)
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
puts "nmax: illegal argument #{args[0]}. Must be an integer"
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
command.run(ARGV)
|
data/bin/setup
ADDED
data/lib/nmax.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nmax/version'
|
2
|
+
require 'cri'
|
3
|
+
|
4
|
+
module Nmax
|
5
|
+
def self.get_nmax_from_stream(stream, n)
|
6
|
+
nmax_numbers = []
|
7
|
+
stream.each_line do |line|
|
8
|
+
current_line_numbers = get_nmax_from_string(line, n)
|
9
|
+
sorted_numbers = (nmax_numbers + current_line_numbers).sort.reverse
|
10
|
+
nmax_numbers = sorted_numbers.size >= n ? sorted_numbers[-n, n] : sorted_numbers
|
11
|
+
end
|
12
|
+
nmax_numbers
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_nmax_from_string(string, n)
|
16
|
+
return [] if string.empty? || n.nil? || n.zero?
|
17
|
+
numbers = string.scan(/\d{1,1000}/).map(&:to_i)
|
18
|
+
sorted_numbers = numbers.sort
|
19
|
+
return sorted_numbers[-n, n] if sorted_numbers.size >= n
|
20
|
+
sorted_numbers
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.print(nmax_numbers)
|
24
|
+
nmax_numbers.each do |number|
|
25
|
+
puts "#{number}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/nmax/version.rb
ADDED
data/nmax.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'nmax/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'nmaximal'
|
9
|
+
spec.version = Nmax::VERSION
|
10
|
+
spec.authors = ['Aleksei Kosorotov']
|
11
|
+
spec.email = ['alkos.network@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'utility to get n maximal numbers from text stream.'
|
14
|
+
spec.description = 'utility to get n maximal numbers from text stream.'
|
15
|
+
spec.homepage = 'https://github.com/kosorotov/nmaximal'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'pry'
|
29
|
+
spec.add_dependency 'cri'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nmaximal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aleksei Kosorotov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-12 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: utility to get n maximal numbers from text stream.
|
84
|
+
email:
|
85
|
+
- alkos.network@gmail.com
|
86
|
+
executables:
|
87
|
+
- console
|
88
|
+
- nmax
|
89
|
+
- setup
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".rvmrc"
|
96
|
+
- ".travis.yml"
|
97
|
+
- Gemfile
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/nmax
|
103
|
+
- bin/setup
|
104
|
+
- lib/nmax.rb
|
105
|
+
- lib/nmax/version.rb
|
106
|
+
- nmax.gemspec
|
107
|
+
homepage: https://github.com/kosorotov/nmaximal
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.6.11
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: utility to get n maximal numbers from text stream.
|
131
|
+
test_files: []
|