a unique number for a word

Hello all. I am trying to take a unique value for a wide string, with the function.

1
2
3
4
5
6
7
8
9
10
11
long int UniqueCode(wchar_t* ch)
{
long power=127.0;
        long int code=0;
        int res,j=0;
        for (;*ch;ch++) {
                res=*ch;
                code+=res*pow(power,j++);
        }
        return code;
}


But at some different words i have the same resaults.
Also when the word is big the resault is negative, bacause of limits.
Any ideas?


Last edited on
Google CRC32. It's still quite likely to get collisions, though. If you want to have a little more certainty that there won't be any collisions, Google MD5 or SHA-1.
wchar_t has more biytes I think

now power=2^(sizeof(wchar_t)*8) and if its signed than you need to make it unsigned(at leas make it appear unsigned) so after res=*ch; res+=power/2;
Last edited on
Here is the all routine, but it seems have a bug...
In this routine there is a unique subcode for the same string.
Any improovment?
To use an md5 etc.. is an all story...
Difficault for me.


1
2
3
4
5
6
7
8
9
10
11
12
13
unsigned long int UniqueCode(wchar_t* ch, int sbCode)
{
        long power=2^(sizeof(wchar_t)*8);
        long int code=0;
        int res,j=0;
        for (;*ch;ch++) {
                res=*ch;
                res+=power/2;
                code+=res*pow(power+0.0,j++);
        }
        code+=sbCode*2^j;
        return code;
}
Last edited on
You are trying to take N significant bits and compress them into <N significant bits. There will always be collisions. It is not a 1:1 function.
Last edited on
New idea, function etc ?
What are you trying to do with this?
It is a very complicate project, and i think i am finish, and without this function. It is about control in Greek anssient text, that means utf8. I convert the hole project to c++, without knowing STL, and reading and asq.
Thanks all for the great help.
Topic archived. No new replies allowed.