container/mutable_tree_map/Entry.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 Entry
#
# -----------------------------------------------------------------------
# Entry -- an entry of a mutable tree map
#
module Entry(module key KEY, module val VAL) ref is
# reference to the left subtree at this entry, or, if it is empty, nil
#
module left := LM.env.new (option Entry) nil
# reference to the right subtree at this entry, or if it is empty, nil
#
module right := LM.env.new (option Entry) nil
# height of the subtree whose root is this entry
#
module height := LM.env.new i32 0
# get the value stored in this submap at key k, nil if k is not a key
# in this submap
#
module get(k KEY) =>
if k < key
left.get.bind VAL (e -> e.get k)
else if key < k
right.get.bind VAL (e -> e.get k)
else
val
# get a sequence of all key/value pairs in this Entry
#
module items Sequence (tuple KEY VAL) =>
[(key,val)] ++
(left.get.bind (Sequence (tuple KEY VAL)) x->x.items).or_else (list (tuple KEY VAL)).empty ++
(right.get.bind (Sequence (tuple KEY VAL)) x->x.items).or_else (list (tuple KEY VAL)).empty
last changed: 2025-01-23