class

NgLib::AATreeMap(K, V)

Inherits Enumerable < Reference < Object

順序付き連想配列です。

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

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

Constructors

new(enumerable : Enumerable(Tuple(K, V)))
Source
new(default : V)
Source

Instance methods

<<(item : Tuple(K, V)) : Nil
Source
[](key : K) : V
Source
[]=(key : K, value : V) : V
Source
[]?(key : K) : V | Nil
Source
at(k : Int) : Tuple(K, V)
Source
at?(k : Int) : Tuple(K, V) | Nil
Source
clear
Source
concat(elems) : self
Source
delete_at(k : Int)
Source
delete_key(key : K) : Bool
Source
each

Must yield this collection's elements to the block.

Source
each_key
Source
each_value
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
greater_equal_index(key : K) : Int32 | Nil
Source
greater_index(key : K) : Int32 | Nil
Source
has_key?(key : K) : Bool
Source
includes?(key : K, value : V) : Bool
Source
inspect(io : IO)

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
key_at(k : Int) : K
Source
key_at?(k : Int) : K | Nil
Source
keys
Source
less_equal_index(key : K) : Int32 | Nil
Source
less_index(key : K) : Int32 | Nil
Source
lower_bound_index(key : K) : 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(key : K) : Int32
Source
value_at(k : Int) : V
Source
value_at?(k : Int) : V | Nil
Source
values
Source