ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
reading about JavaScript I found that arrays in it are associative.
Conceptually it's sufficient, i.e. arrays with numeric index can be mapped onto associative arrays using the numeric index (stringified ?) as hash key.
However, there are performance and memory footprint considerations.
With associative arrays hash function should be called per access, and from my experience in Perl storing data in hashes takes more memory - which is not surprising - buckets and stuff ( https://en.wikipedia.org/wiki/Hash_table ).
I also know that typed arrays are being introduced into JavaScript ( https://developer.mozilla.org/en-US/...t_typed_arrays ). But, IIUC, not all JavaScript engines support typed arrays - the latter do use numeric index like in "C".
So, are there other than typed non-associative arrays (the ones using numeric index directly) ? Perhaps as an add-on module and/or bindings to some code written in "C" ?
Thanks in advance.
Last edited by Sergei Steshenko; 11-16-2012 at 10:10 PM.
Reason: numeric index, hash key
The typed arrays are supported in all new browsers supporting HTML5. The only problem would be old Internet Explorer versions. Only IE 10 supports it.
I think it wasn't really necessary before WebGL. Traditionally, we would use Ajax calling a database on a server to deal with lots of data.
If all you need is a lookup in a big data set, you could write the data as a long string and use charCodeAt, but changing the data would be a problem.
The only thing I can think of for old browsers is using ActionScript (flash) or something. Arrays in ActionScript are always indexed by integer, but they're sparse arrays, so I'm really not sure about how it does the lookups.
The typed arrays are supported in all new browsers supporting HTML5. The only problem would be old Internet Explorer versions. Only IE 10 supports it.
I think it wasn't really necessary before WebGL. Traditionally, we would use Ajax calling a database on a server to deal with lots of data.
If all you need is a lookup in a big data set, you could write the data as a long string and use charCodeAt, but changing the data would be a problem.
The only thing I can think of for old browsers is using ActionScript (flash) or something. Arrays in ActionScript are always indexed by integer, but they're sparse arrays, so I'm really not sure about how it does the lookups.
I meant Qt QML JavaScript which, AFAIK, does not yet support typed arrays. It looks like Qt developers are considering moving to V8 JavaScript Engine, Node.js, etc.
Anyway, the question is more general than just typed arrays. I am looking for elastic non-associative arrays which can store elements of "any" type - like Perl arrays do.
Thanks for clarification - JavaScript is not as bad as I thought it was reading unreliable sources. And even is consistent with Perl regarding [...] vs {...}:
Quote:
So I will say it again: Array is not meant to be used for key/value pairs. Luckily, there is a dead-simple way to fix this. In the above example, you need only change Array to Object. (Or, if you’re using literal syntax, change [] to {}.) There. Your wrong code is no longer wrong, and it took only a little more work than a simple find-and-replace.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.