News News News Messages: 9 Messages: 9 Messages: 9
Printer friendly Printer friendly Printer friendly
Post reply Post reply Post reply
XML XML XML ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Message #224524
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
void quickSort(final FastTable<? extends Comparable> table) {
final int size = table.size();
if (size < 100) {
table.sort(); // Direct quick sort.
} else {
// Splits table in two and sort both part concurrently.
final FastTable<? extends Comparable> t1 = FastTable.newInstance();
final FastTable<? extends Comparable> t2 = FastTable.newInstance();
ConcurrentContext.enter();
try {
ConcurrentContext.execute(new Logic() {
public void run() {
t1.addAll(table.subList(0, size / 2));
quickSort(t1); // Recursive.
}
});
ConcurrentContext.execute(new Logic() {
public void run() {
t2.addAll(table.subList(size / 2, size));
quickSort(t2); // Recursive.
}
});
} finally {
ConcurrentContext.exit();
}
// Merges results.
for (int i=0, i1=0, i2=0; i < size; i++) {
if (i1 >= t1.size()) {
table.set(i, t2.get(i2++));
} else if (i2 >= t2.size()) {
table.set(i, t1.get(i1++));
} else {
Comparable o1 = t1.get(i1);
Comparable o2 = t2.get(i2);
if (o1.compareTo(o2) < 0) {
table.set(i, o1);
i1++;
} else {
table.set(i, o2);
i2++;
}
}
}
FastTable.recycle(t1);
FastTable.recycle(t2);
}
}
Message #224529
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Message #224536
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Message #224537
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Message #224554
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Message #224608
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
<?xml version="1.0" encoding="UTF-8"?>
<!--
(c) Copyright 2006 Pervasive Software Inc. All rights reserved.
-->
<AssemblySpecification
xmlns="http://www.pervasive.com/xmlns/dataflow/sdk"
schemaVersion="1.0"
package="tests.learning"
name="SortTest">
<Doc>
<Author>mwalker</Author>
<DateCreated>2006-12-23</DateCreated>
<Description>Demonstrates the sort operator.</Description>
</Doc>
<Operator>
<Contract>
</Contract>
<Composition>
<Assembly instance="source" type="com.pervasive.dataflow.operators.source.GenerateRandomRows">
<Set target="outputType" value="int"/>
<Set target="rowCount" value="10"/>
</Assembly>
<Assembly instance="sort" type="com.pervasive.dataflow.operators.sort.Sort">
<Set target="partitionCount" value="0"/>
<Set target="sortAlgorithm" value="merge"/>
<Link instance="source" source="output" target="input"/>
</Assembly>
<Assembly instance="log" type="com.pervasive.dataflow.operators.sink.LogRows">
<Set target="logFrequency" value="1"/>
<Link instance="sort" source="output" target="input"/>
</Assembly>
</Composition>
</Operator>
</AssemblySpecification>
C:\workspace\testing>dfe -cp build\dist\testing.jar tests.learning.SortTest
2006-12-23 08:42:11.419 INFO SortTest.log.logType.customize Input type is int
2006-12-23 08:42:11.740 INFO SortTest.sort.sortDispatcher.run Sorted 10 rows in memory
2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run There were 10 rows sinked
2006-12-23 08:42:11.970 INFO com.pervasive.dataflow.tools.cli.DFECLI.processLeftoverArgs Job runtime: 1.815
2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 10 is 2022775704 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 9 is 1962638078 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 8 is 1711199546 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 7 is 1570617054 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 6 is 980354890 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 5 is 185780738 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 4 is 175398363 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 3 is 15967868 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 2 is -982258612 2006-12-23 08:42:11.960 INFO SortTest.log.logRows.run Row 1 is -1261162224
Message #224610
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Message #224694
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
public class RandomIntegers {
public static Integer[] getSortedRandomIntegers(int num) {
Random random = new Random();
Integer[] ret = new Integer[num];
for(int i=0;i<num;i++)
ret[i] = random.nextInt();
Arrays.sort(ret);
return ret;
}
public static void main(String... args) {
int num = args.length> 0 ? Integer.parseInt(args[0]) : 10;
System.out.println("Random numbers length= "+num);
System.out.println(Arrays.asList(getSortedRandomIntegers(num)));
}
}
Message #224699
Post reply Post reply Post reply
Go to top Go to top Go to top ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com ![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.theserverside.com%2Ftt%2Fskin%2Fimages%2Fbar_end.gif)
Paul Rene Jørgensen talks about UseMon, an efficient, open-source, real-time JVM performance monitoring agent. (October 2, Tech Brief)
In this podcast, John Davies will cover several case studies of extreme transaction processing, low latency and high performance systems and offer insight into what we might expect to see in mainstream in the near future. (September 29, Podcast)
Learn about Mule, ServiceMix, Synapse, Petal and other OpenESBs in Action from authors Tijs Rademakers and Jos Dirksen - Tech Brief about their new book. (September 24, Tech Brief)
In this podcast, Holly Cummins will introduce a number of tools for identifying and fixing common Java performance problems. (September 17, Podcast)
In this podcast, TheServerSide.com editor Peter Varhol asks Terracotta CTO Ari Zilka about how the software works and what it can be used for. (September 15, Podcast)
Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.You are viewing a mobilized version of this site...
View original page here