Skip to content

Instantly share code, notes, and snippets.

@krestenkrab
Created October 2, 2013 09:44
Show Gist options
  • Save krestenkrab/6791376 to your computer and use it in GitHub Desktop.
Save krestenkrab/6791376 to your computer and use it in GitHub Desktop.
first/next implementations for hanoidb
-module(to_ulf).
-include_lib("hanoidb/include/hanoidb.hrl").
first(Ref) ->
case hanoidb:fold_range(Ref,fun(K,V,Acc) -> [{K,V}|Acc] end,[],
#key_range{from_key= <<>>, limit=1, to_key=undefined})
of
[] -> '$end_of_table';
[{Key,Value}] -> {Key,Value}
end.
next(Ref, Key) when is_binary(Key) ->
case hanoidb:fold_range(Ref,fun(K,V,Acc) -> [{K,V}|Acc] end,[],
#key_range{from_key=Key, from_inclusive=false, limit=1, to_key=undefined})
of
[] -> '$end_of_table';
[{Key,Value}] -> {Key,Value}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment