small post about ordered_set and partially-bound keys

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

small post about ordered_set and partially-bound keys

Max Lapshin-2
Erlang ets with ordered_set mode has very cool feature: partially bound tuple primary key that allows to use ets as a good old binary tree.

I haven't found any good explanations of how to use, so have written some draft of post:

Would be glad for any feedback.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: small post about ordered_set and partially-bound keys

Andreas Schultz-3
Max Lapshin <[hidden email]> schrieb am Do., 13. Dez. 2018 um 10:06 Uhr:
Erlang ets with ordered_set mode has very cool feature: partially bound tuple primary key that allows to use ets as a good old binary tree.

I haven't found any good explanations of how to use, so have written some draft of post:

You don't need to play tricks with ets:fun2ms/1. It is mostly a helper so that you don't have to think to much about the structure of a match spec yourself. But, you can still construct the same spec manually.

So, instead of:

    ets:fun2ms(fun (#segment{utc={_,_,_}} = Segment) ->  true end)

You can simply use:

    [{#segment{utc = {'_','_','_'}, _ = '_'}, [], [true]}]

Or to use your sample:

    match_spec_hour(Name, Hour, true) ->
     [{#segment{utc = {Name,Hour,'_'}, _ = '_'}, [], [true]}];

    match_spec_hour(Name, Hour, segment) ->
     [{#segment{utc = {Name,Hour,'_'}, _ = '_'}, [], ['$_']}].

Regards
Andreas



Would be glad for any feedback.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
--
--
Dipl.-Inform. Andreas Schultz

----------------------- enabling your networks ----------------------
Travelping GmbH                     Phone:  +49-391-81 90 99 0
Roentgenstr. 13                     Fax:    +49-391-81 90 99 299
39108 Magdeburg                     Email:  [hidden email]
GERMANY                             Web:    http://www.travelping.com

Company Registration: Amtsgericht Stendal        Reg No.:   HRB 10578
Geschaeftsfuehrer: Holger Winkelmann          VAT ID No.: DE236673780
---------------------------------------------------------------------

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions