Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / include / blobhash.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2 /*
3  * Ceph - scalable distributed file system
4  *
5  * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
6  *
7  * This is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License version 2.1, as published by the Free Software 
10  * Foundation.  See file COPYING.
11  * 
12  */
13
14 #ifndef CEPH_BLOBHASH_H
15 #define CEPH_BLOBHASH_H
16
17 #include "hash.h"
18
19 /*
20 - this is to make some of the STL types work with 64 bit values, string hash keys, etc.
21 - added when i was using an old STL.. maybe try taking these out and see if things 
22   compile now?
23 */
24
25 class blobhash {
26 public:
27   uint32_t operator()(const char *p, unsigned len) {
28     static rjhash<uint32_t> H;
29     uint32_t acc = 0;
30     while (len >= sizeof(acc)) {
31       acc ^= *(uint32_t*)p;
32       p += sizeof(uint32_t);
33       len -= sizeof(uint32_t);
34     }
35     int sh = 0;
36     while (len) {
37       acc ^= (uint32_t)*p << sh;
38       sh += 8;
39       len--;
40       p++;
41     }
42     return H(acc);
43   }
44 };
45
46
47 #endif