1919import static org .lwjgl .util .lmdb .LMDB .MDB_CREATE ;
2020import static org .lwjgl .util .lmdb .LMDB .MDB_DUPSORT ;
2121import static org .lwjgl .util .lmdb .LMDB .MDB_FIRST ;
22+ import static org .lwjgl .util .lmdb .LMDB .MDB_FIRST_DUP ;
2223import static org .lwjgl .util .lmdb .LMDB .MDB_GET_BOTH_RANGE ;
2324import static org .lwjgl .util .lmdb .LMDB .MDB_KEYEXIST ;
2425import static org .lwjgl .util .lmdb .LMDB .MDB_LAST ;
@@ -761,6 +762,9 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
761762 if (rc == MDB_SUCCESS ) {
762763 valueData .mv_data (valueBuf );
763764 rc = mdb_cursor_get (cursor , keyData , valueData , MDB_GET_BOTH_RANGE );
765+ if (rc != MDB_SUCCESS ) {
766+ rc = mdb_cursor_get (cursor , keyData , valueData , MDB_FIRST_DUP );
767+ }
764768 }
765769 int keyDiff ;
766770 if (rc != MDB_SUCCESS ||
@@ -784,17 +788,18 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
784788 if (rc == MDB_SUCCESS ) {
785789 readVarints (keyData .mv_data (), valueData .mv_data (), s .maxValues );
786790 // this is required to correctly estimate the range size at a later point
787- s .startValues [s .MAX_BUCKETS ] = s .maxValues ;
791+ s .startValues [Statistics .MAX_BUCKETS ] = s .maxValues ;
788792 } else {
789793 break ;
790794 }
791795
792796 long allSamplesCount = 0 ;
793797 int bucket = 0 ;
794798 boolean endOfRange = false ;
795- for (; bucket < s .MAX_BUCKETS && !endOfRange ; bucket ++) {
799+ for (; bucket < Statistics .MAX_BUCKETS && !endOfRange ; bucket ++) {
796800 if (bucket != 0 ) {
797- bucketStart ((double ) bucket / s .MAX_BUCKETS , s .minValues , s .maxValues , s .values );
801+ bucketStart ((double ) bucket / Statistics .MAX_BUCKETS , s .minValues , s .maxValues ,
802+ s .values );
798803 keyBuf .clear ();
799804 Varint .writeUnsigned (keyBuf , s .values [0 ]);
800805 Varint .writeUnsigned (keyBuf , s .values [1 ]);
@@ -813,7 +818,7 @@ protected double cardinality(long subj, long pred, long obj, long context) throw
813818 valueData .mv_data (valueBuf );
814819 rc = mdb_cursor_get (cursor , keyData , valueData , MDB_GET_BOTH_RANGE );
815820 }
816- while (rc == MDB_SUCCESS && currentSamplesCount < s .MAX_SAMPLES_PER_BUCKET ) {
821+ while (rc == MDB_SUCCESS && currentSamplesCount < Statistics .MAX_SAMPLES_PER_BUCKET ) {
817822 keyDiff = mdb_cmp (txn , dbi , keyData , maxKey );
818823 if (keyDiff > 0 || keyDiff == 0 && mdb_dcmp (txn , dbi , valueData , maxValue ) >= 0 ) {
819824 endOfRange = true ;
0 commit comments