<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class="" style="font-family: SourceCodePro-Regular;"><div class="">I needed this prefix matching on gproc</div></div></blockquote></div><div class=""><br class=""></div><div class="">You should mentioned that earlier. Use tuples as keys as Lukas said.</div><div class=""><br class=""></div><div class="">- Dmitry</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 28 Oct 2014, at 03:20, Eduardo Gurgel <<a href="mailto:edgurgel@gmail.com" class="">edgurgel@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Thank you, Lukas and Ulf. I'll check out both proposed solutions.<div class=""><br class=""></div><div class="">I needed this prefix matching on gproc, so I don't think kvdb will be a possible solution for me in this case .I will probably need to see if I can use a simple string instead of a binary to tag my processes.</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">--</div><div class=""><br class=""></div><div class="">Eduardo</div></div><div class="gmail_extra" style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On 27 October 2014 23:06, Ulf Wiger<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:ulf@feuerlabs.com" target="_blank" class="">ulf@feuerlabs.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><br class=""></div><div class="">FWIW, the kvdb database [1] allows for select operations on e.g. ets-based tables, including prefix match on binary keys.</div><div class=""><br class=""></div><div class="">It does this through a little trickery. Since the match syntax doesn’t support prefix notation for binaries, and kvdb keys are always some form of binary encoding, specifying a list prefix, e.g. “aa” ++ ‘_’ in the head pattern will indicate to kvdb that you want to match on prefix, and the match spec will be modified. More specifically, kvdb will derive a proper prefix and do a prefix_match using ‘next’ iteration, and then matching the objects using ets:match_spec_run/2.</div><div class=""><br class=""></div><div class="">Example:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Eshell V5.10.3  (abort with ^G)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">1> kvdb:start().</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">starting kvdb</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">KVDB Dbs = []</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">ok</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">2> kvdb:open(db,[{backend,ets}]).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">File = "db.db"</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{ok,<0.53.0>}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">3> kvdb:add_table(db,t,[]).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">ok</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">4> kvdb:put(db,t,{<<"aaaaa">>,1}).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">ok</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">5> kvdb:put(db,t,{<<"aabbb">>,2}).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">ok</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">6> kvdb:put(db,t,{<<"aabcc">>,3}).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">ok</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">7> kvdb:select(db,t,[{{<<"aa">>,'_'},[],['$_']}]).       </div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{[],#Fun<kvdb_direct.34.51139377>}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">8> kvdb:select(db,t,[{{"aa" ++ '_','_'},[],['$_']}]).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{[{<<"aaaaa">>,1},{<<"aabbb">>,2},{<<"aabcc">>,3}],</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> #Fun<kvdb_direct.34.51139377>}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">9> kvdb:select(db,t,[{{"aab" ++ '_','_'},[],['$_']}]).</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{[{<<"aabbb">>,2},{<<"aabcc">>,3}],</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> #Fun<kvdb_direct.34.51139377>}</div></div><div class=""><br class=""></div><div class="">This is obviously (significantly) slower than doing a normal ets:select() or mnesia:[dirty_]select(), but it’s mainly a question of constant-factor overheads. Kvdb clearly puts semantics before performance. ;-)</div><div class=""><br class=""></div><div class="">BR,</div><div class="">Ulf W</div><div class=""><br class=""></div><div class="">[1]<span class="Apple-converted-space"> </span><a href="https://github.com/Feuerlabs/kvdb" target="_blank" class="">https://github.com/Feuerlabs/kvdb</a></div><br class=""><div class=""><div class=""><div class="h5"><div class="">On 27 Oct 2014, at 10:02, Lukas Larsson <<a href="mailto:lukas@erlang.org" target="_blank" class="">lukas@erlang.org</a>> wrote:</div><br class=""></div></div><blockquote type="cite" class=""><div class=""><div class="h5"><div dir="ltr" class="">Hello,<br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Oct 23, 2014 at 11:35 AM, Eduardo Gurgel<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:edgurgel@gmail.com" target="_blank" class="">edgurgel@gmail.com</a>></span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class="">Is it possible to match the prefix of a binary using ETS match spec?</div></blockquote><div class=""><br class=""></div><div class="">It is not possible.</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class="">And if it's not, is it a limitation or just a missing implementation?<br class=""></div></blockquote><div class=""><br class=""></div><div class="">At the moment it is both :)</div><div class=""><br class=""></div><div class="">I've never tried to do something like that, but I would guess you work around this limitation by extracting what you have to match from the binary into a surrounding tuple before doing the insert. Right now there is afaik no plan to add the possibility to do this.</div><div class=""><br class=""></div><div class="">Lukas</div></div></div></div></div></div>_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" target="_blank" class="">erlang-questions@erlang.org</a><br class=""><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank" class="">http://erlang.org/mailman/listinfo/erlang-questions</a><br class=""></blockquote></div><br class=""><div class=""><span style="border-collapse: separate; border-spacing: 0px;" class=""><div class=""><div class="">Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div><div class=""><a href="http://feuerlabs.com/" target="_blank" class="">http://feuerlabs.com</a></div></div><div class=""><br class=""></div></span><br class=""></div><br class=""></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div dir="ltr" class="">Eduardo<br class=""></div></div><span style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">erlang-questions mailing list</span><br style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:erlang-questions@erlang.org" style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">erlang-questions@erlang.org</a><br style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://erlang.org/mailman/listinfo/erlang-questions" style="font-family: SourceCodePro-Regular; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://erlang.org/mailman/listinfo/erlang-questions</a></div></blockquote></div><br class=""></div></body></html>