Skip to content
Browse files

different fetch API

  • Loading branch information...
1 parent b832032 commit 1b0952e24d6ac7b16c627089952d4856b59936c2 @etrepum committed May 14, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/markov.erl
View
11 src/markov.erl
@@ -1,5 +1,5 @@
-module(markov).
--export([new/0, input/2, fetch/2]).
+-export([new/0, input/2, fetch/2, fetch/3]).
new() ->
append({start, start}, stop, gb_trees:empty()).
@@ -20,8 +20,15 @@ append(K, V, T) ->
gb_trees:update(K, {1 + Count, [V | Others]}, T)
end.
+fetch([], Max, T) ->
+ fetch([start, start], Max, T);
+fetch([A], Max, T) ->
+ fetch([start, A], Max, T);
+fetch([A, B], Max, T) ->
+ fetch({A, B}, erlang:now(), Max, T).
+
fetch(Max, T) ->
- fetch({start, start}, erlang:now(), Max, T).
+ fetch([], Max, T).
fetch(K={_A, B}, RState, Max, T) when Max > 0 ->
case choose(gb_trees:lookup(K, T), RState) of

0 comments on commit 1b0952e

Please sign in to comment.
Something went wrong with that request. Please try again.