Improve from_list in skiplist
form_list had taken a suprrising amount of time - so improved the efficiency of this
This commit is contained in:
parent
c43014a0ee
commit
34a25bdb88
1 changed files with 21 additions and 47 deletions
|
@ -188,53 +188,27 @@ enter(Key, Value, Hash, SkipList, Width, Level) ->
|
||||||
{MarkerKey, UpdSubSkipList})
|
{MarkerKey, UpdSubSkipList})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
from_list(SkipList, _SkipWidth, 0) ->
|
||||||
from_list(KVL, Width, 1) ->
|
SkipList;
|
||||||
Slots = length(KVL) div Width,
|
from_list(KVList, SkipWidth, ListHeight) ->
|
||||||
SkipList0 = lists:map(fun(X) ->
|
L0 = length(KVList),
|
||||||
N = X * Width,
|
SL0 =
|
||||||
{K, _V} = lists:nth(N, KVL),
|
case L0 > SkipWidth of
|
||||||
{K, lists:sublist(KVL,
|
true ->
|
||||||
N - Width + 1,
|
from_list(KVList, L0, [], SkipWidth);
|
||||||
Width)}
|
false ->
|
||||||
end,
|
{LastK, _LastSL} = lists:last(KVList),
|
||||||
lists:seq(1, length(KVL) div Width)),
|
[{LastK, KVList}]
|
||||||
case Slots * Width < length(KVL) of
|
end,
|
||||||
true ->
|
from_list(SL0, SkipWidth, ListHeight - 1).
|
||||||
{LastK, _V} = lists:last(KVL),
|
|
||||||
SkipList0 ++ [{LastK, lists:nthtail(Slots * Width, KVL)}];
|
from_list([], 0, SkipList, SkipWidth) ->
|
||||||
false ->
|
SkipList;
|
||||||
SkipList0
|
from_list(KVList, L, SkipList, SkipWidth) ->
|
||||||
end;
|
SubLL = min(SkipWidth, L),
|
||||||
from_list(KVL, Width, Level) ->
|
{Head, Tail} = lists:split(SubLL, KVList),
|
||||||
SkipWidth = width(Level, Width),
|
{LastK, _LastV} = lists:last(Head),
|
||||||
LoftSlots = length(KVL) div SkipWidth,
|
from_list(Tail, L - SubLL, SkipList ++ [{LastK, Head}], SkipWidth).
|
||||||
case LoftSlots of
|
|
||||||
0 ->
|
|
||||||
{K, _V} = lists:last(KVL),
|
|
||||||
[{K, from_list(KVL, Width, Level - 1)}];
|
|
||||||
_ ->
|
|
||||||
SkipList0 =
|
|
||||||
lists:map(fun(X) ->
|
|
||||||
N = X * SkipWidth,
|
|
||||||
{K, _V} = lists:nth(N, KVL),
|
|
||||||
SL = lists:sublist(KVL,
|
|
||||||
N - SkipWidth + 1,
|
|
||||||
SkipWidth),
|
|
||||||
{K, from_list(SL, Width, Level - 1)}
|
|
||||||
end,
|
|
||||||
lists:seq(1, LoftSlots)),
|
|
||||||
case LoftSlots * SkipWidth < length(KVL) of
|
|
||||||
true ->
|
|
||||||
{LastK, _V} = lists:last(KVL),
|
|
||||||
TailList = lists:nthtail(LoftSlots * SkipWidth, KVL),
|
|
||||||
SkipList0 ++ [{LastK, from_list(TailList,
|
|
||||||
Width,
|
|
||||||
Level - 1)}];
|
|
||||||
false ->
|
|
||||||
SkipList0
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
list_lookup(Key, SkipList, 1) ->
|
list_lookup(Key, SkipList, 1) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue