doubly_linkedlist 0.2.1 → 0.3.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +23 -6
- data/doubly_linkedlist.gemspec +11 -2
- data/lib/doubly_linkedlist/list.rb +25 -15
- data/lib/doubly_linkedlist/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e865f7e649d417e521eee62161eefad156b78713dfe2a980132165664929c45
|
4
|
+
data.tar.gz: 21e9e0fd3239a3abb074d5ddd25fd66449cf57dcd1c713959762ac3f43456369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e004e644641a8c7f653bb910a897c4db89f8a78442b5a0f904c2fa5cc000d8e751a07aedcea003cd3ff76e007c59f68b614c52b660e51bca4ed6a31df66b477
|
7
|
+
data.tar.gz: c4126333e9b1ed4540137eb9e95ce2c96ae6a9417386a0e4399d9f1e2862c286ac24dc312f54584fc7906ffbd9841c79d5866ad3ad5f1eb5cd47d18626329292
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DoublyLinkedlist
|
2
2
|
|
3
|
-
A Ruby implementation of the famous Doubly Linkedlist data structure following ruby idioms. A Linkedlist is efficient in many specific cases than other data structures such as Array.
|
3
|
+
A Ruby implementation of the famous Doubly Linkedlist data structure with support to the Enumerable methods such as `each`, `to_a`, `map`, etc. following ruby idioms. Supports Queue operations as well as Stack operations. A Linkedlist is efficient in many specific cases than other data structures such as Array.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -124,7 +124,7 @@ list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
|
124
124
|
list.count # => 5
|
125
125
|
|
126
126
|
list.delete_at(1) # => "Some object"
|
127
|
-
list # => [1, 40, 100, 40]
|
127
|
+
list # => <DoublyLinkedlist::List: [1, 40, 100, 40]>
|
128
128
|
list.count # => 4
|
129
129
|
|
130
130
|
list.delete_at(6) # => nil
|
@@ -138,6 +138,23 @@ Converts the list object into an array object with all the node values.
|
|
138
138
|
```ruby
|
139
139
|
list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
140
140
|
|
141
|
+
```
|
142
|
+
#### Enumerable Methods Support
|
143
|
+
|
144
|
+
Supports the methods available in the Enumerable module such as `to_a`, `each`, `each_with_object`, `any?`, etc. For more information on available methods refer documentation for Ruby Enumerable Module.
|
145
|
+
|
146
|
+
Some examples below,
|
147
|
+
```ruby
|
148
|
+
list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
149
|
+
|
150
|
+
list.each { |obj| puts obj }
|
151
|
+
# 1
|
152
|
+
# Some object
|
153
|
+
# 40
|
154
|
+
# 100
|
155
|
+
# 40
|
156
|
+
# => nil
|
157
|
+
|
141
158
|
arr = list.to_a
|
142
159
|
arr.class # => Array
|
143
160
|
arr # => [1, "Some object", 40, 100, 40]
|
@@ -154,7 +171,7 @@ increments and returns the count of nodes.
|
|
154
171
|
list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
155
172
|
|
156
173
|
list.push(25) # => 6
|
157
|
-
list # => [25, 1, "Some object", 40, 100, 40]
|
174
|
+
list # => <DoublyLinkedlist::List: [25, 1, "Some object", 40, 100, 40]>
|
158
175
|
```
|
159
176
|
|
160
177
|
##### #pop
|
@@ -166,7 +183,7 @@ list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
|
166
183
|
|
167
184
|
list.pop # => 1
|
168
185
|
list.count # => 4
|
169
|
-
list # => ["Some object", 40, 100, 40]
|
186
|
+
list # => <DoublyLinkedlist::List: ["Some object", 40, 100, 40]>
|
170
187
|
```
|
171
188
|
|
172
189
|
#### Queue Operations
|
@@ -180,7 +197,7 @@ increments and returns the count of nodes.
|
|
180
197
|
list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
181
198
|
|
182
199
|
list.enqueue(25) # => 6
|
183
|
-
list # => [1, "Some object", 40, 100, 40, 25]
|
200
|
+
list # => <DoublyLinkedlist::List: [1, "Some object", 40, 100, 40, 25]>
|
184
201
|
```
|
185
202
|
|
186
203
|
##### #deque
|
@@ -192,7 +209,7 @@ list = DoublyLinkedlist::List.new [1, "Some object", 40, 100, 40]
|
|
192
209
|
|
193
210
|
list.deque # => 1
|
194
211
|
list.count # => 4
|
195
|
-
list # => ["Some object", 40, 100, 40]
|
212
|
+
list # => <DoublyLinkedlist::List: ["Some object", 40, 100, 40]>
|
196
213
|
```
|
197
214
|
|
198
215
|
Refer [documentation](https://rubydoc.info/gems/doubly_linkedlist/DoublyLinkedlist/) for more information.
|
data/doubly_linkedlist.gemspec
CHANGED
@@ -6,8 +6,17 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Anshab M K"]
|
7
7
|
spec.email = ["anshabmk@live.com"]
|
8
8
|
|
9
|
-
spec.summary = %q{
|
10
|
-
|
9
|
+
spec.summary = %q{
|
10
|
+
An iterable, minimal Ruby implementation of a Doubly Linkedlist data structure.
|
11
|
+
}
|
12
|
+
|
13
|
+
spec.description = %q{
|
14
|
+
A Ruby implementation of the famous Doubly Linkedlist data structure with support
|
15
|
+
to the Enumerable methods such as `each`, `to_a`, `map`, etc. following ruby idioms.
|
16
|
+
Supports Queue operations as well as Stack operations. A Linkedlist is efficient in
|
17
|
+
many specific cases(eg:- Queue operations) than other data structures such as Array.
|
18
|
+
}
|
19
|
+
|
11
20
|
spec.homepage = "https://github.com/anshabmk/doubly_linkedlist/blob/master/README.md"
|
12
21
|
spec.license = "MIT"
|
13
22
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
@@ -5,6 +5,8 @@ require 'doubly_linkedlist/node'
|
|
5
5
|
module DoublyLinkedlist
|
6
6
|
# Creates list with nodes
|
7
7
|
class List
|
8
|
+
include Enumerable
|
9
|
+
|
8
10
|
# @return [Integer] the number of nodes in the list.
|
9
11
|
attr_reader :count
|
10
12
|
|
@@ -130,29 +132,37 @@ module DoublyLinkedlist
|
|
130
132
|
|
131
133
|
alias :deque :pop
|
132
134
|
|
133
|
-
# Converts the list
|
135
|
+
# Converts the list representation into a string.
|
134
136
|
#
|
135
|
-
# @return [
|
136
|
-
def
|
137
|
-
|
138
|
-
arr = []
|
137
|
+
# @return [String] the string object after converting the representation of list into string.
|
138
|
+
def to_s
|
139
|
+
str = "<#{self.class}: ["
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
141
|
+
each_with_index do |v, i|
|
142
|
+
str += v.to_s
|
143
|
+
str += ', ' unless i == (count - 1)
|
143
144
|
end
|
144
145
|
|
145
|
-
|
146
|
+
str + ']>'
|
146
147
|
end
|
147
148
|
|
148
|
-
|
149
|
+
alias :inspect :to_s
|
150
|
+
|
151
|
+
# Support for Enumerable methods.
|
149
152
|
#
|
150
|
-
# @
|
151
|
-
|
152
|
-
|
153
|
-
|
153
|
+
# @params [Block] the block to be yielded on each item
|
154
|
+
# @return [Enumerator] the enumerator when no block is given
|
155
|
+
# @return [DoublyLinkedlist] the object after yielding block on every item
|
156
|
+
def each
|
157
|
+
return enum_for(:each) unless block_given?
|
154
158
|
|
155
|
-
|
159
|
+
item = @head
|
160
|
+
|
161
|
+
while item do
|
162
|
+
yield item.value
|
163
|
+
item = item.next
|
164
|
+
end
|
165
|
+
end
|
156
166
|
|
157
167
|
private
|
158
168
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doubly_linkedlist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anshab M K
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,7 +24,11 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
|
-
description:
|
27
|
+
description: "\n A Ruby implementation of the famous Doubly Linkedlist data structure
|
28
|
+
with support \n to the Enumerable methods such as `each`, `to_a`, `map`, etc.
|
29
|
+
following ruby idioms. \n Supports Queue operations as well as Stack operations.
|
30
|
+
A Linkedlist is efficient in \n many specific cases(eg:- Queue operations) than
|
31
|
+
other data structures such as Array.\n "
|
28
32
|
email:
|
29
33
|
- anshabmk@live.com
|
30
34
|
executables: []
|
@@ -73,5 +77,5 @@ requirements: []
|
|
73
77
|
rubygems_version: 3.1.2
|
74
78
|
signing_key:
|
75
79
|
specification_version: 4
|
76
|
-
summary: Ruby implementation of a Doubly Linkedlist data structure.
|
80
|
+
summary: An iterable, minimal Ruby implementation of a Doubly Linkedlist data structure.
|
77
81
|
test_files: []
|