class NgLib:: AATreeSet(T)

Overview

順序付き集合です。

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

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

Included Modules

Defined in:

nglib/data_structure/aatree_set.cr

Constructors

Instance Method Summary

Constructor Detail

def self. new (enumerable : Enumerable(T)) #

[ View source ]
def self. new #

[ View source ]

Instance Method Detail

def << (val : T) : Bool #

[ View source ]
def == (other : AATreeSet (T)) : Bool #

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

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

[ View source ]
def add (val : T) : Nil #

[ View source ]
def add? (val : T) : Bool #

[ View source ]
def at (k : Int ) : T #

[ View source ]
def at? (k : Int ) : T | Nil #

[ View source ]
def clear #

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

[ View source ]
def count (val : T) : Int32 #

[ View source ]
def delete (val : T) : Bool #

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

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

[ View source ]
def each (& : T -> ) #
Description copied from module Enumerable(T)

Must yield this collection's elements to the block.


[ View source ]
def empty? : Bool #
Description copied from module Enumerable(T)

Returns true if self is empty, false otherwise.

([] of Int32).empty? # => true
([1]).empty?         # => false

[ View source ]
def first : T #
Description copied from module Enumerable(T)

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

[ View source ]
def first? : T | Nil #
Description copied from module Enumerable(T)

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

([1, 2, 3]).first?   # => 1
([] of Int32).first? # => nil

[ View source ]
def greater_equal_index (val : T) : Int32 | Nil #

[ View source ]
def greater_index (val : T) : Int32 | Nil #

[ View source ]
def includes? (val : T) : Bool #

[ View source ]
def inspect (io : IO) : Nil #
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 last : T #

[ View source ]
def last? : T | Nil #

[ View source ]
def less_equal_index (val : T) : Int32 | Nil #

[ View source ]
def less_index (val : T) : Int32 | Nil #

[ View source ]
def lower_bound_index (val : T) : Int32 #

[ View source ]
def size : Int32 #
Description copied from module Enumerable(T)

Returns the number of elements in the collection.

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

[ View source ]
def to_a : Array(T) #
Description copied from module Enumerable(T)

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 (val : T) : Int32 #

[ View source ]