Re: [Erlangweb-users] implementation of edict
Brought to you by:
etcerlangweb,
paulgray
|
From: Michal S. <mi...@er...> - 2008-09-01 13:20:29
|
Hi, Thank you for your email. Both patches should be included in the 1.1 release, which we are working on right now. Thanks, Michal -- Michal Slaski http://www.erlang-consulting.com On 30 Aug 2008, at 17:19, Ulf Wiger wrote: > Just thought I'd think out loud about the implementation of edict. > Note that I've just been browsing the code on the web, so this > is just from a quick read-through. > > The data representation seems a bit inefficient. For example: > > fset(Key, Value) -> > case ets:lookup(?MODULE, self()) of > [{_, Dict}] -> ets:insert(?MODULE, {self(), dict:store(Key, > Value, Dict)}); > [] -> exit(no_dict_attached) > end. > > This strategy obviously scales very poorly if a large number of keys > is inserted. > > An alternative strategy would be: > > fset(Key, Value) -> > case ets:member(?MODULE, self()} of > true -> > ets:insert(?MODULE, {{self(),Key}, Value}); > false -> > exit(no_dict_attached) > end. > > ...and so on. > > The penalty will be incurred on terminate_state(), which will > look something like this: > > terminate_state() -> > ets:delete(?MODULE, self()), > ets:match_delete(?MODULE, {self(),'_'},'_'}). > > (the ets table being an ordered_set, of course.) > > > Since it would appear as if this module will be called many times > while > building a page, I would think that this ought to give better > characteristics. > > > One more thing - I believe this function to be wrong: > > fset(List, Key, Value) -> > case ets:lookup(?MODULE, self()) of > [{_, Dict}] -> ets:insert(?MODULE, {self(), dict:store(List, [{Key, > Value}|dict_fetch(List, Dict)], Dict)}); > [] -> exit(no_dict_attached) > end. > > > The dict_fetch/2 function returns 'undefined' if there is no occurence > of the key List. > That would mean that calling e.g. fset("list", "person", "john") > before storing an > initial value for "list", would result in the term {"list", > [{"person","john"}|undefined]} > in the dictionary. It would be better to return an error or initialize > it to [] first. > > BR, > Ulf W > > ---------------------------------------------------------------------- > --- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Erlangweb-users mailing list > Erl...@li... > https://lists.sourceforge.net/lists/listinfo/erlangweb-users |