Re: Hashing article title, will it always be unique?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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();




.



Relevant Pages

  • Re: storing byte values
    ... constraint which includes the column with the byte values? ... RAW column in a table (don't confuse RAW with LONG RAW, ... won't work unless you use large block size and a composite primary key ... and then hash the data using SHA-1 ...
    (comp.databases.oracle.misc)
  • Re: storing byte values
    ... RAW column in a table (don't confuse RAW with LONG RAW, ... won't work unless you use large block size and a composite primary key ... ensure uniqueness of your binary data. ... and then hash the data using SHA-1 ...
    (comp.databases.oracle.misc)
  • Re: SQL TOP 50,000 Help
    ... A lot of the time, people use AutoNumber as their primary key, and the ... the column used to generate the hash number contains many equal ... to ensure equal distribution of values. ... Of course, there might be a few duplicate numbers generated, ...
    (microsoft.public.access.formscoding)
  • Re: Get the First record
    ... >>function of the hash should have the same effect, ... There were two approaches in this hashing algorithm: ... If the primary key was numeric and the key value was less than the ... which was given the term "migrating secondaries". ...
    (comp.lang.php)
  • Re: misunderstanding with the function split
    ... push @authors, $author; ... push @titles, $title; ... Can I use a hash array to do what I wanted initially that is to say if I ...
    (perl.beginners)