On Wed, Sep 30, 2015 at 7:38 AM, Rolf Huehne <rhue...@fli-leibniz.de> wrote:

> On 09/29/2015 10:08 PM, Robert Hanson wrote:
> > I have an idea. Let's call the "associative array" a "map" just so we
> > don't have so many "array" words.
> >
> I would rather prefer "hash" because the term is used for it in other
> languages like Perl and I am used to it. I used "associative array" to
> adapt to the name used in the description of the new system.
>

I thought about hash, and in Jmol {....}.type == "hash", but technically it
is not a hash. It is a map.


>
> > On Tue, Sep 29, 2015 at 12:44 PM, Rolf Huehne <rhue...@fli-leibniz.de
> > <mailto:rhue...@fli-leibniz.de>> wrote:
> >
> >
> Bob, it seems that we have a different perception of hashes in different
> levels.
>
> For me the first level hash usually is just like a standard array. So it
> doesn't contain the actual data directly but in second-level hashes. The
> only crucial difference to a standard array is, that the index of an
> array element is foreseable (if the hash keys are designed properly).
> This enables to avoid duplicates automatically without any performance
> penalty (increasing with array size) while the array is built or
> expanded. And it also enables direct access to any dataset if the key
> properties are already known. So changing the data structure to a
> standard array is not an option for me.
>
> So for me it is not "bypassing a map level". It is just the same as if
> the first level would be a standard array.
>
>
Then map.array("id") is perfect for you. It turns that map into an actual
array (temporarily), and you can then use WHERE and WHEREIN on that next
level of maps. After you do that, using array("id") again returns your
top-level map. The result was identical to what you requested.

I think what you are missing is that Jmol is treating an array or array of
arrays totally differently from a map. The array is passed through, and
WHERE or WHEREIN operate directly on the map itself, no matter how many
levels deep it is in the array. So it makes no sense to refer to the array
itself and its subarrays as the "first level." The first map that is found
-- that is the level for WHERE; if the values in that map are also maps,
those are what are tested for WHEREIN.

It's not more complicated than that.

 snpInfo = {"rs1229984": [resno: 48,
                          from: "R",
                          to: "H"],
            "rs1041969": [resno: 57,
                          from: "N",
                          to: "K"]
            };

print "=== Case 1 ====";
print snpInfo.array("id").select("id,from,to WHERE
to='H'").array("id").format("JSON");

print "=== Case 2 ====";
print snpInfo.array("id").select("(resno) WHERE to='H'").format("JSON");

=== Case 1 ====
{ "rs1229984": { "to": "H","from": "R" } }
=== Case 2 ====
[ 48 ]


Right?
------------------------------------------------------------------------------
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to