Commit fa11805d authored by HankG's avatar HankG

Straight port of regexredux but only running empty case

parent e8d4f78a
Revised BSD license
This is a specific instance of the Open Source Initiative (OSI) BSD license template
http://www.opensource.org/licenses/bsd-license.php
Copyright © 2004-2008 Brent Fulgham, 2005-2017 Isaac Gouy
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of "The Computer Language Benchmarks Game" nor the name of "The Computer Language Shootout Benchmarks" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*
The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
Based on Java regex-dna program (#5) contributed by Michael Stover
Contributed by Hank Grabowski
*/
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.HashMap
import java.util.regex.Pattern
object regexredux {
private val replacements = HashMap<String, String>()
init {
replacements.put("tHa[Nt]", "<4>")
replacements.put("aND|caN|Ha[DS]|WaS", "<3>")
replacements.put("a[NSt]|BY", "<2>")
replacements.put("<[^>]*>", "|")
replacements.put("\\|[^|][^|]*\\|", "-")
}
@Throws(IOException::class)
@JvmStatic
fun main(args: Array<String>) {
val r = BufferedReader(InputStreamReader(System.`in`,
"US-ASCII"))
val sb = StringBuffer()
var line: String = ""
while ({line = r.readLine(); line}() != null) {
sb.append(line)
sb.append("\n")
}
val initialLength = sb.length
val sequence = sb.toString().replace(">.*\n|\n".toRegex(), "")
val codeLength = sequence.length
val variants = arrayOf("agggtaaa|tttaccct", "[cgt]gggtaaa|tttaccc[acg]", "a[act]ggtaaa|tttacc[agt]t", "ag[act]gtaaa|tttac[agt]ct", "agg[act]taaa|ttta[agt]cct", "aggg[acg]aaa|ttt[cgt]ccct", "agggt[cgt]aa|tt[acg]accct", "agggta[cgt]a|t[acg]taccct", "agggtaa[cgt]|[acg]ttaccct")
val results = HashMap<String, Int>()
val tg = ThreadGroup("regexWork")
for (v in variants) {
object : Thread(tg, v) {
override fun run() {
var count = 0
val m = Pattern.compile(v).matcher(sequence)
while (m.find()) {
count++
}
results.put(v, count)
}
}.start()
}
val threads = arrayOfNulls<Thread>(variants.size)
tg.enumerate(threads)
for (t in threads) {
try {
t?.join()
} catch (e: InterruptedException) {
// noop
}
}
tg.destroy()
for (variant in variants) {
println(variant + " " + results[variant])
}
val buf = StringBuffer()
val m = Pattern.compile("[WYKMSRBDVHN]").matcher(sequence)
while (m.find()) {
m.appendReplacement(buf, "")
buf.append(replacements[m.group()])
}
m.appendTail(buf)
println()
println(initialLength)
println(codeLength)
println(buf.length)
}
}
......@@ -73,6 +73,7 @@ onlydirs =
knucleotide
mandelbrot
pidigits
regexredux
......@@ -139,6 +140,7 @@ pidigits = 1 100 1000 2500 5000 10000
knucleotide = ../knucleotide-input.txt
regexdna = ../regexdna-input.txt
regexredux = ../regexdna-input.txt
revcomp = ../revcomp-input.txt
......
Revised BSD license
This is a specific instance of the Open Source Initiative (OSI) BSD license template
http://www.opensource.org/licenses/bsd-license.php
Copyright © 2004-2008 Brent Fulgham, 2005-2017 Isaac Gouy
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of "The Computer Language Benchmarks Game" nor the name of "The Computer Language Shootout Benchmarks" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*
The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
regex-dna program contributed by Michael Stover
converted from regex-dna program
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class regexredux {
private static final Map<String, String> replacements = new HashMap<String, String>();
static {
replacements.put("tHa[Nt]", "<4>");
replacements.put("aND|caN|Ha[DS]|WaS", "<3>");
replacements.put("a[NSt]|BY", "<2>");
replacements.put("<[^>]*>", "|");
replacements.put("\\|[^|][^|]*\\|", "-");
}
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in,
"US-ASCII"));
StringBuffer sb = new StringBuffer();
String line;
while ((line = r.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
int initialLength = sb.length();
final String sequence = sb.toString().replaceAll(">.*\n|\n", "");
int codeLength = sequence.length();
String[] variants = { "agggtaaa|tttaccct", "[cgt]gggtaaa|tttaccc[acg]",
"a[act]ggtaaa|tttacc[agt]t", "ag[act]gtaaa|tttac[agt]ct",
"agg[act]taaa|ttta[agt]cct", "aggg[acg]aaa|ttt[cgt]ccct",
"agggt[cgt]aa|tt[acg]accct", "agggta[cgt]a|t[acg]taccct",
"agggtaa[cgt]|[acg]ttaccct" };
final Map<String, Integer> results = new HashMap<String, Integer>();
ThreadGroup tg = new ThreadGroup("regexWork");
for (String v : variants) {
final String variant = v;
new Thread(tg, v) {
@Override
public void run() {
int count = 0;
Matcher m = Pattern.compile(variant).matcher(sequence);
while (m.find()) {
count++;
}
results.put(variant, count);
}
}.start();
}
Thread[] threads = new Thread[variants.length];
tg.enumerate(threads);
for (Thread t : threads) {
try {
if (t != null) {
t.join();
}
} catch (InterruptedException e) {
// noop
}
}
tg.destroy();
for (String variant : variants) {
System.out.println(variant + " " + results.get(variant));
}
StringBuffer buf = new StringBuffer();
Matcher m = Pattern.compile("[WYKMSRBDVHN]").matcher(sequence);
while (m.find()) {
m.appendReplacement(buf, "");
buf.append(replacements.get(m.group()));
}
m.appendTail(buf);
System.out.println();
System.out.println(initialLength);
System.out.println(codeLength);
System.out.println(buf.length());
}
}
/*
The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
Based on Java regex-dna program (#5) contributed by Michael Stover
Contributed by Hank Grabowski
*/
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.HashMap
import java.util.regex.Pattern
object regexredux {
private val replacements = HashMap<String, String>()
init {
replacements.put("tHa[Nt]", "<4>")
replacements.put("aND|caN|Ha[DS]|WaS", "<3>")
replacements.put("a[NSt]|BY", "<2>")
replacements.put("<[^>]*>", "|")
replacements.put("\\|[^|][^|]*\\|", "-")
}
@Throws(IOException::class)
@JvmStatic
fun main(args: Array<String>) {
val r = BufferedReader(InputStreamReader(System.`in`,
"US-ASCII"))
val sb = StringBuffer()
var line: String = ""
while ({line = r.readLine(); line}() != null) {
sb.append(line)
sb.append("\n")
}
val initialLength = sb.length
val sequence = sb.toString().replace(">.*\n|\n".toRegex(), "")
val codeLength = sequence.length
val variants = arrayOf("agggtaaa|tttaccct", "[cgt]gggtaaa|tttaccc[acg]", "a[act]ggtaaa|tttacc[agt]t", "ag[act]gtaaa|tttac[agt]ct", "agg[act]taaa|ttta[agt]cct", "aggg[acg]aaa|ttt[cgt]ccct", "agggt[cgt]aa|tt[acg]accct", "agggta[cgt]a|t[acg]taccct", "agggtaa[cgt]|[acg]ttaccct")
val results = HashMap<String, Int>()
val tg = ThreadGroup("regexWork")
for (v in variants) {
object : Thread(tg, v) {
override fun run() {
var count = 0
val m = Pattern.compile(v).matcher(sequence)
while (m.find()) {
count++
}
results.put(v, count)
}
}.start()
}
val threads = arrayOfNulls<Thread>(variants.size)
tg.enumerate(threads)
for (t in threads) {
try {
t?.join()
} catch (e: InterruptedException) {
// noop
}
}
tg.destroy()
for (variant in variants) {
println(variant + " " + results[variant])
}
val buf = StringBuffer()
val m = Pattern.compile("[WYKMSRBDVHN]").matcher(sequence)
while (m.find()) {
m.appendReplacement(buf, "")
buf.append(replacements[m.group()])
}
m.appendTail(buf)
println()
println(initialLength)
println(codeLength)
println(buf.length)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment