linked-list 0.0.7 → 0.0.8
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/.travis.yml +1 -0
- data/README.md +32 -2
- data/lib/linked-list/list.rb +11 -6
- data/lib/linked-list/version.rb +1 -1
- data/linked-list.gemspec +1 -0
- data/test/list_test.rb +15 -0
- data/test/test_helper.rb +3 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cf89e62ce52b53b8f7662c7b33b13376ef92ae6
|
4
|
+
data.tar.gz: fa7edc99d8406550a2904270bb19cbcfa5029050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a447dcf94c2b742d113ede66a551956c54c66d0fd58ca9197b4febafc2fab0cd2b25d80e5fa3ebf998782f439a00f85af770b4a264e2ac4ced99f8e0f0b5e5
|
7
|
+
data.tar.gz: 51f4fe4ffacd1db48697fa9eb6cbef9972f8bab3cf2e1f0b14929d99d3dd4cb9532a0d001a2edbbcb8eda8a08d0561cd59e8398e69033fa27ef9c6fdb922ca41
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
[](https://codeclimate.com/github/spectator/linked-list)
|
2
2
|
[](http://travis-ci.org/spectator/linked-list)
|
3
|
+
[](http://badge.fury.io/rb/linked-list)
|
4
|
+
[](https://coveralls.io/r/spectator/linked-list)
|
3
5
|
|
4
6
|
# LinkedList
|
5
7
|
|
@@ -48,15 +50,43 @@ list.each { |e| puts e }
|
|
48
50
|
list.first # head of the list
|
49
51
|
list.last # tail of the list
|
50
52
|
|
53
|
+
list.length
|
54
|
+
list.size # same as `length`
|
55
|
+
|
51
56
|
list.to_a
|
52
57
|
```
|
53
58
|
|
54
|
-
|
59
|
+
Another way to instantiate `List` or `Node` is to use conversion functions.
|
60
|
+
First, include `LinkedList::Conversions` module to your class
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class Foo
|
64
|
+
include LinkedList::Conversions
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Now anywhere in your class you can use the following methods
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Node(object) # will return new `Node` object
|
72
|
+
List(object) # will return new `List` object with one `Node` object
|
73
|
+
List([object, object]) # will return new `List` object with two `Node` objects
|
74
|
+
```
|
75
|
+
|
76
|
+
Please see `LinkedList::List`, `LinkedList::Node`, and
|
77
|
+
`LinkedList::Conversions` for details.
|
55
78
|
|
56
79
|
## TODO
|
57
80
|
|
58
81
|
* Insert / delete in the middle
|
59
|
-
|
82
|
+
|
83
|
+
## Tests
|
84
|
+
|
85
|
+
Run test with
|
86
|
+
|
87
|
+
```shell
|
88
|
+
$ rake
|
89
|
+
```
|
60
90
|
|
61
91
|
## Contributing
|
62
92
|
|
data/lib/linked-list/list.rb
CHANGED
@@ -29,7 +29,7 @@ module LinkedList
|
|
29
29
|
# node:: Any object, including +Node+ objects.
|
30
30
|
#
|
31
31
|
# == Returns:
|
32
|
-
# self of +List+ object.
|
32
|
+
# +self+ of +List+ object.
|
33
33
|
#
|
34
34
|
def push(node)
|
35
35
|
node = Node(node)
|
@@ -49,7 +49,7 @@ module LinkedList
|
|
49
49
|
# node:: Any object, including +Node+ objects.
|
50
50
|
#
|
51
51
|
# == Returns:
|
52
|
-
# self of +List+ object.
|
52
|
+
# +self+ of +List+ object.
|
53
53
|
#
|
54
54
|
def unshift(node)
|
55
55
|
node = Node(node)
|
@@ -62,7 +62,7 @@ module LinkedList
|
|
62
62
|
self
|
63
63
|
end
|
64
64
|
|
65
|
-
# Removes
|
65
|
+
# Removes data from the end of the list.
|
66
66
|
#
|
67
67
|
# == Returns:
|
68
68
|
# Data stored in the node or nil.
|
@@ -84,7 +84,7 @@ module LinkedList
|
|
84
84
|
tail.data
|
85
85
|
end
|
86
86
|
|
87
|
-
# Removes
|
87
|
+
# Removes data from the beginning of the list.
|
88
88
|
#
|
89
89
|
# == Returns:
|
90
90
|
# Data stored in the node or nil.
|
@@ -111,7 +111,7 @@ module LinkedList
|
|
111
111
|
# Reverses list of nodes in place.
|
112
112
|
#
|
113
113
|
# == Returns:
|
114
|
-
# self in reverse order.
|
114
|
+
# +self+ in reverse order.
|
115
115
|
#
|
116
116
|
def reverse!
|
117
117
|
return self unless @head
|
@@ -148,10 +148,14 @@ module LinkedList
|
|
148
148
|
end
|
149
149
|
alias_method :to_ary, :to_a
|
150
150
|
|
151
|
+
def inspect
|
152
|
+
sprintf('#<%s:%#x %s>', self.class, self.__id__, to_a.inspect)
|
153
|
+
end
|
154
|
+
|
151
155
|
# Conversion function, see +Conversions.List+.
|
152
156
|
#
|
153
157
|
# == Returns:
|
154
|
-
# self
|
158
|
+
# +self+
|
155
159
|
#
|
156
160
|
def to_list
|
157
161
|
self
|
@@ -162,6 +166,7 @@ module LinkedList
|
|
162
166
|
def __shift
|
163
167
|
head = @head
|
164
168
|
@head = @head.next
|
169
|
+
head.next = nil
|
165
170
|
head
|
166
171
|
end
|
167
172
|
|
data/lib/linked-list/version.rb
CHANGED
data/linked-list.gemspec
CHANGED
data/test/list_test.rb
CHANGED
@@ -195,6 +195,21 @@ describe LinkedList::List do
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
+
describe '#inspect' do
|
199
|
+
it 'includes class name' do
|
200
|
+
assert_match(/LinkedList::List/, list.inspect)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'includes object id' do
|
204
|
+
assert_match(/#{list.object_id.to_s(16)}/, list.inspect)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'includes node values' do
|
208
|
+
list.push(node_1)
|
209
|
+
assert_match(/foo/, list.inspect)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
198
213
|
describe 'conversion' do
|
199
214
|
it '#to_list returns self' do
|
200
215
|
assert_equal list, list.to_list
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linked-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Velikanau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -64,6 +64,20 @@ dependencies:
|
|
64
64
|
- - <=
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '6.0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: coveralls
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
67
81
|
description: Ruby implementation of Linked List, following some Ruby idioms.
|
68
82
|
email:
|
69
83
|
- yury.velikanau@gmail.com
|
@@ -107,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
121
|
version: '0'
|
108
122
|
requirements: []
|
109
123
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.1.11
|
111
125
|
signing_key:
|
112
126
|
specification_version: 4
|
113
127
|
summary: Ruby implementation of Linked List, following some Ruby idioms.
|