class
NgLib::SqrtSet(T)
- NgLib::SqrtSet(T)
- Reference
- Object
Included Modules
- Enumerable(T)
- Indexable(T)
- Indexable::Mutable(T)
Defined in:
nglib/data_structure/sortedcontainers/sqrt_set.crConstant Summary
-
BUCKET_RATIO =
16 -
SPLIT_RATIO =
24
Constructors
Instance Method Summary
- #&(other : self) : self
- #+(other : SqrtSet(U)) : SqrtSet(T | U) forall U
- #-(other : SqrtSet)
- #-(other : Enumerable)
- #<(other)
- #<<(elem : T) : self
- #<=(other)
- #===(other : T)
- #>(other)
- #>=(other)
- #^(other : Enumerable(U)) forall U
- #|(other : SqrtSet(U)) : SqrtSet(T | U) forall U
- #add(elem : T) : self
- #add?(elem : T) : Bool
- #at(index : Int)
- #at(index : Int, &)
- #at?(index : Int)
- #clear
- #clone
- #concat(elems)
- #count(range : Range(T | Nil, T | Nil))
-
#count(object)
Returns the number of times that the passed item is present in the collection.
- #delete(object) : self
- #delete_at(index : Int, &)
-
#dup
Returns a shallow copy of this object.
-
#each(& : T -> ) : Nil
Calls the given block once for each element in
self, passing that element as a parameter. -
#empty?
Returns
trueifselfis empty,falseotherwise. - #includes?(elem : T)
-
#index(object)
Returns the index of the first appearance of object in
selfstarting from the given offset, ornilif object is not inself. -
#index!(object)
Returns the index of the first appearance of obj in
selfstarting from the given offset. -
#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.
- #intersects?(other)
- #largest_less_than(object)
- #largest_less_than_or_equal_to(object)
- #lower_bound(object : T)
-
#max
Returns the element with the maximum value in the collection.
-
#max?
Like
#maxbut returnsnilif the collection is empty. -
#min
Returns the element with the minimum value in the collection.
-
#min?
Like
#minbut returnsnilif the collection is empty. - #pop(&)
- #pop
- #pop?
- #proper_subset_of?(other)
- #proper_superset_of?(other)
-
#rindex(object)
Returns the index of the last appearance of value in
self, ornilif the value is not inself. -
#rindex!(object)
Returns the index of the last appearance of value in
self, ornilif the value is not inself. - #shift : T
- #shift(&)
- #shift? : T | Nil
-
#size : Int32
Returns the number of elements in this container.
- #smallest_greater_than(object)
- #smallest_greater_than_or_equal_to(object)
- #subset_of?(other)
- #subtract(other : Enumerable)
- #superset_of?(other)
-
#to_a
Returns an
Arraywith all the elements in the collection. -
#to_s(io : IO)
Appends a short String representation of this object which includes its class name and its object address.
-
#unsafe_fetch(index : Int)
Returns the element at the given index, without doing any bounds check.
-
#unsafe_put(index : Int, value : T)
Sets the element at the given index to value, without doing any bounds check.
- #upper_bound(object : T)
Constructor Detail
Instance Method Detail
Returns the number of times that the passed item is present in the collection.
[1, 2, 3, 4].count(3) # => 1
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self into it.
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 --
Returns true if self is empty, false otherwise.
([] of Int32).empty? # => true
([1]).empty? # => false
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
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
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>
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.
Like #max but returns nil if the collection is empty.
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.
Like #min but returns nil if the collection is empty.
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
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.
Returns the number of elements in this container.
Returns an Array with all the elements in the collection.
(1..5).to_a # => [1, 2, 3, 4, 5]
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>
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.
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.