Account Options

  1. Anmelden
Das alte Google Groups wird demnächst nicht mehr unterstützt. Die neue Version ist jedoch nicht kompatibel mit Ihrem Browser.
Google Groups-Startseite
« Google Groups-Startseite
Nachricht von Diskussion Performance and complexity

Received: by 10.224.195.9 with SMTP id ea9mr8016122qab.27.1311111709449;
        Tue, 19 Jul 2011 14:41:49 -0700 (PDT)
X-BeenThere: scala-user@googlegroups.com
Received: by 10.224.20.10 with SMTP id d10ls400849qab.4.gmail; Tue, 19 Jul
 2011 14:41:45 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.224.197.134 with SMTP id ek6mr616014qab.5.1311111705799; Tue,
 19 Jul 2011 14:41:45 -0700 (PDT)
Received: by f35g2000vbr.googlegroups.com with HTTP; Tue, 19 Jul 2011 14:41:45
 -0700 (PDT)
Date: Tue, 19 Jul 2011 14:41:45 -0700 (PDT)
In-Reply-To: <CAP_xLa1v8ELB7eAXCjubt91Y=Qt7-X=h+K=UB8nwHAgPaPn0hw@mail.gmail.com>
References: <CAOphgJAiUb5Pfx2Rbtc4K7_gk=EvzfnXmJpm89t_sO5XS9u_Mg@mail.gmail.com>
 <CAP_xLa1v8ELB7eAXCjubt91Y=Qt7-X=h+K=UB8nwHAgPaPn0hw@mail.gmail.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1;
 Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR
 3.0.30729; Media Center PC 6.0; Media Center PC 5.0; SLCC1; .NET4.0E; Tablet
 PC 2.0; .NET4.0C),gzip(gfe)
Message-ID: <cef6c4eb-6287-4f1e-a871-2e5308c0dc50@f35g2000vbr.googlegroups.com>
Subject: Re: Performance and complexity
From: Dave <dave.mahabiers...@hotmail.com>
To: scala-user <scala-user@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

Maybe you could optimize the fucntion it for tail call recursion

package eliminate

import scala.annotation.tailrec

object Main extends App {

@tailrec
def eliminate[@specialized(Byte) T : ClassManifest](acc: Array[T], xs:
Array[T], slice: Seq[T]): Array[T] = {
  val i = xs indexOfSlice slice
  i match {
    case -1 => acc ++ xs
    case _  => eliminate(acc ++ xs.take(i), xs.drop(i + slice.length),
slice)
  }
}

val acc : Array[Byte] = Array.empty
val ar = List[Byte](1, 2, 26, 20, 64, 3, 26, 20, 64, 4).toArray
val sl = Seq[Byte](26, 20, 64)
val el = eliminate[Byte](acc, ar, sl)
println(el.toList)

}