From: Josh Suereth <joshua.suer...@gmail.com>
Date: Tue, 19 Jul 2011 17:21:51 -0400
Local: Tues, Jul 19 2011 5:21 pm
Subject: Re: [scala-user] Performance and complexity
Your Java version doesn't abstract over the size of the slice. I'm working on a better scala version, but part of the pain is avoiding the - Josh 2011/7/19 Cédric Beust ♔ <ced...@beust.com> > Hi everyone,
> I became intrigued with a problem that Mark Nelson posted to the list last > The problem is simple: eliminate all the occurrences of the sequence (26, > Of all the solutions proposed, only the one proposed by Ruediger Keller > def eliminate[@specialized(Byte) T : ClassManifest](xs: Array[T], > } > Daniel Sobral also offered a correct solution but it only works on Byte, so > I became curious to see what kind of complexity the functional solution > private static List<Integer> eliminate(List<Integer> value) { > List<Integer> result = Lists.newArrayList(); > for (int i = 0; i < value.size(); i++) { > if (value.get(i) == SLICE.get(0) && value.get(i + 1) == SLICE.get(1) > && value.get(i + 2) == SLICE.get(2)) { > i += 2; > } else { > result.add(value.get(i)); > } > } > return result; > } > I decided to run a few benchmarks and the results were surprising. I tried > The imperative version solves the problem for lists up to 10M of elements > However, the Scala version above takes 2 seconds for 1000 elements and > Can someone suggest additional functional solutions to this problem that > Also, what are the complexities of these functional solutions? > -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||