Hello Erlangers!<div><br></div><div>So I made a dict as field of my state record and I do serialize it via term_to_binary and it seems to work like a charm.</div><div><br></div><div>One thing which makes me thinking about implementing my own serializer or dict like library - why dict data structure has many empty lists in it? Is it for the case of fast growing?</div>
<div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">Eshell V5.8.5 (abort with ^G)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">1> D = dict:new().</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">{dict,0,16,16,8,80,48,</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}</font></div></div><div><br clear="all"><div>Actually those empty lists doesn't hurt me much, but why? If nobody knows I will check sources :-)</div>
<div><br></div><div>Best regards,</div><div>Max</div><br><br>
<br><br><div class="gmail_quote">On Sat, Nov 12, 2011 at 1:09 AM, Bob Gustafson <span dir="ltr"><<a href="mailto:bobgus@rcn.com">bobgus@rcn.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
How you implement your 'database' depends on whether you allow the<br>
record structure to change over time without rewriting the whole<br>
database.<br>
<br>
A changeable structure database could be implemented by having a<br>
serializable 'lump' for each record. The structure can be changed by<br>
adding a new tag/value pair to the existing lump.<br>
<br>
Each lump has a unique id number. External indexes can be constructed<br>
for any/all tags with the id number as the index value.<br>
<br>
An update of a record/lump would be done by consulting the index(es) for<br>
each tag value of interest to determine the lump id value(s). The<br>
resulting lump(s) would then be accessed, deserialized, (data values<br>
changed, new tags/values added or deleted), lump(s) re-serialized, and<br>
index(es) updated.<br>
<br>
It can be a very simple database or a very complex database. The<br>
advantage is that lumps written in the distant past can be accessed and<br>
their data values utilized in the same way as newer lumps with more (or<br>
less) tags/values.<br>
<br>
I'm sure this scheme has been invented many times in the past.<br>
<div class="HOEnZb"><div class="h5"><br>
On Fri, 2011-11-11 at 21:46 +0100, Joe Armstrong wrote:<br>
> Umm - followup question.<br>
><br>
><br>
> Is there a way to consult files containing records. If I do<br>
> file:consult on a file containing records what happens?<br>
><br>
><br>
> I tried this without success the other day<br>
><br>
><br>
> /Joe<br>
><br>
> On Fri, Nov 11, 2011 at 11:15 AM, Ulf Wiger<br>
> <<a href="mailto:ulf.wiger@erlang-solutions.com">ulf.wiger@erlang-solutions.com</a>> wrote:<br>
> This is not exactly what was asked for, but…<br>
><br>
><br>
> In JOBS, I have created a jobs_info module that includes<br>
> jobs.hrl and uses exprecs's -export_records() feature.<br>
><br>
><br>
> <a href="https://github.com/esl/jobs/blob/master/src/jobs_info.erl" target="_blank">https://github.com/esl/jobs/blob/master/src/jobs_info.erl</a><br>
><br>
><br>
> I use this module to present metadata about the various<br>
> objects in JOBS. The only thing needed in order to 'serialize'<br>
> a new type of record is to define it in jobs.hrl and add it to<br>
> the -export_records() directive.<br>
><br>
><br>
> BR,<br>
> Ulf W<br>
><br>
><br>
> -module(jobs_info).<br>
><br>
><br>
><br>
> -export([pp/1]).<br>
><br>
><br>
><br>
> -include("jobs.hrl").<br>
><br>
> -include_lib("parse_trans/include/exprecs.hrl").<br>
><br>
><br>
><br>
> -export_records([rr, cr, grp, rate, queue, sampler]).<br>
><br>
><br>
><br>
><br>
><br>
> pp(L) when is_list(L) -><br>
><br>
> [pp(X) || X <- L];<br>
><br>
> pp(X) -><br>
><br>
> case '#is_record-'(X) of<br>
><br>
> true -><br>
><br>
> RecName = element(1,X),<br>
><br>
> {RecName, lists:zip(<br>
><br>
> '#info-'(RecName,fields),<br>
><br>
> pp(tl(tuple_to_list(X))))};<br>
><br>
> false -><br>
><br>
> if is_tuple(X) -><br>
><br>
> list_to_tuple(pp(tuple_to_list(X)));<br>
><br>
> true -><br>
><br>
> X<br>
><br>
> end<br>
><br>
> end.<br>
><br>
><br>
><br>
><br>
> On 11 Nov 2011, at 10:57, Joel Reymont wrote:<br>
><br>
> > You need to serialize the record fields with their tags.<br>
> > Then you can use something like exprecs to set individual<br>
> > fields in the new record definition.<br>
> ><br>
> ><br>
> > This assumes you are just adding fields and names of old<br>
> > fields stay the same.<br>
> ><br>
> > ---<br>
> > Sent from my iPhone<br>
> ><br>
> > On Nov 11, 2011, at 10:44 AM, Maxim Treskin<br>
> > <<a href="mailto:zerthurd@gmail.com">zerthurd@gmail.com</a>> wrote:<br>
> ><br>
> ><br>
> ><br>
> > > Max, what are you need indeed? Your words sounds very<br>
> > > strange.<br>
> > ><br>
> > > On 11 November 2011 15:31, Max Bourinov<br>
> > > <<a href="mailto:bourinov@gmail.com">bourinov@gmail.com</a>> wrote:<br>
> > > Hello Erlangers,<br>
> > ><br>
> > ><br>
> > > What is a best way to serialize record, modify<br>
> > > record's code and then deserialize it back?<br>
> > ><br>
> > ><br>
> > > I seen <a href="https://github.com/esl/parse_trans" target="_blank">https://github.com/esl/parse_trans</a>. Is this<br>
> > > what I need or there are another options?<br>
> > ><br>
> > ><br>
> > > Maybe I better use another data structure?<br>
> > ><br>
> > ><br>
> > > p.s. Of course performance is always important.<br>
> > ><br>
> > ><br>
> > > Best regards,<br>
> > > Max<br>
> > ><br>
> > > _______________________________________________<br>
> > > erlang-questions mailing list<br>
> > > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> > ><br>
> > ><br>
> > ><br>
> > ><br>
> > ><br>
> > > --<br>
> > > Maxim Treskin<br>
> > ><br>
> > > _______________________________________________<br>
> > > erlang-questions mailing list<br>
> > > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> > ><br>
> > _______________________________________________<br>
> > erlang-questions mailing list<br>
> > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
> Ulf Wiger, CTO, Erlang Solutions, Ltd.<br>
> <a href="http://erlang-solutions.com" target="_blank">http://erlang-solutions.com</a><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>