Re: Hashing article title, will it always be unique?
- From: "Michel Walsh" <vanderghastArobaseMsnDotCom@xxxxxxxxxx>
- Date: Mon, 25 Feb 2008 14:08:51 -0500
With a table from a database (MS SQL Server). Your table has two fields, the primary key, an autonumber automatically generated, and the second field, a nvarchar(255) with an index unique but with ignore_dup_key on.
Insert the new title in the table.
INSERT INTO hashTable(secondFieldName) VALUES('microsoft csharp news group')
If the title does not exist, it will be appended. If the title exists, it will be rejected (unique constraint). You can also insert a batch of titles:
INSERT INTO hashTable(secondFieldName) SELECT titles FROM otherTable
and the new titles will be appended, while the existing ones will be rejected (that is because of the ignore_dup_key set to on; if set to false, all the 'batch' would be rejected).
Next, to get the hash number, make a 'lookup' over the title, returning the primary key.
SELECT primaryKey FROM hashTable WHERE secondFieldName='microsoft csharp news group'
That returns the long integer value that satisfy your definition, even if it is not a hash value 'per se'. Since the second field is also indexed, finding the hash value should not be really too slow, even if the hashTable is large. If two titles are the same, they will return the same 'hash value', since only one sample of the title would have been saved in the table (due to the UNIQUE constraint).
Vanderghast, Access MVP.
"DotNetNewbie" <snowman908070@xxxxxxxxx> wrote in message news:c33519be-ef00-477b-b96e-0bac511cd232@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I need to hash the Title of my articles, will the hashed value ALWAYS
be unique so long as the Title is unique?
Example:
string title = "microsfoft csharp news group";
int hash = title.GetHashCode();
.
- References:
- Hashing article title, will it always be unique?
- From: DotNetNewbie
- Hashing article title, will it always be unique?
- Prev by Date: Re: Console application checking if .NET installed
- Next by Date: Which .net features exactly are exposed through the language?
- Previous by thread: Re: Hashing article title, will it always be unique?
- Next by thread: Re: Hashing article title, will it always be unique?
- Index(es):
Relevant Pages
|