Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Fixes HPPCRT-45
Browse files Browse the repository at this point in the history
  • Loading branch information
vsonnier committed Jul 20, 2015
1 parent 0172997 commit 8ba3b37
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 281 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[0.7.1]
** Bug fixes
HPPCRT-45: API with intervals arguments is inconsistent with JDK conventions.

[0.7.0]
This release fix important bugs, and align on some refactorings or changes of HPPC v0.7.1, hence the version number.

Expand Down
6 changes: 3 additions & 3 deletions hppcrt-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<artifactId>hppcrt-benchmarks</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>
<packaging>jar</packaging>

<name>HPPC-RT Benchmarks</name>
Expand All @@ -24,7 +24,7 @@
<commons-lang.version>2.6</commons-lang.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jmh.version>1.10.2</jmh.version>
<jmh.version>1.10.3</jmh.version>
<javac.target>1.7</javac.target>
<uberjar.name>benchmarks</uberjar.name>

Expand Down
4 changes: 2 additions & 2 deletions hppcrt-template-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-template-processor</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>
<packaging>jar</packaging>

<name>HPPC-RT Template Processor</name>
Expand Down
4 changes: 2 additions & 2 deletions hppcrt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<parent>
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt-parent</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Project info. -->
<groupId>com.github.vsonnier</groupId>
<artifactId>hppcrt</artifactId>
<version>0.7.0</version>
<version>0.7.1</version>
<packaging>jar</packaging>

<name>HPPC-RT Collections</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/
/*! ${TemplateOptions.generatedAnnotation} !*/
public class KTypeArrayDeque<KType>
extends AbstractKTypeCollection<KType> implements KTypeDeque<KType>, KTypeIndexedContainer<KType>, Cloneable
extends AbstractKTypeCollection<KType> implements KTypeDeque<KType>, KTypeIndexedContainer<KType>, Cloneable
{
/**
* Internal array for storing elements.
Expand All @@ -65,8 +65,8 @@ public class KTypeArrayDeque<KType>
KType []
#else !*/
Object[]
/*! #end !*/
buffer;
/*! #end !*/
buffer;

/**
* The index of the element at the head of the deque or an
Expand Down Expand Up @@ -751,14 +751,18 @@ public <T extends KTypeProcedure<? super KType>> T forEach(final T procedure) {
@Override
public <T extends KTypeProcedure<? super KType>> T forEach(final T procedure, final int fromIndex, final int toIndex) {

if (fromIndex >= toIndex) {
checkRangeBounds(fromIndex, toIndex);

throw new IllegalArgumentException("Index fromIndex " + fromIndex + " is >= toIndex " + toIndex);
if (fromIndex == toIndex) {

return procedure; //nothing to do
}

final int bufferPositionStart = indexToBufferPosition(fromIndex);

final int endBufferPosInclusive = indexToBufferPosition(toIndex - 1); //must be a valid index

internalForEach(procedure, indexToBufferPosition(fromIndex), oneRight(endBufferPosInclusive, this.buffer.length));
internalForEach(procedure, bufferPositionStart, oneRight(endBufferPosInclusive, this.buffer.length));

return procedure;
}
Expand Down Expand Up @@ -791,14 +795,18 @@ public <T extends KTypePredicate<? super KType>> T forEach(final T predicate) {
@Override
public <T extends KTypePredicate<? super KType>> T forEach(final T predicate, final int fromIndex, final int toIndex) {

if (fromIndex >= toIndex) {
checkRangeBounds(fromIndex, toIndex);

if (fromIndex == toIndex) {

throw new IllegalArgumentException("Index fromIndex " + fromIndex + " is >= toIndex " + toIndex);
return predicate; //nothing to do
}

final int bufferPositionStart = indexToBufferPosition(fromIndex);

final int endBufferPosInclusive = indexToBufferPosition(toIndex - 1); //must be a valid index

internalForEach(predicate, indexToBufferPosition(fromIndex), oneRight(endBufferPosInclusive, this.buffer.length));
internalForEach(predicate, bufferPositionStart, oneRight(endBufferPosInclusive, this.buffer.length));

return predicate;
}
Expand Down Expand Up @@ -1035,7 +1043,7 @@ private boolean allIndexesEqual(final KTypeIndexedContainer<KType> b1, final KTy
* instead of using a constructor).
*/
public static/* #if ($TemplateOptions.KTypeGeneric) */<KType> /* #end */
KTypeArrayDeque<KType> newInstance() {
KTypeArrayDeque<KType> newInstance() {
return new KTypeArrayDeque<KType>();
}

Expand All @@ -1044,15 +1052,15 @@ KTypeArrayDeque<KType> newInstance() {
* instead of using a constructor).
*/
public static/* #if ($TemplateOptions.KTypeGeneric) */<KType> /* #end */
KTypeArrayDeque<KType> newInstance(final int initialCapacity) {
KTypeArrayDeque<KType> newInstance(final int initialCapacity) {
return new KTypeArrayDeque<KType>(initialCapacity);
}

/**
* Create a new deque by pushing a variable number of arguments to the end of it.
*/
public static/* #if ($TemplateOptions.KTypeGeneric) */<KType> /* #end */
KTypeArrayDeque<KType> from(final KType... elements) {
KTypeArrayDeque<KType> from(final KType... elements) {
final KTypeArrayDeque<KType> coll = new KTypeArrayDeque<KType>(elements.length);
coll.addLast(elements);
return coll;
Expand All @@ -1062,7 +1070,7 @@ KTypeArrayDeque<KType> from(final KType... elements) {
* Create a new deque by pushing a variable number of arguments to the end of it.
*/
public static/* #if ($TemplateOptions.KTypeGeneric) */<KType> /* #end */
KTypeArrayDeque<KType> from(final KTypeContainer<KType> container) {
KTypeArrayDeque<KType> from(final KTypeContainer<KType> container) {
return new KTypeArrayDeque<KType>(container);
}

Expand All @@ -1081,21 +1089,27 @@ KTypeArrayDeque<KType> from(final KTypeContainer<KType> container) {
*/
public void sort(final int beginIndex, final int endIndex) {

if (endIndex - beginIndex > 1) {
//Fast path : if the actual indices matching [beginIndex; endIndex[
//in the underlying buffer are in increasing order (means there is no folding of buffer in the interval),
// use quicksort array version directly.
final int bufferPosStart = indexToBufferPosition(beginIndex);
final int bufferPosEndInclusive = indexToBufferPosition(endIndex - 1); //must be a valid index
checkRangeBounds(beginIndex, endIndex);

if (bufferPosEndInclusive > bufferPosStart) {
if (beginIndex == endIndex) {

KTypeSort.quicksort(this.buffer, bufferPosStart, bufferPosEndInclusive + 1);
} else {
//Use the slower KTypeIndexedContainer sort
KTypeSort.quicksort(this, beginIndex, endIndex);
}
return; //nothing to do
}

//Fast path : if the actual indices matching [beginIndex; endIndex[
//in the underlying buffer are in increasing order (means there is no folding of buffer in the interval),
// use quicksort array version directly.
final int bufferPosStart = indexToBufferPosition(beginIndex);
final int bufferPosEndInclusive = indexToBufferPosition(endIndex - 1); //must be a valid index

if (bufferPosEndInclusive > bufferPosStart) {

KTypeSort.quicksort(this.buffer, bufferPosStart, bufferPosEndInclusive + 1);
} else {
//Use the slower KTypeIndexedContainer sort
KTypeSort.quicksort(this, beginIndex, endIndex);
}

}

/**
Expand All @@ -1112,26 +1126,32 @@ public void sort(final int beginIndex, final int endIndex) {
public void sort(final int beginIndex, final int endIndex,
/*! #if ($TemplateOptions.KTypeGeneric) !*/
final Comparator<? super KType>
/*! #else
KTypeComparator<? super KType>
#end !*/
comp) {
/*! #else
KTypeComparator<? super KType>
#end !*/
comp) {

if (endIndex - beginIndex > 1) {
//Fast path : if the actual indices matching [beginIndex; endIndex[
//in the underlying buffer are in increasing order (means there is no folding of buffer in the interval),
// use quicksort array version directly.
final int bufferPosStart = indexToBufferPosition(beginIndex);
final int bufferPosEndInclusive = indexToBufferPosition(endIndex - 1); //must be valid indices
checkRangeBounds(beginIndex, endIndex);

if (bufferPosEndInclusive > bufferPosStart) {
if (beginIndex == endIndex) {

KTypeSort.quicksort(Intrinsics.<KType[]> cast(this.buffer), bufferPosStart, bufferPosEndInclusive + 1, comp);
} else {
//Use the slower KTypeIndexedContainer sort
KTypeSort.quicksort(this, beginIndex, endIndex, comp);
}
return; //nothing to do
}

//Fast path : if the actual indices matching [beginIndex; endIndex[
//in the underlying buffer are in increasing order (means there is no folding of buffer in the interval),
// use quicksort array version directly.
final int bufferPosStart = indexToBufferPosition(beginIndex);
final int bufferPosEndInclusive = indexToBufferPosition(endIndex - 1); //must be valid indices

if (bufferPosEndInclusive > bufferPosStart) {

KTypeSort.quicksort(Intrinsics.<KType[]> cast(this.buffer), bufferPosStart, bufferPosEndInclusive + 1, comp);
} else {
//Use the slower KTypeIndexedContainer sort
KTypeSort.quicksort(this, beginIndex, endIndex, comp);
}

}

/**
Expand Down Expand Up @@ -1298,12 +1318,15 @@ private void removeBufferIndicesRange(final int fromBufferIndex, final int toBuf
@Override
public void removeRange(final int fromIndex, final int toIndex) {

if (fromIndex >= toIndex) {
checkRangeBounds(fromIndex, toIndex);

if (fromIndex == toIndex) {

throw new IllegalArgumentException("Index fromIndex " + fromIndex + " is >= toIndex " + toIndex);
return; //nothing to do
}

final int bufferPositionStart = indexToBufferPosition(fromIndex);

final int bufferPositionEndInclusive = indexToBufferPosition(toIndex - 1); //must be a valid index

removeBufferIndicesRange(bufferPositionStart, oneRight(bufferPositionEndInclusive, this.buffer.length));
Expand Down Expand Up @@ -1360,6 +1383,24 @@ private int indexToBufferPosition(final int index) {
return (int) bufferPos;
}

private void checkRangeBounds(final int beginIndex, final int endIndex) {

if (beginIndex > endIndex) {

throw new IllegalArgumentException("Index beginIndex " + beginIndex + " is > endIndex " + endIndex);
}

if (beginIndex < 0) {

throw new IndexOutOfBoundsException("Index beginIndex < 0");
}

if (endIndex > size()) {

throw new IndexOutOfBoundsException("Index endIndex " + endIndex + " out of bounds [" + 0 + ", " + size() + "].");
}
}

/*! #if ($TemplateOptions.declareInline("oneLeft(index, modulus)", "<*>==>(index >= 1) ? index - 1 : modulus - 1")) !*/
/**
* Move one index to the left, wrapping around buffer of size modulus.
Expand Down
Loading

0 comments on commit 8ba3b37

Please sign in to comment.