@@ -123,6 +123,7 @@ public class TripleStore implements Closeable {
123123 public static final int CONTEXT_IDX = 3 ;
124124
125125 static final int MAX_KEY_LENGTH = 4 * 9 ;
126+ static final long NO_PREVIOUS_ID = Long .MIN_VALUE ;
126127
127128 /**
128129 * The default triple indexes.
@@ -812,7 +813,8 @@ protected void filterUsedIds(Collection<Long> ids) throws IOException {
812813 maxKey .mv_data (maxKeyBuf );
813814
814815 keyBuf .clear ();
815- index .getMinKey (keyBuf , subj , pred , obj , context , 0 , 0 , 0 , 0 );
816+ index .getMinKey (keyBuf , subj , pred , obj , context , NO_PREVIOUS_ID , NO_PREVIOUS_ID ,
817+ NO_PREVIOUS_ID , NO_PREVIOUS_ID );
816818 keyBuf .flip ();
817819
818820 // set cursor to min key
@@ -918,7 +920,8 @@ private double estimateWithTransaction(Pool pool, Statistics statistics, MemoryS
918920 statistics .reset ();
919921
920922 keyBuf .clear ();
921- index .getMinKey (keyBuf , subj , pred , obj , context , 0 , 0 , 0 , 0 );
923+ index .getMinKey (keyBuf , subj , pred , obj , context , NO_PREVIOUS_ID , NO_PREVIOUS_ID , NO_PREVIOUS_ID ,
924+ NO_PREVIOUS_ID );
922925 keyBuf .flip ();
923926
924927 int dbi = index .getDB (explicit );
@@ -1888,7 +1891,8 @@ KeyBuilder keyBuilder(long subj, long pred, long obj, long context) {
18881891
18891892 @ Override
18901893 public void writeMin (ByteBuffer buffer ) {
1891- getMinKey (buffer , subj , pred , obj , context , 0 , 0 , 0 , 0 );
1894+ getMinKey (buffer , subj , pred , obj , context , NO_PREVIOUS_ID , NO_PREVIOUS_ID , NO_PREVIOUS_ID ,
1895+ NO_PREVIOUS_ID );
18921896 }
18931897
18941898 @ Override
@@ -1904,7 +1908,12 @@ void getMinKey(ByteBuffer bb, long subj, long pred, long obj, long context, long
19041908 pred = pred <= 0 ? 0 : pred ;
19051909 obj = obj <= 0 ? 0 : obj ;
19061910 context = context <= 0 ? 0 : context ;
1907- toKey (bb , subj , pred , obj , context );
1911+ long prevSubjNorm = prevSubj == NO_PREVIOUS_ID ? NO_PREVIOUS_ID : (prevSubj <= 0 ? 0 : prevSubj );
1912+ long prevPredNorm = prevPred == NO_PREVIOUS_ID ? NO_PREVIOUS_ID : (prevPred <= 0 ? 0 : prevPred );
1913+ long prevObjNorm = prevObj == NO_PREVIOUS_ID ? NO_PREVIOUS_ID : (prevObj <= 0 ? 0 : prevObj );
1914+ long prevContextNorm = prevContext == NO_PREVIOUS_ID ? NO_PREVIOUS_ID
1915+ : (prevContext <= 0 ? 0 : prevContext );
1916+ toKey (bb , subj , pred , obj , context , prevSubjNorm , prevPredNorm , prevObjNorm , prevContextNorm );
19081917 }
19091918
19101919 void getMaxKey (ByteBuffer bb , long subj , long pred , long obj , long context ) {
@@ -1996,6 +2005,11 @@ public void print() {
19962005 }
19972006
19982007 void toKey (ByteBuffer bb , long subj , long pred , long obj , long context ) {
2008+ toKey (bb , subj , pred , obj , context , NO_PREVIOUS_ID , NO_PREVIOUS_ID , NO_PREVIOUS_ID , NO_PREVIOUS_ID );
2009+ }
2010+
2011+ void toKey (ByteBuffer bb , long subj , long pred , long obj , long context , long prevSubj , long prevPred ,
2012+ long prevObj , long prevContext ) {
19992013
20002014 boolean shouldCache = threeOfFourAreZeroOrMax (subj , pred , obj , context );
20012015 if (shouldCache ) {
@@ -2012,7 +2026,9 @@ void toKey(ByteBuffer bb, long subj, long pred, long obj, long context) {
20122026 }
20132027
20142028 // Pass through to the keyWriter with caching hint
2015- keyWriter .write (bb , subj , pred , obj , context , shouldCache );
2029+ boolean hasPrev = prevSubj != NO_PREVIOUS_ID ;
2030+ keyWriter .write (bb , subj , pred , obj , context , shouldCache , hasPrev , prevSubj , prevPred , prevObj ,
2031+ prevContext );
20162032 }
20172033
20182034 void keyToQuad (ByteBuffer key , long [] quad ) {
0 commit comments