Set is a collection without duplicates (according to ==
)
var s: Set[String] = new ArraySet[String]
var a = "Hello"
var b = "Hel" + "lo"
# ...
s.add(a)
assert s.has(b) == true
core :: Set :: defaultinit
core :: Set :: intersection
Returns the intersection of this set with theother
set
core $ Set :: remove_all
Synonym of remove since there is only one itemcore :: Collection :: CONCURRENT
Type of the concurrent variant of this collectionserialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Collection :: combinations
Allr
-length combinations on self (in same order) without repeated elements.
core :: Collection :: combinations_with_replacement
Allr
-length combination on self (in same order) with repeated elements.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Set :: defaultinit
core :: SimpleCollection :: defaultinit
core :: Cloneable :: defaultinit
core :: Collection :: defaultinit
core :: Object :: defaultinit
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: Collection :: has_all
Does the collection contain at least each element ofother
?
core :: Collection :: has_any
Does the collection contain at least one element ofother
?
core :: Collection :: has_exactly
Does the collection contain exactly all the elements ofother
?
core :: Set :: intersection
Returns the intersection of this set with theother
set
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: output_class_name
Display class name on stdout (debug only).core :: Collection :: permutations
Allr
-length permutations on self (all possible ordering) without repeated elements.
core :: Collection :: product
Cartesian product, overr
times self
.
core :: RemovableCollection :: remove
Remove an occurrence ofitem
core :: RemovableCollection :: remove_all
Remove all occurrences ofitem
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
core :: Collection :: to_concurrent
Wrapsself
in a thread-safe collection
core :: Collection :: to_counter
Create and fill up a counter with the elements of `self.core :: Collection :: to_curlslist
Convert Collection[String] to CURLSListserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: Collection :: to_shuffle
Return a new array made of elements in a random order.Serializer::serialize
# Abstract sets.
#
# Set is a collection without duplicates (according to `==`)
#
# var s: Set[String] = new ArraySet[String]
# var a = "Hello"
# var b = "Hel" + "lo"
# # ...
# s.add(a)
# assert s.has(b) == true
interface Set[E]
super SimpleCollection[E]
super Cloneable
redef fun has_only(item)
do
var l = length
if l == 1 then
return has(item)
else if l == 0 then
return true
else
return false
end
end
# Only 0 or 1
redef fun count(item)
do
if has(item) then
return 1
else
return 0
end
end
# Synonym of remove since there is only one item
redef fun remove_all(item) do remove(item)
# Equality is defined on set and means that each set contains the same elements
redef fun ==(other)
do
if not other isa Set[nullable Object] then return false
if other.length != length then return false
return has_all(other)
end
# Because of the law between `==` and `hash`, `hash` is redefined to be the sum of the hash of the elements
redef fun hash
do
# 23 is a magic number empirically determined to be not so bad.
var res = 23 + length
# Note: the order of the elements must not change the hash value.
# So, unlike usual hash functions, the accumulator is not combined with itself.
for e in self do
if e != null then res += e.hash
end
return res
end
# Returns the union of this set with the `other` set
fun union(other: Set[E]): Set[E]
do
var nhs = new_set
nhs.add_all self
nhs.add_all other
return nhs
end
# Returns the intersection of this set with the `other` set
fun intersection(other: Set[E]): Set[E]
do
var nhs = new_set
for v in self do if other.has(v) then nhs.add(v)
return nhs
end
redef fun clone do return union(self)
# Returns a new instance of `Set`.
#
# Depends on the subclass, mainly used for copy services
# like `union` or `intersection`.
protected fun new_set: Set[E] is abstract
end
lib/core/collection/abstract_collection.nit:446,1--530,3