Namdak Tonpa 4 лет назад
Родитель
Сommit
bc9c13a915
1 измененных файлов с 13 добавлено и 13 удалено
  1. 13 13
      src/stores/kvs_rocks.erl

+ 13 - 13
src/stores/kvs_rocks.erl

@@ -49,15 +49,15 @@ fd(K) -> Key = tb(K),
   end,
   binary:part(Key,{0,S}).
 
-o(<<>>,SK,_,_) -> {ok,SK,[],[]};
-o(Key, % key
+run(<<>>,SK,_,_) -> {ok,SK,[],[]};
+run(Key, % key
   SK,  % sup-key
   Dir, % direction next/prev
   Compiled_Operations) ->
+       % H is iterator reference
 
   S = sz(SK),
-
-% H is iterator reference
+  Initial_Object = {ref(), []},
 
   Run = fun (F,K,H,V,Acc) when binary_part(K,{0,S}) == SK -> {F(H,Dir),H,[V|Acc]}; % continue +------------+
             (_,K,H,V,Acc) -> stop_it(H),                                           % fail-safe closing     |
@@ -76,10 +76,10 @@ o(Key, % key
     (F,{{ok,K,V},H})      -> Run(F,K,H,V,[]);                           % first chained next-take          |
     (F,{{ok,K,V},H,A})    -> Run(F,K,H,V,A);                            % chained CPS-take continuator +---+
     (_,{{error,E},H,Acc}) -> {{error,E},H,Acc};                         % error effects
-    (F,{R,O})             -> F(R,O)                                     % chain constructor
+    (F,{I,O})             -> F(I,O)                                     % chain constructor from initial object
   end,
 
-  catch case lists:foldl(State_Machine, {ref(), []}, Compiled_Operations) of
+  catch case lists:foldl(State_Machine, Initial_Object, Compiled_Operations) of
     {{ok,K,Bin},_,A}  -> {ok, fd(K),  bt(Bin), [bt(A1) || A1 <- A]};
     {{ok,K,Bin},_}    -> {ok, fd(K),  bt(Bin), []};
     {{error,_},_,Acc} -> {ok, fd(SK), bt(shd(Acc)), [bt(A1) || A1 <- Acc]};
@@ -101,15 +101,15 @@ join(_)    -> application:start(rocksdb),
               initialize(),
               application:set_env(kvs,rocks_ref,Ref).
 
-compile(seek)     -> [fun rocksdb:iterator/2,fun rocksdb:iterator_move/2];
-compile(move)     -> [fun rocksdb:iterator_move/2];
-compile(close)    -> [fun rocksdb:iterator_close/1].
-compile(take,N)   -> lists:map(fun(_) -> fun rocksdb:iterator_move/2 end, lists:seq(1, N)).
+compile(seek) -> [fun rocksdb:iterator/2,fun rocksdb:iterator_move/2];
+compile(move) -> [fun rocksdb:iterator_move/2];
+compile(close) -> [fun rocksdb:iterator_close/1].
+compile(take,N) -> lists:map(fun(_) -> fun rocksdb:iterator_move/2 end, lists:seq(1, N)).
 
 stop_it(H) -> try begin [F]=compile(close), F(H) end catch error:badarg -> ok end.
-seek_it(K) -> o(K,K,ok,compile(seek)).
-move_it(Key,SK,Dir)   -> o(Key,SK,Dir,compile(seek) ++ compile(move)).
-take_it(Key,SK,Dir,N) when is_integer(N) andalso N >= 0 -> o(Key,SK,Dir,compile(seek) ++ compile(take,N));
+seek_it(K) -> run(K,K,ok,compile(seek)).
+move_it(Key,SK,Dir) -> run(Key,SK,Dir,compile(seek) ++ compile(move)).
+take_it(Key,SK,Dir,N) when is_integer(N) andalso N >= 0 -> run(Key,SK,Dir,compile(seek) ++ compile(take,N));
 take_it(Key,SK,Dir,_) -> take_it(Key,SK,Dir,0).
 
 all(R) -> kvs_st:feed(R).