From C++14 and Java 1.8
bearophile
bearophileHUGS at lycos.com
Sun Apr 21 05:08:53 PDT 2013
Through Reddit I've seen this interesting report about C++14:
http://isocpp.org/blog/2013/04/trip-report-iso-c-spring-2013-meeting
Variable templates: sometimes in D I've felt a little desire for
a shorter syntax, a templated alias:
alias Foo(T) = Bar!(T, "red");
But in the end I think this that syntax sugar isn't so necessary.
- - - - - - - - -
Dynamic Arrays: they replace the variable-sized stack-allocated
arrays of C99. I'd like something like this in D2 (Issue 9832)
with a better integration with the type system.
- - - - - - - - -
optional<T>: see the little maybeTo helper function I have
suggested in
http://d.puremagic.com/issues/show_bug.cgi?id=6840
-----------------------------------
From another thread about the future Java 1.8 I've seen Java
parallelSort:
http://blog.sanaulla.info/2013/04/08/arrays-sort-versus-arrays-parallelsort/
That blog post explains quickly how it works:
<<
Arrays#parallelSort uses Fork/Join framework introduced in Java 7
to assign the sorting tasks to multiple threads available in the
thread pool. This is called eating your own dog food. Fork/Join
implements a work stealing algorithm where in a idle thread can
steal tasks queued up in another thread.
An overview of Arrays#parallelSort:
The method uses a threshold value and any array of size lesser
than the threshold value is sorted using the Arrays#sort() API
(i.e sequential sorting). And the threshold is calculated
considering the parallelism of the machine, size of the array and
is calculated as:
private static final int getSplitThreshold(int n) {
int p = ForkJoinPool.getCommonPoolParallelism();
int t = (p > 1) ? (1 + n / (p << 3)) : n;
return t < MIN_ARRAY_SORT_GRAN ? MIN_ARRAY_SORT_GRAN : t;
}
Once its decided whether to sort the array in parallel or in
serial, its now to decide how to divide the array in to multiple
parts and then assign each part to a Fork/Join task which will
take care of sorting it and then another Fork/Join task which
will take care of merging the sorted arrays. The implementation
in JDK 8 uses this approach:
- Divide the array into 4 parts.
- Sort the first two parts and then merge them.
- Sort the next two parts and then merge them.
And the above steps are repeated recursively with each part until
the size of the part to sort is not lesser than the threshold
value calculated above.
>>
I think it's worth adding something similar as strategy of
std.algorithm.sort.
Bye,
bearophile
More information about the Digitalmars-d
mailing list