double_linked_list 0.3.1 → 0.3.2
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/README.md +12 -0
- data/lib/double_linked_list/element.rb +16 -7
- data/lib/double_linked_list/version.rb +1 -1
- data/lib/double_linked_list.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feab77ef8adb57a32be8e66ea3ceb36d27b7c48f
|
4
|
+
data.tar.gz: af9e03f9681a2ef41d6465a06e8cca63e9c6f94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a5a1be7aa0965dda4560b0d98b72e690162bce07cad1fbfebb4cd46f15a097504bd41fb754339639e36128bf98ecdeea24b3b855115443c92a186a9844824ba
|
7
|
+
data.tar.gz: 4bbf0deae7c97ad7c8b0e33118159bd0c69222a589de14885d270c54086a13b5436c56757479842e538036a01009ba7a2c0561801351edaab3d1842ab9bd0357
|
data/README.md
CHANGED
@@ -123,6 +123,18 @@ chunked.first.last.datum #=> 2
|
|
123
123
|
chunked.map{|ll| ll.to_a } #=> [[1, 2], [3, 4]]
|
124
124
|
```
|
125
125
|
|
126
|
+
A custom dll can be provided to enhance dll outputs
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
class CustomDLL < DoubleLinkedList; end
|
130
|
+
|
131
|
+
llist = DoubleLinkedList.from_a(1, 2, 3, 4)
|
132
|
+
chunked = llist.chunk_by do |e, current_llist|
|
133
|
+
e.datum == 3 && current_llist.head.datum == 1
|
134
|
+
end
|
135
|
+
chunked.first.is_a? CustomDLL #=> true
|
136
|
+
```
|
137
|
+
|
126
138
|
__select_by:__
|
127
139
|
|
128
140
|
For selecting fractions of the linked list avoiding the elements not returned in between the selected head and last sequences.
|
@@ -1,7 +1,16 @@
|
|
1
1
|
class DoubleLinkedList
|
2
|
-
class Element
|
2
|
+
class Element
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
+
attr_reader :datum
|
6
|
+
attr_accessor :previous, :_next
|
7
|
+
|
8
|
+
def initialize(datum, previous = nil, _next = nil)
|
9
|
+
@datum = datum
|
10
|
+
@previous = previous
|
11
|
+
@_next = _next
|
12
|
+
end
|
13
|
+
|
5
14
|
alias_method :next, :_next
|
6
15
|
alias_method :prev, :previous
|
7
16
|
|
@@ -16,19 +25,19 @@ class DoubleLinkedList
|
|
16
25
|
end
|
17
26
|
|
18
27
|
def count
|
19
|
-
reduce(0) { |p
|
28
|
+
reduce(0) { |p| p + 1 }
|
20
29
|
end
|
21
30
|
alias_method :included_next_count, :count
|
22
31
|
|
23
32
|
def next_count
|
24
33
|
c = 0
|
25
|
-
_each {
|
34
|
+
_each { c += 1 }
|
26
35
|
c
|
27
36
|
end
|
28
37
|
|
29
38
|
def prev_count
|
30
39
|
c = 0
|
31
|
-
_reverse_each {
|
40
|
+
_reverse_each { c += 1 }
|
32
41
|
c
|
33
42
|
end
|
34
43
|
|
@@ -69,12 +78,12 @@ class DoubleLinkedList
|
|
69
78
|
new_last
|
70
79
|
end
|
71
80
|
|
72
|
-
def chunk_by(acc, &block)
|
81
|
+
def chunk_by(acc, custom_dll = DoubleLinkedList, &block)
|
73
82
|
if acc.empty?
|
74
|
-
acc <<
|
83
|
+
acc << custom_dll.from_a(self.datum)
|
75
84
|
else
|
76
85
|
if block.call(self, acc.last, acc)
|
77
|
-
acc <<
|
86
|
+
acc << custom_dll.from_a(self.datum)
|
78
87
|
else
|
79
88
|
acc.last << self.datum
|
80
89
|
end
|
data/lib/double_linked_list.rb
CHANGED
@@ -58,8 +58,8 @@ class DoubleLinkedList
|
|
58
58
|
last.find_previous_by(false, &block)
|
59
59
|
end
|
60
60
|
|
61
|
-
def chunk_by(&block)
|
62
|
-
head.chunk_by([], &block)
|
61
|
+
def chunk_by(custom_dll = DoubleLinkedList, &block)
|
62
|
+
head.chunk_by([], custom_dll, &block)
|
63
63
|
end
|
64
64
|
|
65
65
|
def select_by(&block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: double_linked_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Pañach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|