class NgLib::AATreeMap(K, V)

Overview

順序付き連想配列です。

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

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

Included Modules

Defined in:

nglib/data_structure/aatree_map.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(enumerable : Enumerable(Tuple(K, V))) #

[View source]
def self.new(default : V) #

[View source]
def self.new #

[View source]

Instance Method Detail

def <<(item : Tuple(K, V)) : Nil #

[View source]
def [](key : K) : V #

[View source]
def []=(key : K, value : V) : V #

[View source]
def []?(key : K) : V | Nil #

[View source]
def at(k : Int) : Tuple(K, V) #

[View source]
def at?(k : Int) : Tuple(K, V) | Nil #

[View source]
def clear #

[View source]
def concat(elems) : self #

[View source]
def delete_at(k : Int) #

[View source]
def delete_key(key : K) : Bool #

[View source]
def each(& : Tuple(K, V) -> ) #
Description copied from module Enumerable({K, V})

Must yield this collection's elements to the block.


[View source]
def each_key(& : K -> ) #

[View source]
def each_value(& : V -> ) #

[View source]
def empty? : Bool #
Description copied from module Enumerable({K, V})

Returns true if self does not contain any element.

([] of Int32).empty? # => true
([1]).empty?         # => false
[nil, false].empty?  # => false
  • #present? returns the inverse.

[View source]
def greater_equal_index(key : K) : Int32 | Nil #

[View source]
def greater_index(key : K) : Int32 | Nil #

[View source]
def has_key?(key : K) : Bool #

[View source]
def includes?(key : K, value : V) : Bool #

[View source]
def inspect(io : IO) #
Description copied from class Reference

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>

[View source]
def key_at(k : Int) : K #

[View source]
def key_at?(k : Int) : K | Nil #

[View source]
def keys : Array(K) #

[View source]
def less_equal_index(key : K) : Int32 | Nil #

[View source]
def less_index(key : K) : Int32 | Nil #

[View source]
def lower_bound_index(key : K) : Int32 #

[View source]
def size : Int32 #
Description copied from module Enumerable({K, V})

Returns the number of elements in the collection.

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

[View source]
def to_a : Array(Tuple(K, V)) #
Description copied from module Enumerable({K, V})

Returns an Array with all the elements in the collection.

(1..5).to_a # => [1, 2, 3, 4, 5]

[View source]
def to_s(io : IO) : Nil #
Description copied from class Reference

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>

[View source]
def upper_bound_index(key : K) : Int32 #

[View source]
def value_at(k : Int) : V #

[View source]
def value_at?(k : Int) : V | Nil #

[View source]
def values : Array(V) #

[View source]