container/Set.fz
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion standard library feature Set
#
# Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------
# Set -- an abstract set of values
#
public Set(public E type : property.equatable) ref : Sequence E is
# is this sequence known to be finite? For infinite sequences, features like
# count diverge.
#
public redef finite => size_option??
# number of entries in this set. May be undefined, i.e., a range of
# floating point numbers or an infinite set.
#
public size_option option i32 => nil
# does this set contain the given value?
#
public contains (e E) bool => abstract
# list representation of values in this set
#
public redef as_list list E => abstract
# add new element k to this set.
#
public add (k E) Set E =>
panic "*** NYI: REMOVE Set.add, we need some support for mutable Sets ***"
public redef as_string =>
if is_empty
"∅"
else
("\{"
+ (as_list.map String (x -> x.as_string)).fold(String.concat ";")
+ "}")
last changed: 2024-03-07