1%%%
2%%% Copyright 2011, Boundary
3%%%
4%%% Licensed under the Apache License, Version 2.0 (the "License");
5%%% you may not use this file except in compliance with the License.
6%%% You may obtain a copy of the License at
7%%%
8%%%     http://www.apache.org/licenses/LICENSE-2.0
9%%%
10%%% Unless required by applicable law or agreed to in writing, software
11%%% distributed under the License is distributed on an "AS IS" BASIS,
12%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13%%% See the License for the specific language governing permissions and
14%%% limitations under the License.
15%%%
16
17
18%%%-------------------------------------------------------------------
19%%% File:      folsom_sample.erl
20%%% @author    joe williams <j@boundary.com>
21%%% @doc
22%%% @end
23%%%------------------------------------------------------------------
24
25-module(folsom_sample).
26
27-export([
28         new/1,
29         new/2,
30         new/3,
31         update/3,
32         get_values/2
33        ]).
34
35-include("folsom.hrl").
36
37%% API
38
39new(slide) ->
40    new(slide, ?DEFAULT_SLIDING_WINDOW);
41new(slide_uniform) ->
42    new(slide_uniform, {?DEFAULT_SLIDING_WINDOW, ?DEFAULT_SIZE});
43new(Type) ->
44    new(Type, ?DEFAULT_SIZE, ?DEFAULT_ALPHA).
45
46new(Type, Size) ->
47    new(Type, Size, ?DEFAULT_ALPHA).
48
49new(slide, Size, _) ->
50    folsom_sample_slide:new(Size);
51new(slide_uniform, Sizes, _) ->
52    folsom_sample_slide_uniform:new(Sizes);
53new(uniform, Size, _) ->
54    folsom_sample_uniform:new(Size);
55new(none, Size, _) ->
56    folsom_sample_none:new(Size);
57new(slide_sorted, Size, _) ->
58    folsom_sample_slide_sorted:new(Size);
59new(exdec, Size, Alpha) ->
60    folsom_sample_exdec:new(Size, Alpha).
61
62update(uniform, Sample, Value) ->
63    folsom_sample_uniform:update(Sample, Value);
64update(none, Sample, Value) ->
65    folsom_sample_none:update(Sample, Value);
66update(slide_sorted, Sample, Value) ->
67    folsom_sample_slide_sorted:update(Sample, Value);
68update(exdec, Sample, Value) ->
69    folsom_sample_exdec:update(Sample, Value);
70update(slide, Sample, Value) ->
71    folsom_sample_slide:update(Sample, Value);
72update(slide_uniform, Sample, Value) ->
73    folsom_sample_slide_uniform:update(Sample, Value).
74
75
76get_values(uniform, Sample) ->
77    folsom_sample_uniform:get_values(Sample);
78get_values(none, Sample) ->
79    folsom_sample_none:get_values(Sample);
80get_values(slide_sorted, Sample) ->
81    folsom_sample_slide_sorted:get_values(Sample);
82get_values(exdec, Sample) ->
83    folsom_sample_exdec:get_values(Sample);
84get_values(slide, Sample) ->
85    folsom_sample_slide:get_values(Sample);
86get_values(slide_uniform, Sample) ->
87    folsom_sample_slide_uniform:get_values(Sample).
88