top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

hash function and combining function/operator in perl

+1 vote
713 views

I'm looking for a hash function and a related function or operator such that:

 H(string1 . string2) = f(H(string1), H(string2))
 H(string1 . string2) = H(string1) op H(string2)

 where:
 H() is the hash function    
 string1 is a string
 string2 is a string    
 . is the string concatenation operator 
 f() is a function
 op is a binary operator

Any suggestions?

posted Sep 23, 2013 by Abhay Kulkarni

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

My immediate thought is that the only hash function that can work like this is the identity function (or any one-one mapping) because, by extension, the hash of a string must be equal to f(the hash of each of
its characters).

Not that I can prove this at present, of course! Could you explain the problem you're trying to solve?

answer Sep 23, 2013 by Seema Siddique
Writing scripts that look for duplicate, similar, and/or missing files.
I don't know the answer but... it sounds like NCBI's BLAST to me, which compares nucleotide or protein sequences. NCBI's FTP site provides local BLAST binaries, and bioperl offers some convenient tools to implement it.
That looks like server-side software, callable via a WWW UI and/or Perl modules (?).
Where is the design documentation for BLAST -- especially the hashing algorithms?
Another look at it, and I think I've pointed you to a wrong way. BLAST might not what you need. Sorry about this.
Similar Questions
+1 vote

This was asked today in interview any pointer.

"Design a unique hash function for every tweet in Twitter"

+1 vote

I would retrieve my hash table when i pass it in argument at a function. In my case, function1 return my hash table, then i pass my hash table in argument to my function2 and in my function2 i would retrieve my hash table for browse it.

sub function1{
    my code;
    return %hash;
}

sub function2{
    my %hash=$_[0];
    my code browse my hash;
}

my %hash = function1();
function2(%hash);

I have the following error : Odd number of elements in hash assignment at

+2 votes

I want to print one hash with one key undefined . I have condition print if key exist . I guess it should not print value for undefined key, but it does .

#!/usr/bin/perl -w

@array = ("abc", 123, "dfg" ,456, "xsd",undef);
%hash = reverse @array;

foreach $k (keys %hash){
 print "key $k value $hash{$k}n" if(exists $hash{$k});
 }

And another issue is , I want to write one line code for printing hash like below:

 print "key $k value $hash{$k}n" foreach $k (keys %hash);

But it fails with error :

syntax error at my_test.pl line 16, near "$k ("
Execution of my_test.pl aborted due to compilation errors.

Please point me where am I wrong?

...