| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.index; |
| 7 |
|
| 8 |
import org.h2.message.DbException; |
| 9 |
import org.h2.result.Row; |
| 10 |
import org.h2.result.SearchRow; |
| 11 |
import org.h2.value.Value; |
| 12 |
import org.h2.value.ValueBigint; |
| 13 |
|
| 14 |
/** |
| 15 |
* The cursor implementation for the range index. |
| 16 |
*/ |
| 17 |
class RangeCursor implements Cursor { |
| 18 |
|
| 19 |
private boolean beforeFirst; |
| 20 |
private long current; |
| 21 |
private Row currentRow; |
| 22 |
private final long start, end, step; |
| 23 |
|
| 24 |
RangeCursor(long start, long end, long step) { |
| 25 |
this.start = start; |
| 26 |
this.end = end; |
| 27 |
this.step = step; |
| 28 |
beforeFirst = true; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public Row get() { |
| 33 |
return currentRow; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public SearchRow getSearchRow() { |
| 38 |
return currentRow; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public boolean next() { |
| 43 |
if (beforeFirst) { |
| 44 |
beforeFirst = false; |
| 45 |
current = start; |
| 46 |
} else { |
| 47 |
current += step; |
| 48 |
} |
| 49 |
currentRow = Row.get(new Value[]{ValueBigint.get(current)}, 1); |
| 50 |
return step > 0 ? current <= end : current >= end; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public boolean previous() { |
| 55 |
throw DbException.getInternalError(toString()); |
| 56 |
} |
| 57 |
|
| 58 |
} |