Hi Andrew,
Yes, this code will do the work, especially if
item.hashCode();
can be guaranteed to produce different values for different "item"s
Cheers,
Dimitre
On 7/29/07, Andrew Welch <andrew.j.welch@...> wrote:
> On 7/25/07, Dimitre Novatchev <dnovatchev@...> wrote:
> > > Well, there's going to be a fixed time T to create the array, and then a
> > > constant time t to access each member. If you use lazy evaluation, the only
> > > difference is that the cost T will be distributed so that some of the member
> > > access values are increased to t+T/x. The total time will be the same or
> > > smaller, so how can you tell the difference?
> >
> > Some people need to be able to time their implementations in a
> > reliable/consistent way. Having an accidental T/x distorts the picture
> > (and will distort it most of the time)
> >
> > > Sorry, don't understand your use case here at all. Surely if generate-id()
> > > returns anything for an atomic value, it would return that value? Atomic
> > > values and sequences don't have an identity, they only have a value, so the
> > > notion of an id (or pointer) seems flawed.
> >
> > If the value is a 2MB string, then why not identify this 2MB string
> > with something much more compact (say with an integer)?
> >
> > The same goes for a sequence of 2000000 items.
>
> Hi Dimitre,
>
> I'm not too sure what your goal is here, but I think a simple
> extension function might be what you're requesting:
>
> public class HashMapExt {
>
> private static HashMap hashmap = new HashMap();
>
> public static int put(Object item) {
> int hc = item.hashCode();
> hashmap.put(hc, item);
> return hc;
> }
>
> public static Object get(int key) {
> return hashmap.get(key);
> }
> }
>
> and then:
>
> <xsl:variable name="stringIDs" select="for $x in ('def', 'abc') return
> hm:put($x)"/>
> <xsl:for-each select="for $x in $stringIDs return hm:get($x)">
> <xsl:sort select="."/>
> <xsl:copy-of select="."/>
> </xsl:for-each>
>
> produces:
>
> abc def
>
> The extension takes the item and returns the hash code for it - the
> simple integer representation you were after. The $stringIDs variable
> holds a sequence of integers, and the get() method returns the
> original strings given the hash code.
>
> Is that what you meant?
>
>
> --
> http://andrewjwelch.com
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> saxon-help mailing list
> saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
|