Re: [Vala] FNV Hash algorithm



On Sun, Jan 8, 2012 at 8:19 PM, Denis Kuzmenok <forward_ua ukr net> wrote:

Solved only my making C library and calling via Vapi file =\

What  is  the  equivalent of this C code in vala (For utf8 string also
should work)?

typedef u_int64_t Fnv64_t;
#define FNV_64_INIT ((Fnv64_t)0x84222325cbf29ce4ULL)
#define FNV_64_PRIME ((Fnv64_t)0x100000001b3ULL)

Fnv64_t
fnv_64_str(char *str)
{
       Fnv64_t hval = FNV_64_INIT;
   unsigned char *s = (unsigned char *)str;

   while (*s) {
               hval *= FNV_64_PRIME;
               hval ^= (Fnv64_t)*s++;
   }

   return hval;
}


The problem might be in the signedness of the string in vala. Try using
exactly this code (with some variation), using pointers, and it should work
fine.

-- 
www.debian.org - The Universal Operating System


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]