View Source a_tree (a_tree v0.3.2)

A module for interacting with an ATree.

Examples

1> {ok, Tree} = a_tree:new([
    {boolean, <<"private">>},
    {string, <<"country">>},
    {integer, <<"exchange_id">>},
    {string, <<"city">>},
    {string_list, <<"deals">>},
    {integer_list, <<"segment_ids">>}
]).
2> ok = a_tree:insert(Tree, 1, <<"exchange_id = 1 and not private and deals one of [\"deal-1\", \"deal-2\"]">>).
3> ok = a_tree:insert(Tree, 2, <<"exchange_id = 1 and not private and deals one of [\"deal-2\", \"deal-3\"] and segment_ids one of [1, 2, 3, 4]">>).
4> ok = a_tree:insert(Tree, 3, <<"exchange_id = 1 and not private and deals one of [\"deal-2\", \"deal-3\"] and segment_ids one of [5, 6, 7, 8] and country in [\"CA\", \"US\"]">>).
5> {ok, Results} = a_tree:search(Tree, [
    {<<"private">>, false},
    {<<"exchange_id">>, 1},
    {<<"deals">>, [<<"deal-1">>, <<"deal-3">>]},
    {<<"segment_ids">>, [2, 3]},
    {<<"country">>, <<"CA">>}
]).

Summary

Functions

Remove the specified boolean expression from the atree/0.

Insert a new arbitrary boolean expression inside the atree/0 with the specified user_id/0.

Create a new atree/0.

Search for boolean expressions that match the specified event.

Export the atree/0 to Graphviz format.

Types

atree()

-opaque atree()

attribute()

-type attribute() :: {attribute_type(), attribute_name()}.

attribute_name()

-type attribute_name() :: binary().

attribute_type()

-type attribute_type() :: boolean | integer | string | integer_list | string_list.

attribute_value()

-type attribute_value() :: boolean() | binary() | integer() | [integer()] | [binary()].

event()

-type event() :: [{attribute_name(), attribute_value()}].

user_id()

-type user_id() :: non_neg_integer().

Functions

delete(ATree, Id)

-spec delete(ATree :: atree(), Id :: user_id()) -> ok.

Remove the specified boolean expression from the atree/0.

insert(ATree, Id, Expression)

-spec insert(ATree :: atree(), Id :: user_id(), Expression :: binary()) -> ok | {error, term()}.

Insert a new arbitrary boolean expression inside the atree/0 with the specified user_id/0.

The boolean expression must contain defined attributes with the correct types otherwise an error will be returned.

new(Attributes)

-spec new(Attributes :: [attribute()]) -> {ok, atree()} | {error, term()}.

Create a new atree/0.

The attributes must all be different otherwise an error will be returned.

search(ATree, Event)

-spec search(ATree :: atree(), Event :: event()) -> {ok, Matches :: [user_id()]} | {error, term()}.

Search for boolean expressions that match the specified event.

to_graphviz(ATree)

-spec to_graphviz(ATree :: atree()) -> {ok, binary()} | {error, term()}.

Export the atree/0 to Graphviz format.