double_linked_list 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: 4bd1278ef39c3b852ef5993fbf7dd68da8cf6165
4
+ data.tar.gz: c150f49470d1bd86df704fca5a484774a2e73f25
5
+ SHA512:
6
+ metadata.gz: 01058c5d4f74e50be1c3e2fb5b569b5bcdf5023686a928161f09e4d9458c5e1ff3f235c5faa4a6fa69e3a52476b5dfa733faf86033b3a72376102ca458a9f365
7
+ data.tar.gz: 7f9bb129aa3efeb4b66e9f48e7ddd8569f5c95f918c4f8af678180a8c40ad116931e926f62443b31109f072865da515ce8079eedce62a959c30356db9a943aa0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in double_linked_list.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # DoubleLinkedList
2
+
3
+ The missing Ruby Linked list
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'double_linked_list'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install double_linked_list
20
+
21
+ ## Usage
22
+
23
+ __navigation:__
24
+ - `next`
25
+ - `previous` or `prev`
26
+
27
+ ```ruby
28
+ llist = DoubleLinkedList.from_a(1, 2, 3)
29
+ llist.datum #=> 1
30
+ llist.next.datum #=> 2
31
+ llist.next.next.datum #=> 3
32
+ llist.next.next.next #=> nil
33
+ llist.next.next.prev.datum #=> 2
34
+ ```
35
+ __last:__
36
+
37
+ ```ruby
38
+ llist = DoubleLinkedList.from_a(1, 2, 3)
39
+ llist.last.datum #=> 3
40
+ ```
41
+
42
+ __find:___
43
+
44
+ ```ruby
45
+ llist = DoubleLinkedList.from_a(1, 2, 3)
46
+ two = llist.find(2)
47
+ two.datum #=> 2
48
+ two.next.datum #=> 3
49
+ llist.find(3).datum #=> 3
50
+ llist.find(9) #=> nil
51
+ ```
52
+
53
+ __find_previous:__
54
+
55
+ ```ruby
56
+ llist = DoubleLinkedList.from_a(1, 2, 3)
57
+ llist.find_previous(3).datum #=> 2
58
+ llist.find_previous(2).datum #=> 1
59
+ llist.find_previous(1) #=> nil
60
+ ```
61
+
62
+ __append:__
63
+
64
+ ```ruby
65
+ llist = DoubleLinkedList.from_a(1, 2, 3)
66
+ llist.append(4)
67
+ llist.last.datum #=> 4
68
+ llist.last.next #=> be_nil
69
+ llist.last.previous.datum #=> 3
70
+ ```
71
+
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false ---` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ 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).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/double_linked_list.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "double_linked_list"
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
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'double_linked_list/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "double_linked_list"
8
+ spec.version = DoubleLinkedList::VERSION
9
+ spec.authors = ["Artur Pañach"]
10
+ spec.email = ["arturictus@gmail.com"]
11
+
12
+ spec.summary = %q{The missing Ruby Double Linked List}
13
+ spec.description = %q{The missing Ruby Double Linked List.}
14
+ spec.homepage = "https://github.com/arturictus/double_linked_list"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.5"
24
+ # spec.add_development_dependency "false ---", "~> "
25
+ end
@@ -0,0 +1,3 @@
1
+ class DoubleLinkedList
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,69 @@
1
+ require "double_linked_list/version"
2
+ require 'forwardable'
3
+ class DoubleLinkedList
4
+ extend Forwardable
5
+ attr_accessor :head, :last
6
+ delegate [:datum, :next] => :head
7
+
8
+ def initialize(datum)
9
+ @head = (datum.is_a?(Element) ? datum : Element.new(datum))
10
+ end
11
+
12
+ class << self
13
+ def from_a(*ary)
14
+ head = Element.new(ary.first)
15
+ last = ary.drop(1).reduce(head) do |cur_last, datum|
16
+ cur_last.append(datum)
17
+ end
18
+ new(head).tap do |o|
19
+ o.last = last
20
+ end
21
+ end
22
+ end
23
+
24
+ def append(datum)
25
+ self.last = last.append(datum)
26
+ end
27
+
28
+
29
+ def find(datum)
30
+ found = nil
31
+ head.each do |elem|
32
+ found = elem if elem.datum == datum
33
+ break if found
34
+ end
35
+ found
36
+ end
37
+
38
+ def find_previous(datum)
39
+ found = nil
40
+ last.reverse_each do |elem|
41
+ found = elem.previous if elem.datum == datum
42
+ break if found
43
+ end
44
+ found
45
+ end
46
+
47
+ class Element < Struct.new(:datum, :previous, :_next)
48
+ include Enumerable
49
+ alias_method :next, :_next
50
+ alias_method :prev, :previous
51
+
52
+ def each(&block)
53
+ block.call self
54
+ _next.each(&block) if _next
55
+ end
56
+
57
+ def each_from_last(&block)
58
+ block.call self
59
+ previous.each_from_last(&block) if previous
60
+ end
61
+ alias_method :reverse_each, :each_from_last
62
+
63
+ def append(datum)
64
+ new_last = Element.new(datum, self, nil)
65
+ self._next = new_last
66
+ new_last
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: double_linked_list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Artur Pañach
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-01 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ description: The missing Ruby Double Linked List.
56
+ email:
57
+ - arturictus@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - double_linked_list.gemspec
71
+ - lib/double_linked_list.rb
72
+ - lib/double_linked_list/version.rb
73
+ homepage: https://github.com/arturictus/double_linked_list
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: The missing Ruby Double Linked List
96
+ test_files: []