kyanite 0.6.1 → 0.7.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.
- data/Div +6 -32
- data/{History.txt → History.rdoc} +8 -0
- data/{License.txt → License.rdoc} +0 -0
- data/Manifest.txt +6 -21
- data/README.rdoc +44 -0
- data/Rakefile.rb +19 -68
- data/console.rb +2 -4
- data/lib/kyanite.rb +151 -14
- data/lib/kyanite/array.rb +127 -4
- data/lib/kyanite/basics.rb +3 -7
- data/lib/kyanite/dictionary.rb +19 -21
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +22 -24
- data/lib/kyanite/enumerable/enumerable_numerics.rb +51 -49
- data/lib/kyanite/enumerable/enumerable_strings.rb +18 -25
- data/lib/kyanite/enumerable/structure.rb +46 -58
- data/lib/kyanite/general/callerutils.rb +30 -28
- data/lib/kyanite/general/classutils.rb +73 -63
- data/lib/kyanite/general/kernel.rb +45 -64
- data/lib/kyanite/general/object.rb +22 -46
- data/lib/kyanite/general/true_false.rb +33 -27
- data/lib/kyanite/general/undoable.rb +12 -16
- data/lib/kyanite/hash.rb +63 -58
- data/lib/kyanite/numeric.rb +14 -1
- data/lib/kyanite/numeric/float.rb +32 -22
- data/lib/kyanite/numeric/integer.rb +12 -20
- data/lib/kyanite/optimizer.rb +41 -24
- data/lib/kyanite/range.rb +42 -22
- data/lib/kyanite/set.rb +56 -63
- data/lib/kyanite/string.rb +1 -2
- data/lib/kyanite/string/cast.rb +61 -37
- data/lib/kyanite/string/chars.rb +66 -36
- data/lib/kyanite/string/chars_const.rb +4 -3
- data/lib/kyanite/string/diff.rb +64 -34
- data/lib/kyanite/string/include.rb +16 -9
- data/lib/kyanite/string/list.rb +38 -8
- data/lib/kyanite/string/misc.rb +64 -0
- data/lib/kyanite/string/nested.rb +39 -22
- data/lib/kyanite/string/random.rb +117 -47
- data/lib/kyanite/string/split.rb +84 -45
- data/lib/kyanite/symbol.rb +30 -21
- data/lib/kyanite/tree.rb +33 -28
- data/test/_start_all.rb +18 -15
- data/test/array/test_array.rb +5 -7
- data/test/enumerable/test_enumerable_enumerables.rb +11 -15
- data/test/enumerable/test_enumerable_numerics.rb +50 -54
- data/test/enumerable/test_enumerable_strings.rb +8 -11
- data/test/enumerable/test_structure.rb +6 -8
- data/test/general/test_classutils.rb +9 -9
- data/test/general/test_object.rb +4 -5
- data/test/general/test_true_false.rb +4 -5
- data/test/numeric/test_numeric_integer.rb +6 -6
- data/test/string/test_cast.rb +4 -5
- data/test/string/test_chars.rb +6 -7
- data/test/string/test_diff.rb +4 -5
- data/test/string/test_list.rb +4 -5
- data/test/string/test_misc.rb +58 -0
- data/test/string/test_nested.rb +4 -5
- data/test/string/test_split.rb +10 -5
- data/test/test_dictionary.rb +4 -6
- data/test/test_hash.rb +5 -7
- data/test/test_optimizer.rb +4 -5
- data/test/test_range.rb +8 -9
- data/test/test_set.rb +7 -7
- data/test/test_tree.rb +7 -10
- data/version.rb +8 -0
- metadata +32 -33
- data/README.txt +0 -47
- data/lib/kyanite/array/array.rb +0 -140
- data/lib/kyanite/array/array2.rb +0 -142
- data/lib/kyanite/array/matrix2.rb +0 -120
- data/lib/kyanite/hoe.rb +0 -2
- data/lib/kyanite/matrix2.rb +0 -2
- data/lib/kyanite/numeric/numeric.rb +0 -54
- data/lib/kyanite/operation.rb +0 -5
- data/lib/kyanite/operation/call_tracker.rb +0 -69
- data/lib/kyanite/operation/hoe.rb +0 -12
- data/lib/kyanite/operation/rake.rb +0 -298
- data/lib/kyanite/operation/regexp.rb +0 -28
- data/lib/kyanite/operation/unit_test.rb +0 -50
- data/lib/kyanite/rake.rb +0 -2
- data/lib/kyanite/smart_load_path.rb +0 -6
- data/lib/kyanite/string/div.rb +0 -28
- data/lib/kyanite/string/mgsub.rb +0 -43
- data/lib/kyanite/unit_test.rb +0 -2
- data/test/array/test_matrix2.rb +0 -166
- data/test/string/test_mgsub.rb +0 -58
data/lib/kyanite/numeric.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
2
|
require 'kyanite/numeric/float'
|
3
3
|
require 'kyanite/numeric/integer'
|
4
|
-
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
class Numeric
|
8
|
+
|
9
|
+
# +false+, Numerics are not empty.
|
10
|
+
# @return [Boolean]
|
11
|
+
# @private
|
12
|
+
def empty?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end # class
|
@@ -1,33 +1,43 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
Infinity = 1.0/0 unless defined? Infinity
|
3
9
|
Googol = 10**100 unless defined? Googol
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
# ---
|
9
|
-
#
|
10
|
-
# == *Float*
|
11
|
-
#
|
12
|
-
#
|
11
|
+
|
12
|
+
|
13
|
+
# @!macro numeric
|
13
14
|
class Float
|
14
15
|
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# 98.6.
|
18
|
-
# 98.6.approx(98.66, 0.001) => true
|
19
|
-
# Copyright 2006 O'Reilly Media, Ruby Cookbook, by Lucas Carlson and Leonard Richardson
|
16
|
+
# Fuzzy comparison of Floats. Example:
|
17
|
+
# (98.6).fuzzy_equal?(98.66) => false
|
18
|
+
# (98.6).fuzzy_equal?(98.66, 0.001) => true
|
20
19
|
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return
|
20
|
+
# @param other [Float] Value to compare with
|
21
|
+
# @param error_max [Float] Maximum relative error
|
22
|
+
def fuzzy_equal?(other, error_max=0.000001)
|
23
|
+
diff = other - self
|
24
|
+
return true if diff.abs <= Float::EPSILON
|
25
|
+
relative_error = (diff / (self > other ? self : other)).abs
|
26
|
+
#puts relative_error
|
27
|
+
return relative_error <= error_max
|
26
28
|
end
|
27
|
-
|
28
|
-
# Ruby Cookbook, by Lucas Carlson and Leonard Richardson
|
29
|
-
# Copyright 2006 O'Reilly Media
|
29
|
+
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# -----------------------------------------------------------------------------------------
|
36
|
+
# ausprobieren
|
37
|
+
#
|
38
|
+
if $0 == __FILE__ then
|
39
|
+
|
40
|
+
puts (98.6).fuzzy_equal?(98.66)
|
41
|
+
puts (98.6).fuzzy_equal?(98.66, 0.001)
|
42
|
+
|
43
|
+
end # if
|
@@ -1,32 +1,24 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
# @!macro numeric
|
10
10
|
class Integer
|
11
11
|
|
12
|
-
#
|
12
|
+
# Converts a number of seconds-since-1970 in a Time object
|
13
|
+
# @return [Time]
|
13
14
|
def to_time
|
14
15
|
return nil if self > 2099999999 # geht leider nur bis ins Jahr 2036
|
15
16
|
::Time.at(self) # ohne die Doppelpunkte sucht Ruby die Methode at in ::Time und wirft einen Error
|
16
17
|
end
|
17
18
|
|
18
|
-
# Rückgabe: self
|
19
|
-
# Test: TestKyaniteNumeric#test_integer_triviales
|
20
|
-
def to_integer; self; end
|
21
|
-
|
22
|
-
|
23
|
-
# Rückgabe: self
|
24
|
-
# Test: TestKyaniteNumeric#test_integer_triviales
|
25
|
-
def to_integer_optional; self; end
|
26
|
-
|
27
19
|
|
28
|
-
|
29
|
-
|
20
|
+
# +self+, you can not dup Integers
|
21
|
+
# @return [self]
|
30
22
|
def dup; self; end
|
31
23
|
|
32
24
|
end # class
|
data/lib/kyanite/optimizer.rb
CHANGED
@@ -1,24 +1,36 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
+
# ü
|
3
|
+
if $0 == __FILE__
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
|
+
end
|
7
|
+
|
2
8
|
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
# @!macro optimizer
|
13
|
+
# ==== Example
|
14
|
+
# require 'kyanite/optimizer'
|
15
|
+
# test = Optimizer.new
|
16
|
+
# test.push 1, 'hello'
|
17
|
+
# test.push 5, 'item'
|
18
|
+
# test.push 6, 'maximum23'
|
19
|
+
# test.push -1, 'minimum'
|
20
|
+
# test.push -1, 'another minimum'
|
21
|
+
# test.content_max
|
22
|
+
# >= "maximum23"
|
23
|
+
# test.content_min
|
24
|
+
# >= "minimum"
|
25
|
+
# More tests and examples {TestKyaniteOptimizer here}.
|
3
26
|
#
|
4
|
-
|
5
|
-
|
6
|
-
# ---
|
7
|
-
#
|
8
|
-
# == *Optimizer*
|
9
|
-
# Auswahl von Objekten auf Basis von Scores. See TestKyaniteOptimizer for Tests and examples.
|
10
|
-
#
|
11
|
-
# Jedes Objekt wird per +push+ in den Optimizer geschrieben. Dabei wird auch sein Score übergeben.
|
12
|
-
# +content_max+ bzw. +content_min+ liefern das Objekt mit dem höchsten / niedrigsten Score.
|
13
|
-
# +delete_max+ bzw. +delete_min+ löschen das Objekt mit den höchsten / niedrigsten Score. Dadurch ist auch der Zugriff auf die zweiten und dritten Objekte möglich.
|
14
|
-
#
|
27
|
+
class Optimizer < Hash
|
28
|
+
|
15
29
|
# Drei Stufen für Marshall sind denkbar:
|
16
30
|
# * kein Marshal
|
17
31
|
# * Marshal.load(Marshal.dump) beim Schreiben. Dadurch sind Schreibzugriffe teuer, Lesezugriffe aber billig
|
18
32
|
# * Marshal.dump beim Schreiben, Marshal.load beim Lesen. Dadurch sind Lese- und Schreibzugriffe teuer,
|
19
33
|
# die im Optimizer gespeicherten Objekte sind aber abgeschottet und geschützt.
|
20
|
-
#
|
21
|
-
class Optimizer < Hash
|
22
34
|
|
23
35
|
#@@marshal = true
|
24
36
|
|
@@ -27,24 +39,25 @@ class Optimizer < Hash
|
|
27
39
|
# end
|
28
40
|
|
29
41
|
|
30
|
-
|
42
|
+
|
43
|
+
# @return [Numeric] Value of maximum score
|
31
44
|
def score_max
|
32
45
|
return nil if size == 0
|
33
46
|
keys.max
|
34
47
|
end
|
35
48
|
|
36
49
|
|
37
|
-
#
|
50
|
+
# @return [Numeric] Value of minimum score
|
38
51
|
def score_min
|
39
52
|
return nil if size == 0
|
40
53
|
keys.min
|
41
54
|
end
|
42
55
|
|
43
56
|
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
57
|
+
# Returns the content with maximum score.
|
58
|
+
# content_max(0) # returns the first content with maximum score
|
59
|
+
# content_max(-1) # returns the last content with maximum score
|
60
|
+
# content_max(0..-1) # returns all contents with maximum score (as Array)
|
48
61
|
#
|
49
62
|
def content_max(range=0..0)
|
50
63
|
return nil if size == 0
|
@@ -61,7 +74,11 @@ class Optimizer < Hash
|
|
61
74
|
end
|
62
75
|
|
63
76
|
|
64
|
-
#
|
77
|
+
# Returns the content with minimum score.
|
78
|
+
# content_min(0) # returns the first content with minimum score
|
79
|
+
# content_min(-1) # returns the last content with minimum score
|
80
|
+
# content_min(0..-1) # returns all contents with minimum score (as Array)
|
81
|
+
#
|
65
82
|
def content_min(range=0..0)
|
66
83
|
return nil if size == 0
|
67
84
|
range = (range..range) if range.kind_of?(Fixnum)
|
@@ -77,7 +94,7 @@ class Optimizer < Hash
|
|
77
94
|
end
|
78
95
|
|
79
96
|
|
80
|
-
#
|
97
|
+
# Load the optimizer with objects.
|
81
98
|
def push( score, content, options={} )
|
82
99
|
if self.has_key?(score)
|
83
100
|
self[score] << Marshal.dump(content)
|
@@ -87,7 +104,7 @@ class Optimizer < Hash
|
|
87
104
|
end
|
88
105
|
|
89
106
|
|
90
|
-
#
|
107
|
+
# Deletes all objects in the middle.
|
91
108
|
def cleanup
|
92
109
|
return false if size <= 2
|
93
110
|
keys.sort[1..-2].each do | key |
|
@@ -97,14 +114,14 @@ class Optimizer < Hash
|
|
97
114
|
end
|
98
115
|
|
99
116
|
|
100
|
-
#
|
117
|
+
# Deletes the object with the lowest score.
|
101
118
|
def delete_min
|
102
119
|
return false if size <= 1
|
103
120
|
self.delete(keys.min)
|
104
121
|
true
|
105
122
|
end
|
106
123
|
|
107
|
-
#
|
124
|
+
# Deletes the object with the highest score.
|
108
125
|
def delete_max
|
109
126
|
return false if size <= 1
|
110
127
|
self.delete(keys.max)
|
data/lib/kyanite/range.rb
CHANGED
@@ -1,46 +1,63 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
|
-
#
|
2
|
+
#
|
3
3
|
if $0 == __FILE__
|
4
|
-
require
|
5
|
-
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
6
|
end
|
7
|
+
|
7
8
|
require 'facets/range/combine'
|
8
9
|
require 'facets/range/within'
|
9
|
-
require 'kyanite/enumerable' # is_collection? ist
|
10
|
+
require 'kyanite/enumerable' # is_collection? ist false for Ranges
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
# == *Range*
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# Aus {Facets/Range}[http://facets.rubyforge.org/doc/api/core/classes/Range.html] eingefügt:
|
19
|
-
# umbrella(range)
|
20
|
-
# within?
|
21
|
-
# combine(range)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
# @!macro range
|
22
16
|
#
|
17
|
+
# === Added from {http://rubyworks.github.com/rubyfaux/?doc=http://rubyworks.github.com/facets/docs/facets-2.9.3/core.json#api-class-Range Facets Range}:
|
18
|
+
# [+umbrella(range)+] Returns a two element array of the relationship between two Ranges
|
19
|
+
# [+within? (range)+] Is another Range anywhere within this Range?
|
20
|
+
# [+combine(range)+] Combine ranges
|
23
21
|
#
|
24
22
|
class Range
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
#
|
24
|
+
|
25
|
+
|
26
|
+
# Given a range for selecting a section of a {String} or an {Array},
|
27
|
+
# +invert_index+ inverts this range, so that the result
|
28
|
+
# selects the inverse part of the {String} or {Array}.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# # return back
|
32
|
+
# (0..5).invert_index
|
33
|
+
# => (6..-1)
|
34
|
+
#
|
35
|
+
# # return front
|
36
|
+
# (3..-1).invert_index
|
37
|
+
# => (0..2)
|
38
|
+
#
|
39
|
+
# # return outer
|
40
|
+
# (2..4).invert_index
|
41
|
+
# => [0..1, 5..-1]
|
42
|
+
#
|
43
|
+
# Tests and more examples {TestKyaniteRange here}.
|
29
44
|
#
|
45
|
+
#
|
46
|
+
# @return [Range] or [Array] of two Ranges
|
30
47
|
def invert_index
|
31
48
|
|
32
|
-
#
|
49
|
+
# back
|
33
50
|
if first == 0
|
34
51
|
return (1..0) if last == -1 # leer
|
35
52
|
return (last+1..-1) # hinterer Teil
|
36
53
|
|
37
|
-
#
|
54
|
+
# front
|
38
55
|
else
|
39
56
|
return (0..first-1) if last == -1 # vorderer Teil
|
40
57
|
|
41
58
|
end
|
42
59
|
|
43
|
-
#
|
60
|
+
# outer
|
44
61
|
return [(first..-1).invert_index, (0..last).invert_index]
|
45
62
|
end # def
|
46
63
|
|
@@ -53,13 +70,16 @@ end # class
|
|
53
70
|
|
54
71
|
if defined? TransparentNil
|
55
72
|
class NilClass
|
56
|
-
|
73
|
+
# @!group return nil
|
74
|
+
def invert_index; nil; end
|
57
75
|
def umbrella(*a); nil; end
|
58
76
|
def combine(*a); nil; end
|
59
77
|
def within?(*a); nil; end
|
60
78
|
end
|
61
79
|
end # if defined? TransparentNil
|
62
80
|
|
81
|
+
|
82
|
+
|
63
83
|
# ==================================================================================
|
64
84
|
# Ausprobieren
|
65
85
|
#
|
data/lib/kyanite/set.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ruby encoding: utf-8
|
2
2
|
# ü
|
3
3
|
if $0 == __FILE__
|
4
|
-
require
|
5
|
-
|
4
|
+
require 'drumherum'
|
5
|
+
smart_init
|
6
6
|
end
|
7
7
|
|
8
8
|
require 'set'
|
@@ -13,41 +13,34 @@ require 'kyanite/symbol' # damit man auch Symbols aufnehmen kann
|
|
13
13
|
require 'kyanite/hash' # Korrektur der Methoden hash und eql?
|
14
14
|
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
# === Unterschiede der verschiedenen Set-Klassen
|
25
|
-
# * Ein {Set}[http://www.ruby-doc.org/core/classes/Set.html] ist ungeordnet.
|
26
|
-
# Beispiele: TestKyaniteSet#test_set
|
27
|
-
# * Ein OrderedSet ist geordnet, es behält die ursprüngliche Reihenfolge, wird aber nicht kontinuierlich neu sortiert.
|
28
|
-
# Es sei denn, man sorgt dafür mit Dictionary#order_by
|
29
|
-
# Beispiele: TestKyaniteSet#test_ordered_set
|
30
|
-
# * Ein {SortedSet}[http://www.ruby-doc.org/core/classes/SortedSet.html] ist geordnet und sortiert. Es behält immer die Sortierung.
|
31
|
-
# Beispiele: TestKyaniteSet#test_sorted_set
|
32
|
-
#
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
# @!macro set
|
33
24
|
class Set
|
34
25
|
|
35
|
-
#
|
26
|
+
# Adds the element to the set.
|
36
27
|
def push(elt)
|
37
28
|
self << elt
|
38
29
|
end
|
39
30
|
|
40
31
|
|
41
|
-
#
|
32
|
+
# Comparison operator (by size)
|
33
|
+
# @return [Integer] 1, 0, -1
|
42
34
|
def <=>(other)
|
43
35
|
self.size <=> other.size
|
44
36
|
end
|
45
37
|
|
46
38
|
# def hash_raw
|
47
|
-
#
|
39
|
+
# hash
|
48
40
|
# end
|
49
41
|
|
50
|
-
|
42
|
+
|
43
|
+
# @return any element
|
51
44
|
def first
|
52
45
|
@hash.each do |key, value|
|
53
46
|
return key
|
@@ -55,7 +48,7 @@ class Set
|
|
55
48
|
end #def
|
56
49
|
|
57
50
|
|
58
|
-
#
|
51
|
+
# @return any other element
|
59
52
|
def last
|
60
53
|
first = nil
|
61
54
|
@hash.each do |key, value|
|
@@ -71,16 +64,10 @@ class Set
|
|
71
64
|
end
|
72
65
|
|
73
66
|
|
74
|
-
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# == *Ordered* *Set*
|
79
|
-
# Tests and examples see TestKyaniteSet
|
80
|
-
#
|
81
|
-
# Ein OrderedSet ist geordnet, es behält die ursprüngliche Reihenfolge, wird aber nicht kontinuierlich neu sortiert.
|
82
|
-
# Es sei denn, man sorgt dafür mit Dictionary#order_by
|
83
|
-
#
|
67
|
+
|
68
|
+
# =================================================================================================================
|
69
|
+
# @!macro set
|
70
|
+
#
|
84
71
|
class OrderedSet < Set
|
85
72
|
|
86
73
|
def initialize(enum = nil, &block) # :yields: o
|
@@ -94,30 +81,32 @@ class OrderedSet < Set
|
|
94
81
|
end
|
95
82
|
|
96
83
|
|
97
|
-
#
|
84
|
+
# @return n-th Element
|
98
85
|
def [](index)
|
99
86
|
@hash.order[index]
|
100
87
|
end
|
101
88
|
|
102
|
-
|
103
|
-
def zugrundeliegendes_dictionary
|
89
|
+
# @private
|
90
|
+
def zugrundeliegendes_dictionary
|
104
91
|
@hash
|
105
92
|
end
|
93
|
+
|
106
94
|
|
107
|
-
#
|
108
|
-
#
|
95
|
+
# This method is fast. Nothing needs to be converted.
|
96
|
+
# @return [Array]
|
109
97
|
def to_a
|
110
98
|
@hash.order
|
111
99
|
end
|
112
100
|
|
113
|
-
|
101
|
+
|
102
|
+
# @return [Boolean]
|
114
103
|
def ==(other)
|
115
104
|
silence_warnings do
|
116
105
|
self.to_a.to_set == other.to_a.to_set
|
117
106
|
end
|
118
107
|
end
|
119
108
|
|
120
|
-
#
|
109
|
+
# like Array#index
|
121
110
|
def index(object)
|
122
111
|
self.to_a.index(object)
|
123
112
|
end
|
@@ -131,10 +120,12 @@ class OrderedSet < Set
|
|
131
120
|
@hash.order_by( &block )
|
132
121
|
end
|
133
122
|
|
123
|
+
# @return first element
|
134
124
|
def first
|
135
125
|
self[0]
|
136
126
|
end
|
137
127
|
|
128
|
+
# @return last element
|
138
129
|
def last
|
139
130
|
self[-1]
|
140
131
|
end
|
@@ -144,37 +135,35 @@ class OrderedSet < Set
|
|
144
135
|
end # class
|
145
136
|
|
146
137
|
|
147
|
-
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
# == *Sorted* *Set*
|
152
|
-
# Tests and examples see TestKyaniteSet
|
153
|
-
#
|
154
|
-
# Ein {SortedSet}[http://www.ruby-doc.org/core/classes/SortedSet.html] ist geordnet und sortiert. Es behält immer die Sortierung.
|
155
|
-
# Beispiele: TestKyaniteSet#test_sorted_set
|
156
|
-
#
|
138
|
+
|
139
|
+
# =================================================================================================================
|
140
|
+
# @!macro set
|
141
|
+
#
|
157
142
|
class SortedSet
|
158
143
|
|
159
|
-
#
|
160
|
-
#
|
144
|
+
# @return n-th Element
|
145
|
+
# n-th Element. inefficient!!
|
161
146
|
def [](index)
|
162
147
|
self.to_a[index]
|
163
148
|
end
|
164
149
|
|
150
|
+
# @return first element
|
165
151
|
def first
|
166
152
|
self[0]
|
167
153
|
end
|
168
154
|
|
155
|
+
# @return last element
|
169
156
|
def last
|
170
157
|
self[-1]
|
171
158
|
end
|
172
159
|
|
173
160
|
# das war mal auskommentiert, wird aber von nat_lang gebraucht
|
174
|
-
|
161
|
+
# @private
|
162
|
+
def unshift(e)
|
175
163
|
self << e
|
176
164
|
end
|
177
165
|
|
166
|
+
# @return self
|
178
167
|
def to_sorted_set
|
179
168
|
self
|
180
169
|
end
|
@@ -183,32 +172,36 @@ end # class
|
|
183
172
|
|
184
173
|
|
185
174
|
|
186
|
-
|
175
|
+
# ===========================================================================================================================
|
176
|
+
#
|
187
177
|
|
188
178
|
class Array
|
189
179
|
|
190
|
-
#
|
191
|
-
|
192
|
-
#
|
180
|
+
# @!group Cast
|
181
|
+
|
182
|
+
# Returns {OrderedSet}, tests and examples {TestKyaniteSet#test_ordered_set here}.
|
183
|
+
# @return [OrderedSet]
|
193
184
|
def to_ordered_set
|
194
185
|
OrderedSet.new(self)
|
195
186
|
end
|
196
187
|
|
197
|
-
|
198
|
-
#
|
199
|
-
#
|
188
|
+
|
189
|
+
# Returns {SortedSet}, tests and examples {TestKyaniteSet#test_sorted_set here}.
|
190
|
+
# @return [SortedSet]
|
200
191
|
def to_sorted_set
|
201
192
|
SortedSet.new(self)
|
202
193
|
end
|
203
194
|
|
195
|
+
# @!endgroup
|
204
196
|
|
205
197
|
end # class
|
206
198
|
|
207
199
|
|
208
200
|
class Object
|
209
201
|
|
210
|
-
|
211
|
-
#
|
202
|
+
|
203
|
+
# Returns {Set} with one element
|
204
|
+
# @return [Set] with one element
|
212
205
|
def to_set; Set.new([self]); end
|
213
206
|
|
214
207
|
end
|