ZagorskiADT 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a13b07ff338071374da71e2aa74edd00bb82e89b
4
+ data.tar.gz: 135869779c3be728a9c9b6583c2f35b465c35227
5
+ SHA512:
6
+ metadata.gz: 2972188af44c18a2c670353833c476d30a8530b6e587153ac80eb3a3d6a5465a2c1fc203030bf5d67b4d642029e769efe8535fccbc53c37ece366d79754fc1c4
7
+ data.tar.gz: eb34948b602176e0e8f7e524bc3bb461a4c61806d883651c52773706aabc0f331fb18cff76c2832a166a1b803a7834950af7012993db41d92ea87e8eafd3811c
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at benj@zagorski.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ZagorskiADT.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Benjamin
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,46 @@
1
+ # ZagorskiADT
2
+
3
+ Zagorski ADT is a collection of data types that are not included in the standard Ruby library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ZagorskiADT'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ZagorskiADT
20
+
21
+ ## Usage
22
+
23
+ ZagorskiADT::ADT.help will return a list of objects in the collection, as well as a brief description of each type.
24
+
25
+ I also made a "help" function for each Data Type. Type ZagorskiADT::StackQueue.help get a list of functions for the StackQueue, and so on.
26
+
27
+ ### MinMaxStackQueue
28
+
29
+ A MinMaxStackQueue is an Queue object that allows the minimum and maximum values to be found in constant time. It's built by making a Queue out of a Stack, which has that same min/max ability.
30
+
31
+ Since it is made out of Queues and Stacks, those data types are also available. I also provided StackQueue (functionally the same as a Queue), and a MinMaxStack, which is a Stack version of MinMaxStackQueue.
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ZagorskiADT. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ZagorskiADT/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ZagorskiADT"
8
+ spec.version = ZagorskiADT::VERSION
9
+ spec.authors = ["Benjamin Zagorski"]
10
+ spec.email = ["benj@zagorski.com"]
11
+
12
+ spec.summary = %q{Zagorski ADT is a collection of data types that are not included in the standard Ruby library.}
13
+ spec.description = %q{Includes Stack, Queue, StackQueue, MinMaxStack, and MinMaxStackQueue.}
14
+ spec.homepage = "https://github.com/MrMicrowaveOven/ZagorskiADT.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ZagorskiADT"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,6 @@
1
+ require_relative 'ZagorskiADT/AbstractDataTypes/ADT.rb'
2
+ require_relative 'ZagorskiADT/AbstractDataTypes/Stack.rb'
3
+ require_relative 'ZagorskiADT/AbstractDataTypes/Queue.rb'
4
+ require_relative 'ZagorskiADT/AbstractDataTypes/StackQueue.rb'
5
+ require_relative 'ZagorskiADT/AbstractDataTypes/MinMaxStack.rb'
6
+ require_relative 'ZagorskiADT/AbstractDataTypes/MinMaxStackQueue.rb'
Binary file
@@ -0,0 +1,15 @@
1
+ module ZagorskiADT
2
+ class ADT
3
+ def self.help
4
+ puts "Thank you for using Zagorski Advanced Data Types!"
5
+ puts "This package contains the following Array-like Data Types:"
6
+ puts "-Stack, a LIFO array with functions push and pop"
7
+ puts "-Queue, a FIFO array with functions enqueue and dequeue"
8
+ puts "-StackQueue, a Queue that is Stack-based (no real difference)"
9
+ puts "-MinMaxStack, a Stack that can return Min and Max in constant time"
10
+ puts "-MinMaxStackQueue, a Queue that can return Min and Max in constant time"
11
+ puts ""
12
+ puts "Type Stack.help for a list of Stack functions, and so on."
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,62 @@
1
+ # A MinMaxStack is a stack that allows for Min and Max
2
+ # to be found in constant time, unlike a stack or
3
+ # array that generally takes linear time.
4
+ module ZagorskiADT
5
+ class MinMaxStack
6
+ def initialize
7
+ @values = []
8
+ end
9
+
10
+ def self.help
11
+ puts "Here are the functions for MinMaxStack:"
12
+ puts "push(value)"
13
+ puts "pop"
14
+ puts "peek"
15
+ puts "min"
16
+ puts "max"
17
+ puts "length"
18
+ puts "show"
19
+ puts "empty?"
20
+ end
21
+
22
+ def push(val)
23
+ if @values.empty?
24
+ @values.push([val, val, val])
25
+ else
26
+ cur_min = @values.last[1]
27
+ cur_max = @values.last[2]
28
+ @values.push([val, [val, cur_min].min, [val, cur_max].max])
29
+ @values
30
+ end
31
+ end
32
+
33
+ def pop
34
+ @values.pop[0]
35
+ end
36
+
37
+ def peek
38
+ @values.last[0]
39
+ end
40
+
41
+ def min
42
+ @values.empty? ? "Empty" : @values.last[1]
43
+ end
44
+
45
+ def max
46
+ @values.empty? ? "Empty" : @values.last[2]
47
+ end
48
+
49
+ def length
50
+ @values.length
51
+ end
52
+
53
+ def show
54
+ showthis = []
55
+ @values.map{|value| value[0]}
56
+ end
57
+
58
+ def empty?
59
+ @values.empty?
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,69 @@
1
+ # A MinMaxStackQueue is a queue that allows for Min and Max
2
+ # to be found in constant time, unlike a queue or
3
+ # array that generally takes linear time. It does this
4
+ # because it's based on a MinMaxStack, which has this
5
+ # ability.
6
+ module ZagorskiADT
7
+ class MinMaxStackQueue
8
+ def initialize
9
+ @in = MinMaxStack.new
10
+ @out = MinMaxStack.new
11
+ end
12
+
13
+ def self.help
14
+ puts "Here are the functions for MinMaxStackQueue:"
15
+ puts "show"
16
+ puts "enqueue(value)"
17
+ puts "dequeue"
18
+ puts "min"
19
+ puts "max"
20
+ puts "length"
21
+ puts "empty?"
22
+ end
23
+
24
+ def show
25
+ @out.show.reverse + @in.show
26
+ end
27
+
28
+ def enqueue(val)
29
+ @in.push(val)
30
+ end
31
+
32
+ def dequeue
33
+ if @out.empty?
34
+ @in.length.times do
35
+ @out.push(@in.pop)
36
+ end
37
+ end
38
+ @out.pop
39
+ end
40
+
41
+ def min
42
+ if @in.empty?
43
+ @out.min
44
+ elsif @out.empty?
45
+ @in.min
46
+ else
47
+ [@in.min, @out.min].min
48
+ end
49
+ end
50
+
51
+ def max
52
+ if @in.empty?
53
+ @out.max
54
+ elsif @out.empty?
55
+ @in.max
56
+ else
57
+ [@in.max, @out.max].max
58
+ end
59
+ end
60
+
61
+ def length
62
+ @in.length + @out.length
63
+ end
64
+
65
+ def empty?
66
+ @in.empty? && @out.empty?
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,37 @@
1
+ module ZagorskiADT
2
+ class Queue
3
+ def initialize
4
+ @values = Array.new
5
+ end
6
+
7
+ def self.help
8
+ puts "Here are the functions for Queue:"
9
+ puts "show"
10
+ puts "enqueue(value)"
11
+ puts "dequeue"
12
+ puts "length"
13
+ puts "empty?"
14
+ end
15
+
16
+ def show
17
+ @values
18
+ end
19
+
20
+ def enqueue(val)
21
+ @values.push(val)
22
+ @values
23
+ end
24
+
25
+ def dequeue
26
+ @values.shift
27
+ end
28
+
29
+ def length
30
+ @values.length
31
+ end
32
+
33
+ def empty?
34
+ @values.empty?
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module ZagorskiADT
2
+ class Stack
3
+ def initialize
4
+ @values = Array.new
5
+ end
6
+
7
+ def self.help
8
+ puts "Here are the functions for Stack:"
9
+ puts "show"
10
+ puts "push(value)"
11
+ puts "pop"
12
+ puts "length"
13
+ puts "empty?"
14
+ end
15
+
16
+ def show
17
+ @values
18
+ end
19
+
20
+ def push(val)
21
+ @values.push(val)
22
+ @values
23
+ end
24
+
25
+ def pop
26
+ @values.pop
27
+ end
28
+
29
+ def length
30
+ @values.length
31
+ end
32
+
33
+ def empty?
34
+ @values.empty?
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ # A StackQueue works just like a queue, but it's based on
2
+ # a Stack. Functionality-wise, it's exactly the same
3
+ # as a queue. I mainly made it as an exercise leading
4
+ # up to MinMaxStackQueue.
5
+ module ZagorskiADT
6
+ class StackQueue
7
+ def initialize
8
+ @in = Stack.new
9
+ @out = Stack.new
10
+ end
11
+
12
+ def self.help
13
+ puts "Here are the functions for StackQueue:"
14
+ puts "show"
15
+ puts "enqueue(value)"
16
+ puts "dequeue"
17
+ puts "length"
18
+ puts "empty?"
19
+ end
20
+
21
+ def show
22
+ @out.show.reverse + @in.show
23
+ end
24
+
25
+ def enqueue(val)
26
+ @in.push(val)
27
+ end
28
+
29
+ def dequeue
30
+ if @out.empty?
31
+ @in.length.times do
32
+ @out.push(@in.pop)
33
+ end
34
+ end
35
+ @out.pop
36
+ end
37
+
38
+ def length
39
+ @in.length + @out.length
40
+ end
41
+
42
+ def empty?
43
+ @values.empty?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module ZagorskiADT
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "ZagorskiADT/version"
2
+ require_relative "ADT_requireables.rb"
3
+
4
+ module ZagorskiADT
5
+ # Your code goes here...
6
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ZagorskiADT
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Zagorski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-29 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ description: Includes Stack, Queue, StackQueue, MinMaxStack, and MinMaxStackQueue.
56
+ email:
57
+ - benj@zagorski.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".DS_Store"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - ZagorskiADT.gemspec
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/.DS_Store
75
+ - lib/ADT_requireables.rb
76
+ - lib/ZagorskiADT.rb
77
+ - lib/ZagorskiADT/.DS_Store
78
+ - lib/ZagorskiADT/AbstractDataTypes/.DS_Store
79
+ - lib/ZagorskiADT/AbstractDataTypes/ADT.rb
80
+ - lib/ZagorskiADT/AbstractDataTypes/MinMaxStack.rb
81
+ - lib/ZagorskiADT/AbstractDataTypes/MinMaxStackQueue.rb
82
+ - lib/ZagorskiADT/AbstractDataTypes/Queue.rb
83
+ - lib/ZagorskiADT/AbstractDataTypes/Stack.rb
84
+ - lib/ZagorskiADT/AbstractDataTypes/StackQueue.rb
85
+ - lib/ZagorskiADT/version.rb
86
+ homepage: https://github.com/MrMicrowaveOven/ZagorskiADT.git
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ allowed_push_host: https://rubygems.org
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Zagorski ADT is a collection of data types that are not included in the standard
111
+ Ruby library.
112
+ test_files: []