Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Difference between two arrays Date: Tue, 27 May 2014 19:29:55 +0200 Organization: PointedEars Software (PES) Lines: 29 Message-ID: <3093387.6XATB55v6P@PointedEars.de> References: <0.e9255226716292b2ac8f.20140527134102BST.87lhtne6n5.fsf@bsb.me.uk> <0.d67fc9b63bd18d976391.20140527171603BST.87wqd7ci4c.fsf@bsb.me.uk> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1401211798 12090 eJwNyscBgAAIBLCVRDjKONT9R9C8A1bSNlGo4HA0sCVHUOij1lmoFZqrK8N65rv+j2b3YJsPG9wRSA== (27 May 2014 17:29:58 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 27 May 2014 17:29:58 +0000 (UTC) User-Agent: KNode/4.12.4 X-User-ID: eJwNy8kBwCAIBMCWgrKLlMNl/yWY+Q82hWVKUHFxQ+Z4GJo5li3TR/vkilSDh9BXUwSF0OnVn9vfwG2ldUUfZ+MVng== Cancel-Lock: sha1:Qsq1uotYyNL8oZKAWMvNwlR7vs8= X-NNTP-Posting-Host: eJwFwQkBwDAIA0BLLZBQ5PAM/xJ2B+VluxE0LNZerdixhltIuWTiTmSn1PAig61n4vB9609/FJEQ0g== Xref: csiph.com comp.lang.javascript:24445 Ben Bacarisse wrote: > As Thomas has pointed out, I was assuming that your arrays are arrays of > non-negative integers, as in your examples, but you don't say that so > it's quite possible that I've made too much of the examples. > > If the arrays don't all contain values that can act as array indexes, > you can still invert the array but you can't get an array as the > result. Even if the arrays are of non-negative integers that are smaller than 2³²−1, a further requirement for inversion (values become keys and vice-versa) is uniqueness of (the string representation) of values (as can be expected from a set, but not an array). Otherwise you will need a hash-table implementation because same original-values will map to different original- indexes. The upper index limit can be increased to 2⁵³−1 with jsx.array.BigArray in JSX:array.js. Set and hash-table implementations can be created by reusing jsx.map.Map (with different Bucket setters and getters). JSX:python.js contains a Set implementation (jsx.python.set [1]); the part that does not use Map is erroneous. [1] -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.