]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/batman-adv/hash.h
Merge branch 'for-3.8' of git://linux-nfs.org/~bfields/linux
[karo-tx-linux.git] / net / batman-adv / hash.h
index 977de9c75fc27010c1fd98dd3e11e3aa459ebe41..e05333905afd566117bf1267d6e3ac05596c89c1 100644 (file)
@@ -81,6 +81,28 @@ static inline void batadv_hash_delete(struct batadv_hashtable *hash,
        batadv_hash_destroy(hash);
 }
 
+/**
+ *     batadv_hash_bytes - hash some bytes and add them to the previous hash
+ *     @hash: previous hash value
+ *     @data: data to be hashed
+ *     @size: number of bytes to be hashed
+ *
+ *     Returns the new hash value.
+ */
+static inline uint32_t batadv_hash_bytes(uint32_t hash, void *data,
+                                        uint32_t size)
+{
+       const unsigned char *key = data;
+       int i;
+
+       for (i = 0; i < size; i++) {
+               hash += key[i];
+               hash += (hash << 10);
+               hash ^= (hash >> 6);
+       }
+       return hash;
+}
+
 /**
  *     batadv_hash_add - adds data to the hashtable
  *     @hash: storage hash table