class

NgLib::AATreeSet(T)

Inherits Enumerable < Reference < Object

順序付き集合です。

平衡二分探索木として AA木 を使用しています。 性能は赤黒木の方が良いことが多い気がします。

C++の標準ライブラリの multiset と違って、$k$ 番目の値が取り出せることなどが魅力的です。

Constructors

new(enumerable : Enumerable(T))
Source

Instance methods

<<(val : T) : Bool
Source
==(other : AATreeSet(T)) : Bool
Source
[](k : Int) : T
Source
[]?(k : Int) : T | Nil
Source
add(val : T) : Nil
Source
add?(val : T) : Bool
Source
at(k : Int) : T
Source
at?(k : Int) : T | Nil
Source
clear
Source
concat(elems) : self
Source
count(val : T) : Int32
Source
delete(val : T) : Bool
Source
delete_at(k : Int) : Bool
Source
delete_at?(k : Int) : Bool
Source
each

Must yield this collection's elements to the block.

Source
empty?

Returns true if self does not contain any element.

([] of Int32).empty? # => true
([1]).empty?         # => false
[nil, false].empty?  # => false
  • #present? returns the inverse.
Source
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
Source
first?

Returns the first element in the collection. When the collection is empty, returns nil.

([1, 2, 3]).first?   # => 1
([] of Int32).first? # => nil
Source
greater_equal_index(val : T) : Int32 | Nil
Source
greater_index(val : T) : Int32 | Nil
Source
includes?(val : T) : Bool
Source
inspect(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>
Source
last
Source
last?
Source
less_equal_index(val : T) : Int32 | Nil
Source
less_index(val : T) : Int32 | Nil
Source
lower_bound_index(val : T) : Int32
Source
size

Returns the number of elements in the collection.

[1, 2, 3, 4].size # => 4
Source
to_a

Returns an Array with all the elements in the collection.

(1..5).to_a # => [1, 2, 3, 4, 5]
Source
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>
Source
upper_bound_index(val : T) : Int32
Source