diff --git a/src/leveled_skiplist.erl b/src/leveled_skiplist.erl index 5829448..e8d8627 100644 --- a/src/leveled_skiplist.erl +++ b/src/leveled_skiplist.erl @@ -673,6 +673,32 @@ skiplist_keybefore_test() -> io:format(user, "~nFinding self in keys above ~w microseconds for ~w finds~n", [timer:now_diff(os:timestamp(), SW), N]). +skiplist_range_test() -> + N = 150, + KL = generate_randomkeys(1, N, 1, N div 5), + + KLSL1 = lists:sublist(lists:ukeysort(1, KL), 128), + SkipList1 = from_list(KLSL1), + {LastK1, V1} = lists:last(KLSL1), + R1 = to_range(SkipList1, LastK1, LastK1), + ?assertMatch([{LastK1, V1}], R1), + + KLSL2 = lists:sublist(lists:ukeysort(1, KL), 127), + SkipList2 = from_list(KLSL2), + {LastK2, V2} = lists:last(KLSL2), + R2 = to_range(SkipList2, LastK2, LastK2), + ?assertMatch([{LastK2, V2}], R2), + + KLSL3 = lists:sublist(lists:ukeysort(1, KL), 129), + SkipList3 = from_list(KLSL3), + {LastK3, V3} = lists:last(KLSL3), + R3 = to_range(SkipList3, LastK3, LastK3), + ?assertMatch([{LastK3, V3}], R3), + + {FirstK4, V4} = lists:nth(1, KLSL3), + R4 = to_range(SkipList3, FirstK4, FirstK4), + ?assertMatch([{FirstK4, V4}], R4). + empty_skiplist_size_test() -> ?assertMatch(0, leveled_skiplist:size(empty(false))), diff --git a/src/leveled_sst.erl b/src/leveled_sst.erl index a3f2ec1..3fc5ef3 100644 --- a/src/leveled_sst.erl +++ b/src/leveled_sst.erl @@ -674,7 +674,8 @@ lookup_slots_int(StartKey, all, SkipList) -> lookup_slots_int(StartKey, EndKey, SkipList) -> case leveled_skiplist:to_range(SkipList, StartKey, EndKey) of [] -> - {[], false, false}; + BestKey = leveled_skiplist:key_above(SkipList, StartKey), + {[BestKey], true, true}; L0 -> {LastKey, _LastVal} = lists:last(L0), case LastKey of @@ -788,7 +789,7 @@ trim_slot(SlotBinary, StartKey, EndKey) -> all -> LTrimL; _ -> - {LKeep, _RDrop} = lists:splitwith(RTrimFun, L), + {LKeep, _RDrop} = lists:splitwith(RTrimFun, LTrimL), LKeep end, RTrimL. @@ -1176,6 +1177,14 @@ simple_persisted_test() -> ?assertMatch(SubKVListA3L, length(FetchedListB3)), ?assertMatch(SubKVListA3, FetchedListB3), + io:format("Eight hundredth key ~w~n", [Eight000Key]), + FetchListB4 = sst_getkvrange(Pid, + Eight000Key, + Eight000Key, + 4), + FetchedListB4 = lists:foldl(FoldFun, [], FetchListB4), + ?assertMatch([{Eight000Key, _v800}], FetchedListB4), + ok = sst_close(Pid), ok = file:delete(Filename ++ ".sst").