class NgLib:: SqrtSet(T)

Included Modules

Defined in:

nglib/data_structure/sortedcontainers/sqrt_set.cr

Constant Summary

BUCKET_RATIO = 16
SPLIT_RATIO = 24

Constructors

Instance Method Summary

Constructor Detail

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

[ View source ]
def self. new #

[ View source ]

Instance Method Detail

def & (other : self ) : self #

[ View source ]
def + (other : SqrtSet (U)) : SqrtSet (T | U) forall U #

[ View source ]
def - (other : SqrtSet ) #

[ View source ]
def - (other : Enumerable) #

[ View source ]
def < (other) #

[ View source ]
def << (elem : T) : self #

[ View source ]
def <= (other) #

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

[ View source ]
def > (other) #

[ View source ]
def >= (other) #

[ View source ]
def ^ (other : Enumerable(U)) forall U #

[ View source ]
def | (other : SqrtSet (U)) : SqrtSet (T | U) forall U #

[ View source ]
def add (elem : T) : self #

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

[ View source ]
def at (index : Int ) #

[ View source ]
def at (index : Int , &) #

[ View source ]
def at? (index : Int ) #

[ View source ]
def clear #

[ View source ]
def clone #

[ View source ]
def concat (elems) #

[ View source ]
def count (range : Range(T | Nil, T | Nil)) #

[ View source ]
def count (object) #
Description copied from module Enumerable(T)

Returns the number of times that the passed item is present in the collection.

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

[ View source ]
def delete (object) : self #

[ View source ]
def delete_at (index : Int , &) #

[ View source ]
def dup #
Description copied from class Reference

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.


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

Calls the given block once for each element in self , passing that element as a parameter.

a = ["a", "b", "c"]
a.each { |x| print x, " -- " }

produces:

a -- b -- c --

[ View source ]
def empty? #
Description copied from module Indexable(T)

Returns true if self is empty, false otherwise.

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

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

[ View source ]
def index (object) #
Description copied from module Indexable(T)

Returns the index of the first appearance of object in self starting from the given offset , or nil if object is not in self .

[1, 2, 3, 1, 2, 3].index(2, offset: 2) # => 4

[ View source ]
def index! (object) #
Description copied from module Indexable(T)

Returns the index of the first appearance of obj in self starting from the given offset . Raises Enumerable::NotFoundError if obj is not in self .

[1, 2, 3, 1, 2, 3].index!(2, offset: 2) # => 4

[ 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 intersects? (other) #

[ View source ]
def largest_less_than (object) #

[ View source ]
def largest_less_than_or_equal_to (object) #

[ View source ]
def lower_bound (object : T) #

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

Returns the element with the maximum value in the collection.

It compares using > so it will work for any type that supports that method.

[1, 2, 3].max        # => 3
["Alice", "Bob"].max # => "Bob"

Raises Enumerable::EmptyError if the collection is empty.


[ View source ]
def max? #
Description copied from module Enumerable(T)

Like #max but returns nil if the collection is empty.


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

Returns the element with the minimum value in the collection.

It compares using < so it will work for any type that supports that method.

[1, 2, 3].min        # => 1
["Alice", "Bob"].min # => "Alice"

Raises Enumerable::EmptyError if the collection is empty.


[ View source ]
def min? #
Description copied from module Enumerable(T)

Like #min but returns nil if the collection is empty.


[ View source ]
def pop (&) #

[ View source ]
def pop #

[ View source ]
def pop? #

[ View source ]
def proper_subset_of? (other) #

[ View source ]
def proper_superset_of? (other) #

[ View source ]
def rindex (object) #
Description copied from module Indexable(T)

Returns the index of the last appearance of value in self , or nil if the value is not in self .

If offset is given, it defines the position to end the search (elements beyond this point are ignored).

[1, 2, 3, 2, 3].rindex(2)            # => 3
[1, 2, 3, 2, 3].rindex(2, offset: 2) # => 1

[ View source ]
def rindex! (object) #
Description copied from module Indexable(T)

Returns the index of the last appearance of value in self , or nil if the value is not in self .

If offset is given, it defines the position to end the search (elements beyond this point are ignored).

[1, 2, 3, 2, 3].rindex(2)            # => 3
[1, 2, 3, 2, 3].rindex(2, offset: 2) # => 1

Raises Enumerable::NotFoundError if value is not in self .


[ View source ]
def shift : T #

[ View source ]
def shift (&) #

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

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

Returns the number of elements in this container.


[ View source ]
def smallest_greater_than (object) #

[ View source ]
def smallest_greater_than_or_equal_to (object) #

[ View source ]
def subset_of? (other) #

[ View source ]
def subtract (other : Enumerable) #

[ View source ]
def superset_of? (other) #

[ View source ]
def to_a #
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) #
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 unsafe_fetch (index : Int ) #
Description copied from module Indexable(T)

Returns the element at the given index , without doing any bounds check.

Indexable makes sure to invoke this method with index in 0...size , so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they access elements with #[](index) and #[]?(index) .

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[ View source ]
def unsafe_put (index : Int , value : T) #
Description copied from module Indexable::Mutable(T)

Sets the element at the given index to value , without doing any bounds check.

Indexable::Mutable makes sure to invoke this method with index in 0...size , so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they modify elements with #[]=(index, value) .

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[ View source ]
def upper_bound (object : T) #

[ View source ]