Skip to content

Questions

schrdrl edited this page Feb 1, 2022 · 7 revisions

`Prepends`
def +:(elem: AInt, al2: AList) : AList = ACons(elem, al2 )


`Appends`
def :(al1: AList, elem: AInt) : Set[AList] = al1 match {
case ANil => Set(ACons(elem, ANil))
case ACons(h,t) => if(:
(t, elem).tail.nonEmpty) Set(ACons(h, :(t, elem).head), ACons(h, :(t, elem).tail.head))
else Set(ACons(h, :+(t, elem).head))
case AMany(e) => Set(ACons(elem, ANil), ACons(e, AMany(intervals.union_Interval(e, elem))))
//1. case: ANil → ACons(elem, ANil)
//2. case: ACons(e, AMany(e)) → ACons(e, ACons(elem, ANil)) oder ACons(e, ACons(elem, AMany(e))) oder ACons(e, AMany(e union elem))
}


`Concats`
def +(al1: AList, al2: AList): Set[AList] = (al1, al2) match {
case (ANil, ANil) => Set(ANil)
case (ANil, ACons(h,t)) => Set(al2)
case (ACons(h,t), ANil) => Set(al1)
case (ANil, AMany(e)) => Set(al2)
case (AMany(e), ANil) => Set(al1)
case (AMany(e1), AMany(e2)) => Set(AMany(intervals.union_Interval(e1,e2)))
case (AMany(e1), ACons(h,t)) => Set(al2, ACons(e1, union_AList(al1, al2)))
//1. case: ANil, 2. case: ACons(e,AMany(e1))
case (ACons(h,t), AMany(e2)) => if(
(t,ACons(e2,AMany(e2))).tail.nonEmpty) Set(ACons(h, +(t,ACons(e2,AMany(e2))).head), ACons(h, +(t,ACons(e2,AMany(e2))).tail.head)) else Set(al1, ACons(h,(t,ACons(e2,AMany(e2))).head))
case (ACons(h1, t1), ACons(h2, t2)) => if(
(t1, al2).tail.nonEmpty) Set(ACons(h1, +(t1, al2).head),ACons(h1, +(t1, al2).tail.head)) else Set(ACons(h1, +(t1, al2).head))
}

Clone this wiki locally