This technique seems like a waste of processing time when the underlying
Java object already provides the same thing. From the documentation...

hashCode
public int hashCode()

Returns the hash code value for this map. The hash code of a map is
defined to be the sum of the hash codes of each entry in the map's
entrySet() view. This ensures that t1.equals(t2) implies that
t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by
the general contract of Object.hashCode.

This implementation iterates over entrySet(), calling hashCode on each
element (entry) in the Collection, and adding up the results.

See my earlier response to the question for an example of using the
hashCode method with a Map.

Matt Liotta
President & CEO
Montara Software, Inc.
http://www.montarasoftware.com/
888-408-0900 x901

> -----Original Message-----
> From: Christian Cantrell [mailto:qantrell@;yahoo.com]
> Sent: Tuesday, October 29, 2002 10:08 PM
> To: CF-Talk
> Subject: Re: Shorter urls?
> 
> Here's an interesting solution.  It's not perfect (just threw the code
> together), but it works.  It has the additional benefit of adding a
> level of security to your application because it hashes your query
> string in a way that cannot be reversed (essentially obfuscates it in
a
> non-reversible manner).  It also assumes that once you have created a
> shorter query string, you will eventually want to recover the original
> query string, probably in the page processing the request that
contains
> the query string.
> 
> Start by including these two functions:
> 
> <cfscript>
>      function getShortString(str) {
>          var key = "";
>          if (false is isDefined("application._strMap")) {
>              application._strMap = structNew();
>          }
>          key = hash(str);
>          application._strMap[key] = str;
>          return key;
>      }
> 
>      function getLongString(key) {
>          if (false is isDefined("application._strMap")) {
>              return "";
>          }
> 
>          if (false is structKeyExists(application._strMap, key)) {
>              return "";
>          }
>          return application._strMap[key];
>      }
> </cfscript>
> 
> Then create your querystrings like this:
> 
> <cfset qs = "a=b&b=c&c=a" />
> <a
>
href="someProcessingPage.cfm?q=<cfoutput>#getShortString(qs)#</cfoutput>
">
> click
> here</a>
> 
> In the processing page, retrieve the original querystring like this:
> 
> <cfset qs = "#getLongString(url.q)#" />
> The full querystring is <cfoutput>#qs#</cfoutput>.
> 
> Of course, you could do something a little more clever like creating a
> function that returns a struct or parses the querystring and puts the
> values in the URL scope so that you could retrieve them just as though
> they were literally passed in the URL as opposed to actually getting
> back a query string, but you get the idea.
> 
> Your query string has to be over 32 characters before this technique
> starts to pay for itself in terms of length since the hash() function
> returns a 32 byte string.  As I mentioned earlier, it has the added
> benefit of completely obscruing the data you pass in your query
string,
> too, since the MD5 hash is not reversable.
> 
> If you decide to implement something like this, consider variable
locking.
> 
> Hope this helps.
> 
> Cantrell
> 
> Ian Lurie wrote:
> > Hi all,
> >
> > I've searched the devcenter, google, etc. but can't seem to find any
> > discussion of how to generate shorter URL strings. I want to take:
> >
> > http://www.site.com?action=blah&brand=1&name=blahblah&;....
> >
> > And convert it to
> >
> > http://www.site.com/asdfwer234123
> >
> > I've seen it done but just can't remember where. Can someone send me
a
> url?
> >
> > Thanks in advance,
> >
> > Ian
> 
> 
> --
> Christian Cantrell
> [EMAIL PROTECTED]
> (571) 220-8659 (mobile)
> 
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

Reply via email to