Skip to content

Commit

Permalink
Issue #1843 tests for "order by" for memory storage were passed. Issu…
Browse files Browse the repository at this point in the history
…e was fixed.
  • Loading branch information
andrii0lomakin committed Feb 12, 2014
1 parent b4afb9a commit 0d2f688
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ public OMVRBTreeEntry<K, V> getFirstEntry() {
* Returns the last Entry in the OMVRBTree (according to the OMVRBTree's key-sort function). Returns null if the OMVRBTree is
* empty.
*/
protected OMVRBTreeEntry<K, V> getLastEntry() {
public OMVRBTreeEntry<K, V> getLastEntry() {
OMVRBTreeEntry<K, V> p = root;
if (p != null)
while (p.getRight() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,36 +403,31 @@ private void getValuesBetweenAscOrder(Object rangeFrom, boolean fromInclusive, O

private void getValuesBetweenDescOrder(Object rangeFrom, boolean fromInclusive, Object rangeTo, boolean toInclusive,
ValuesTransformer<V> transformer, ValuesResultListener valuesResultListener) {
final OMVRBTreeEntry<Object, V> firstEntry;
final OMVRBTreeEntry<Object, V> lastEntry;

if (fromInclusive)
firstEntry = map.getHigherEntry(rangeFrom);
else
firstEntry = map.getCeilingEntry(rangeFrom, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);
final OMVRBTreeEntry<Object, V> firstEntry;

if (firstEntry == null)
return;
if (toInclusive)
firstEntry = map.getCeilingEntry(rangeTo, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);
else
firstEntry = map.getLowerEntry(rangeTo);

final int firstEntryIndex = map.getPageIndex();
if (firstEntry == null)
return;

final OMVRBTreeEntry<Object, V> lastEntry;
final int firstEntryIndex = map.getPageIndex();

if (toInclusive)
lastEntry = map.getCeilingEntry(rangeTo, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);
if (fromInclusive)
lastEntry = map.getLowerEntry(rangeFrom);
else
lastEntry = map.getLowerEntry(rangeTo);
lastEntry = map.getCeilingEntry(rangeFrom, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);

final int lastEntryIndex;
final int lastEntryIndex = map.getPageIndex();

if (lastEntry != null)
lastEntryIndex = map.getPageIndex();
else
lastEntryIndex = -1;

OMVRBTreeEntry<Object, V> entry = lastEntry;
map.setPageIndex(lastEntryIndex);
OMVRBTreeEntry<Object, V> entry = firstEntry;
map.setPageIndex(firstEntryIndex);

while (entry != null && !(entry.equals(firstEntry) && map.getPageIndex() == firstEntryIndex)) {
while (entry != null && !(entry.equals(lastEntry) && map.getPageIndex() == lastEntryIndex)) {
final V value = entry.getValue();

boolean cont = addToResult(transformer, valuesResultListener, value);
Expand Down Expand Up @@ -483,22 +478,24 @@ private void getValuesMajorAscOrder(Object fromKey, boolean isInclusive, ValuesT

private void getValuesMajorDescOrder(Object fromKey, boolean isInclusive, ValuesTransformer<V> transformer,
ValuesResultListener valuesResultListener) {
final OMVRBTreeEntry<Object, V> lastEntry = (OMVRBTreeEntry<Object, V>) map.lastEntry();
if (lastEntry == null)
final OMVRBTreeEntry<Object, V> firstEntry = map.getLastEntry();
if (firstEntry == null)
return;

final OMVRBTreeEntry<Object, V> firstEntry;
final OMVRBTreeEntry<Object, V> lastEntry;
final int firstEntryIndex = map.getPageIndex();

if (isInclusive)
firstEntry = map.getHigherEntry(fromKey);
lastEntry = map.getHigherEntry(fromKey);
else
firstEntry = map.getCeilingEntry(fromKey, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);
lastEntry = map.getCeilingEntry(fromKey, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);

final int firsEntryIndex = map.getPageIndex();
OMVRBTreeEntry<Object, V> entry = firstEntry;
final int lastEntryIndex = map.getPageIndex();

OMVRBTreeEntry<Object, V> entry = lastEntry;
map.setPageIndex(firstEntryIndex);

while (entry != null && !(entry.equals(firstEntry) && map.getPageIndex() == firsEntryIndex)) {
while (entry != null && !(entry.equals(lastEntry) && map.getPageIndex() == lastEntryIndex)) {
final V value = entry.getValue();
boolean cont = addToResult(transformer, valuesResultListener, value);
if (!cont)
Expand All @@ -524,45 +521,45 @@ public void getValuesMinor(Object toKey, boolean isInclusive, boolean ascSortOrd

private void getValuesMinorAscOrder(Object toKey, boolean isInclusive, ValuesTransformer<V> transformer,
ValuesResultListener valuesResultListener) {

final OMVRBTreeEntry<Object, V> firstEntry = map.getFirstEntry();
if (firstEntry == null)
return;

final int firstEntryIndex = map.getPageIndex();
final OMVRBTreeEntry<Object, V> lastEntry;

if (isInclusive)
lastEntry = map.getFloorEntry(toKey, OMVRBTree.PartialSearchMode.HIGHEST_BOUNDARY);
lastEntry = map.getHigherEntry(toKey);
else
lastEntry = map.getLowerEntry(toKey);

if (lastEntry == null)
return;
lastEntry = map.getCeilingEntry(toKey, OMVRBTree.PartialSearchMode.LOWEST_BOUNDARY);

OMVRBTreeEntry<Object, V> entry = lastEntry;
OMVRBTreeEntry<Object, V> entry = firstEntry;
final int lastEntryIndex = map.getPageIndex();
map.setPageIndex(firstEntryIndex);

while (entry != null) {
while (entry != null && !(entry.equals(lastEntry) && map.getPageIndex() == lastEntryIndex)) {
V value = entry.getValue();
boolean cont = addToResult(transformer, valuesResultListener, value);

if (!cont)
return;

entry = OMVRBTree.previous(entry);
entry = OMVRBTree.next(entry);
}
}

private void getValuesMinorDescOrder(Object toKey, boolean isInclusive, ValuesTransformer<V> transformer,
ValuesResultListener valuesResultListener) {
final OMVRBTreeEntry<Object, V> firstEntry = map.getFirstEntry();
if (firstEntry == null)
return;

final OMVRBTreeEntry<Object, V> lastEntry;
final OMVRBTreeEntry<Object, V> firstEntry;
if (isInclusive)
lastEntry = map.getHigherEntry(toKey);
firstEntry = map.getCeilingEntry(toKey, OMVRBTree.PartialSearchMode.LOWEST_BOUNDARY);
else
lastEntry = map.getCeilingEntry(toKey, OMVRBTree.PartialSearchMode.LOWEST_BOUNDARY);
firstEntry = map.getLowerEntry(toKey);

OMVRBTreeEntry<Object, V> entry = lastEntry;
final int lastPageIndex = map.getPageIndex();
OMVRBTreeEntry<Object, V> entry = firstEntry;

while (entry != null && !(entry.equals(lastEntry) && map.getPageIndex() == lastPageIndex)) {
while (entry != null) {
V value = entry.getValue();
boolean cont = addToResult(transformer, valuesResultListener, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ public OMVRBTreeEntry<K, V> getFirstEntry() {
* empty.
*/
@Override
protected OMVRBTreeEntry<K, V> getLastEntry() {
public OMVRBTreeEntry<K, V> getLastEntry() {
if (!entryPoints.isEmpty()) {
// FIND THE LAST ELEMENT STARTING FROM THE FIRST ENTRY-POINT IN MEMORY
final Map.Entry<K, OMVRBTreeEntryPersistent<K, V>> entry = entryPoints.lastEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<class name="com.orientechnologies.orient.test.database.auto.LinkMapIndexTest"/>
<class name="com.orientechnologies.orient.test.database.auto.SQLIndexWithoutSchemaTest"/>
<class name="com.orientechnologies.orient.test.database.auto.IndexTxTest"/>
<class name="com.orientechnologies.orient.test.database.auto.OrderByIndexReuseTest"/>
</classes>
</test>
<test name="Dictionary">
Expand Down

0 comments on commit 0d2f688

Please sign in to comment.