Well, in this case I think GetHashCode() is a decent candidate. Please note that there are chances that different strings have identical hash codes.

You are going to the wrong direction, by the way, assuming that the sum of the hash codes of the segments of your url should be smaller than the hash code of the whole. In fact, the hash code generation algorithm for strings is, afaik, undocumented. Many of us believe it is MD5, however.

In order to have a "smaller" hash code you substantially have three alternatives (apart from rewriting your own hashing function); either you could format the hash code in a more "compressed" form using hexadecimal notation, for example, or using a custom encoding, so your integer could be represented by a combination of either letters and digits. The latter, more difficult to implement, give better results in compression terms. Another way consists in reducing the hash code itself, removing some of its data (ie: shift it right by n bits), gaining smaller codes at the cost of a greater chance of duplicates.

Hope this helps.

--
Efran Cobisi
http://www.cobisi.com

Paul Cowan wrote:
Hi,
What we want is a short int that we will put on the bottom of each page so users can call operators and identify the page in question by this human readable integer. In the same way as each page in a book has a page number. We could keep a big xml look up or something like that we could cache but the maintenance is unacceptable. I would like to be able to generate this number somehow. I was thinking of something like the following: string urlToHash = string.Empty;
for (int i = 0; i < Request.Url.Segments.Length; i++)
{
    string candidate = Request.Url.Segments[i].Replace("/", "").Replace(".aspx", 
"");
    if (candidate.Length == 0)
        continue;
    urlToHash += candidate;
}
int hashCode = urlToHash.GetHashCode();
The number is still quite big but I might go with this.
Is there anything other than GetHashCode I could use? Cheers Paul
[EMAIL PROTECTED]



Date: Wed, 11 Jul 2007 16:46:08 +0200> From: [EMAIL PROTECTED]> Subject: Re: [ADVANCED-DOTNET] Url generated int> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> > Hi Paul,> > What's wrong with that integer?> What about using an hashtable-structure instead? Would it be possible,> giving your 
requirements?> > --> Efran Cobisi> http://www.cobisi.com> > Paul Cowan wrote:> > Hi,> >> > I have a flowing quandary that I am struggling with. The long and the short of it is that we have the usual mix of static and dynamic pages for our ASP.NET 2.0 web site.> >> > What 
we need is a way of identifying each page on the site. The dynamic pages do not really worry me. What I would like to do is be able to identify each page with an int.> >> > The first thing that sprung to mind was:> >> > Request.Url.GetHashCode();> >> > This unfortunately brings 
back:> >> > -81369726> >> > For the folloiwng URL:> >> > http://localhost/ak/misc/sendtoafriend.aspx> >> > Can anyone think of a better way to generate a unique integer which we can tag our pages with? The only thing really unique is the url.> >> > Thanks> 
> [EMAIL PROTECTED]> > _________________________________________________________________> > Try Live.com - your fast, personalised homepage with all the things you care about in one place.> > http://www.live.com/?mkt=en-gb> > ===================================> > This list is hosted 
by DevelopMentor® http://www.develop.com> >> > View archives and manage your subscription(s) at http://discuss.develop.com> >> > ===================================> This list is hosted by DevelopMentor® http://www.develop.com> > View archives and manage your subscription(s) at 
http://discuss.develop.com
_________________________________________________________________
Feel like a local wherever you go with BackOfMyHand.com
http://www.backofmyhand.com
===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to