NgLib::AATreeSet(T)
Inherits Enumerable < Reference < Object
順序付き集合です。
平衡二分探索木として AA木 を使用しています。 性能は赤黒木の方が良いことが多い気がします。
C++の標準ライブラリの multiset と違って、$k$ 番目の値が取り出せることなどが魅力的です。
Constructors
new(enumerable : Enumerable(T))
Sourcenew
SourceInstance methods
<<(val : T) : Bool
Source==(other : AATreeSet(T)) : Bool
Sourceadd(val : T) : Nil
Sourceadd?(val : T) : Bool
Sourceclear
Sourceconcat(elems) : self
Sourcecount(val : T) : Int32
Sourcedelete(val : T) : Bool
Sourceempty?
Returns true if self does not contain any element.
([] of Int32).empty? # => true
([1]).empty? # => false
[nil, false].empty? # => false
#present?returns the inverse.
first
Returns the first element in the collection. Raises Enumerable::EmptyError
if the collection is empty.
([1, 2, 3]).first # => 1
([] of Int32).first # raises Enumerable::EmptyError
first?
Returns the first element in the collection.
When the collection is empty, returns nil.
([1, 2, 3]).first? # => 1
([] of Int32).first? # => nil
greater_equal_index(val : T) : Int32 | Nil
Sourcegreater_index(val : T) : Int32 | Nil
Sourceincludes?(val : T) : Bool
Sourceinspect(io : IO) : Nil
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
last
Sourcelast?
Sourceless_equal_index(val : T) : Int32 | Nil
Sourceless_index(val : T) : Int32 | Nil
Sourcelower_bound_index(val : T) : Int32
Sourceto_a
Returns an Array with all the elements in the collection.
(1..5).to_a # => [1, 2, 3, 4, 5]
to_s(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
upper_bound_index(val : T) : Int32
Source