rb_lovely 0.6.1 → 0.6.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/.yardopts +1 -0
- data/yard.rb +197 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc6858428c1b20ccab46f7c4b561e3531853ad7a
|
4
|
+
data.tar.gz: 2de01f2967e14c0149184a12b7191969b07a0821
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23cdc3ee67aeab749cb6bc0dadb1864f4b860511d9ed511abcf7854c601f6858c34be1a8cb16b8e0f3e2ee4481dd6740188978fb1a9cf54744508bb8027b98b9
|
7
|
+
data.tar.gz: 1e7d603e62caa5c32773bdcda4366a928e3e16ab47fb3392a8173904daabb7a7407093c307db312578962ef51c9bde2da57b6b0fe1fc043e0323c9594096028c
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
yard.rb
|
data/yard.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# This file is used to build the yard documentation only as yard cannot currently
|
2
|
+
# generate ruby documentation from C++ files.
|
3
|
+
# The source code for this extension can be found in ext/rb_lovely.
|
4
|
+
|
5
|
+
# Contains sorted container implementations.
|
6
|
+
# @author nuisanceofcats
|
7
|
+
module RbLovely
|
8
|
+
|
9
|
+
# Implement a sorted set with no duplicates where values are compared and sorted using the <=> operator on each member.
|
10
|
+
# @note
|
11
|
+
# A SortedSet should not be modified during iteration.
|
12
|
+
#
|
13
|
+
# Some methods come from the {http://www.ruby-doc.org/core-2.1.2/Enumerable.html Enumerable} module. If you do not find the method you are looking for in this documentation then please look there.
|
14
|
+
#
|
15
|
+
# @author nuisanceofcats
|
16
|
+
# @example
|
17
|
+
# class Person < Struct.new(:name, :age)
|
18
|
+
# def <=> other
|
19
|
+
# return age - other.age
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# empty_set = RbLovely::SortedSet.new
|
24
|
+
#
|
25
|
+
# set = RbLovely::SortedSet.new [ Person.new('Nyamuk', 2), Person.new('Cold Rain', 9999) ]
|
26
|
+
# set.add Person.new('Beards', 15)
|
27
|
+
# set << Person.new('Anna', 12)
|
28
|
+
# set.add Person.new('Moust', 18)
|
29
|
+
# expect(set.first.name).to equal 'Nyamuk'
|
30
|
+
# expect(set.last.name).to equal 'Cold Rain'
|
31
|
+
# expect(set.length).to equal 5
|
32
|
+
#
|
33
|
+
# # Gond isn't added because <=> returns 0 for him and Anna
|
34
|
+
# set.add Person.new('Gond', 12)
|
35
|
+
# expect(set.length).to equal 5
|
36
|
+
class SortedSet
|
37
|
+
include Enumerable
|
38
|
+
|
39
|
+
# @param content [Array] An array of values to insert into the set.
|
40
|
+
def initialize content = [] ; end
|
41
|
+
|
42
|
+
# Deletes first member equivalent to value.
|
43
|
+
# @complexity O(log(n)).
|
44
|
+
# @return The value that was removed or nil if no value was removed.
|
45
|
+
# @param value Value to remove (each member is compared to value using the <=> method).
|
46
|
+
# @example
|
47
|
+
# set = RbLovely::SortedSet.new [ 1, 5, 3 ]
|
48
|
+
# set.delete 3
|
49
|
+
# expect(set.to_a).to eql [1, 5]
|
50
|
+
def delete value ; end
|
51
|
+
|
52
|
+
# Access the first element in the set.
|
53
|
+
# @complexity O(c).
|
54
|
+
# @return The first value according to the <=> method defined on each member.
|
55
|
+
# @example
|
56
|
+
# set = RbLovely::SortedSet.new [4, 0, 2]
|
57
|
+
# expect(set.first).to equal 0
|
58
|
+
def first ; end
|
59
|
+
|
60
|
+
# Remove the first element from the set.
|
61
|
+
# @complexity O(c).
|
62
|
+
# @return The first value according to the <=> method defined on each member or nil if the set is empty.
|
63
|
+
# @example
|
64
|
+
# set = RbLovely::SortedSet.new [4, 0, 2]
|
65
|
+
# expect(set.shift).to equal 0
|
66
|
+
def shift ; end
|
67
|
+
|
68
|
+
# Access the last element in the set.
|
69
|
+
# @complexity O(c).
|
70
|
+
# @return The last value according to the <=> method defined on each member.
|
71
|
+
# @example
|
72
|
+
# set = RbLovely::SortedSet.new [4, 0, 2]
|
73
|
+
# expect(set.last).to equal 4
|
74
|
+
def last ; end
|
75
|
+
|
76
|
+
# Remove the last element from the set.
|
77
|
+
# @complexity O(c).
|
78
|
+
# @return The last value according to the <=> method defined on each member or nil if the set is empty.
|
79
|
+
# @example
|
80
|
+
# set = RbLovely::SortedSet.new [4, 0, 2]
|
81
|
+
# expect(set.pop).to equal 4
|
82
|
+
def pop ; end
|
83
|
+
|
84
|
+
# Remove elements from the set match a given predicate.
|
85
|
+
# @complexity O(n)
|
86
|
+
# @param predicate Items are removed from the set for which predicate returns true.
|
87
|
+
# @example
|
88
|
+
# set = RbLovely::SortedSet.new [0, 1, 2, 3]
|
89
|
+
# set.reject!(&:odd?)
|
90
|
+
# expect(set.to_a).to eql([0, 2])
|
91
|
+
def reject!(&predicate) ; end
|
92
|
+
|
93
|
+
# Remove the first element from the set that matches the given predicate.
|
94
|
+
# @complexity O(log n)
|
95
|
+
# @param predicate The first item is removed which predicate returns true for.
|
96
|
+
# @example
|
97
|
+
# set = RbLovely::SortedSet.new [0, 1, 2, 3]
|
98
|
+
# set.reject!(&:odd?)
|
99
|
+
# expect(set.to_a).to eql([0, 2, 3])
|
100
|
+
def reject_first!(&predicate) ; end
|
101
|
+
|
102
|
+
# Remove elements from the set that do not match a given predicate.
|
103
|
+
# @complexity O(n)
|
104
|
+
# @param predicate Items are removed from the set for which predicate does not return true.
|
105
|
+
# @example
|
106
|
+
# set = RbLovely::SortedSet.new [0, 1, 2, 3]
|
107
|
+
# set.select!(&:odd?)
|
108
|
+
# expect(set.to_a).to eql([1, 3])
|
109
|
+
def select!(&predicate) ; end
|
110
|
+
|
111
|
+
# Calls block once with each value in the set.
|
112
|
+
# @complexity O(n)
|
113
|
+
# @example
|
114
|
+
# set = RbLovely::SortedSet.new [0, 1, 2, 3]
|
115
|
+
# set.each { |x| puts x }
|
116
|
+
def each(&block) ; end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# A SortedHash provides hashed unique keys and ordered non-unique values. Values are sorted using "<=>" and keys are tested for equality using "eql?".
|
121
|
+
# @note
|
122
|
+
# A SortedHash should not be modified during iteration.
|
123
|
+
#
|
124
|
+
# This class is only provided if boost is available on the system when the gem is installed as it is built using the {http://www.boost.org/doc/libs/1_56_0/libs/multi_index/doc/index.html Boost Multi-index Containers Library}.
|
125
|
+
#
|
126
|
+
# Some methods come from the {http://www.ruby-doc.org/core-2.1.2/Enumerable.html Enumerable} module. If you do not find the method you are looking for in this documentation then please look there.
|
127
|
+
# @author nuisanceofcats
|
128
|
+
# @example
|
129
|
+
# empty_hash = RbLovely::SortedHash.new
|
130
|
+
#
|
131
|
+
# # constructor is like: hash[20] = 5 ; hash[9] = 1
|
132
|
+
# hash = RbLovely::SortedHash.new [20, 5, 9, 1]
|
133
|
+
# hash[2] = 16
|
134
|
+
# hash[20] = 4 # updates previous value
|
135
|
+
# expect(hash[20]).to equal 4
|
136
|
+
# expect(hash.length).to equal 3
|
137
|
+
class SortedHash
|
138
|
+
include Enumerable
|
139
|
+
|
140
|
+
# @param content [Array] An array containing key, value, key, value ...
|
141
|
+
# @param compare [Proc] Comparison function used to order values (rather than default
|
142
|
+
# of using <=> method).
|
143
|
+
# @example
|
144
|
+
# hash = RbLovely::SortedHash.new([:a, 10, :c, 5, :b, 1 ])
|
145
|
+
# expect(hash.to_a).to eql [[:b, 1], [:c, 5], [:a, 10]]
|
146
|
+
#
|
147
|
+
# # compare function reverses default sort order
|
148
|
+
# hash = RbLovely::SortedHash.new(compare: proc { |a, b| b <=> a })
|
149
|
+
# hash[:a] = 1
|
150
|
+
# hash[:c] = 5
|
151
|
+
# hash[:b] = 10
|
152
|
+
# expect(hash.to_a).to eql [[:b, 10], [:c, 5], [:a, 1 ]]
|
153
|
+
def initialize content = [], compare: nil ; end
|
154
|
+
|
155
|
+
# Delete the value associated with a key.
|
156
|
+
# @return The value associated with the deleted key or nil if the key was not in the hash.
|
157
|
+
# @example
|
158
|
+
# hash = RbLovely::SortedHash.new([:a, 5 ])
|
159
|
+
# expect(hash.delete(:a)).to equal 5
|
160
|
+
# expect(hash.delete(:b)).to equal nil
|
161
|
+
def delete key ; end
|
162
|
+
|
163
|
+
# Calls block once for each key, passing the key-value pair as parameters.
|
164
|
+
# @complexity O(n)
|
165
|
+
# @example
|
166
|
+
# hash = RbLovely::SortedHash.new [:a, 10, :b, 1]
|
167
|
+
# # This would call the block in value order: with (:b, 1) followed by (:a, 10).
|
168
|
+
# hash.each { |key, value| puts "#{key} => #{value}" }
|
169
|
+
def each(&block) ; end
|
170
|
+
|
171
|
+
# Remove all values from the hash.
|
172
|
+
# @example
|
173
|
+
# hash = RbLovely::SortedHash.new [:a, 10]
|
174
|
+
# hash.clear
|
175
|
+
# expect(hash.length).to equal 0
|
176
|
+
def clear ; end
|
177
|
+
|
178
|
+
# Retrieve value associated with the corresponding key or nil if the key doesn't exist.
|
179
|
+
# @complexity O(c)
|
180
|
+
# @example
|
181
|
+
# hash = RbLovely::SortedHash.new [:a, 2]
|
182
|
+
# expect(hash[:a]).to equal 2
|
183
|
+
# expect(hash[:b]).to equal nil
|
184
|
+
def [](key) ; end
|
185
|
+
|
186
|
+
# Return true if the key is contained in the hash.
|
187
|
+
def include?(key) ; end
|
188
|
+
|
189
|
+
# Retrieve first value sorted by <=> or comparison function or nil if the hash is empty.
|
190
|
+
def first ; end
|
191
|
+
|
192
|
+
# Retrieve last value sorted by <=> or comparison function or nil if the hash is empty.
|
193
|
+
def last ; end
|
194
|
+
|
195
|
+
alias :has_key? :include?
|
196
|
+
end
|
197
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_lovely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pike
|
@@ -19,12 +19,14 @@ extensions:
|
|
19
19
|
- ext/rb_lovely/extconf.rb
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- ".yardopts"
|
22
23
|
- ext/rb_lovely/container.hpp
|
23
24
|
- ext/rb_lovely/extconf.rb
|
24
25
|
- ext/rb_lovely/package.cpp
|
25
26
|
- ext/rb_lovely/ruby_util.hpp
|
26
27
|
- ext/rb_lovely/sorted_hash.cpp
|
27
28
|
- ext/rb_lovely/sorted_set.cpp
|
29
|
+
- yard.rb
|
28
30
|
homepage: https://github.com/nuisanceofcats/rb_lovely
|
29
31
|
licenses:
|
30
32
|
- Expat
|