Sets in SQL/Ruby

I have been working on building a common library that represents
fields as weighted sets.
I am more familiar with Rails know than I was when I started this. I
decided to post this because I was concerned I may need to show my code
in a job interview.

Below is a code sample of how the sets are declared. The example is of
3 different sets.
I map each set element as a name of the element to a symbol of length
one. Then the set is
stored in the database field as a char and a digit (since it’s
weighted). so
“w3u4a0” is the set [windows:3, linux:4, aix:0]. The obvious weakness
is that I can only really have around 26 elements in the set type, but
that seemed ok for what I was doing. If I list my SQL tables from SQL,
the sets are partially descernable more so than just numbers are.
Possibly some bit map could have been used, but it might have been
harder to read from a select. I also may have doubly weighted sets as a
type such as represented by “w32l44”. It all works fine as long as each
weight is one digit. Anyway, I just had a java code review at a job
interview and realized the extent to which people can critique your
code so that inspired me to post this here in case I had to use my code
for a job interview etc.

{:platforms =>
{:windows => :w,
:linux => :l,
:unix => :u,
:aix => :a,
:solaris => :s
}
},
{:frameworks =>
{:rails => :r,
:j2ee => :m,
:dot_net => :d
}
},
{:work =>
{:telecommute => :t,
:contract => :c,
:permanent => :s,
:part_time => :stuck_out_tongue:
}

surf wrote:

I have been working on building a common library that represents
fields as weighted sets.
Below is a code sample of how the sets are declared. The example is of
3 different sets.
I map each set element as a name of the element to a symbol of length
one. Then the set is
stored in the database field as a char and a digit (since it’s
weighted).

I guess the main point here is the database representation. The
solution you have given may be fine given that the data domain can be
limited to those constraints (single char and single digit). You could
increase this a bit by coding the weight and/or element to another base
(i.e. using the full 256 byte values as representation). But then you
loose readability if that is important. You could use a variable length
encoding with a separator character, like so:

element,12,another,4,bigone,12345

Or you could go the whole way and store a YAML representation of the
data set in the database. That’d give you maximum flexibility, but
depending on how the data is to be used may or may not be appropriate.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs