2 * Copyright (c) 2008, 2009, 2010, 2012 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "unaligned.h"
21 /* Returns the hash of the 'n' 32-bit words at 'p', starting from 'basis'.
22 * 'p' must be properly aligned. */
24 hash_words(const uint32_t *p, size_t n, uint32_t basis)
28 a = b = c = 0xdeadbeef + (((uint32_t) n) << 2) + basis;
48 hash_final(&a, &b, &c);
56 /* Returns the hash of 'a', 'b', and 'c'. */
58 hash_3words(uint32_t a, uint32_t b, uint32_t c)
63 hash_final(&a, &b, &c);
67 /* Returns the hash of 'a' and 'b'. */
69 hash_2words(uint32_t a, uint32_t b)
71 return hash_3words(a, b, 0);
74 /* Returns the hash of the 'n' bytes at 'p', starting from 'basis'. */
76 hash_bytes(const void *p_, size_t n, uint32_t basis)
78 const uint8_t *p = p_;
81 a = b = c = 0xdeadbeef + n + basis;
84 a += get_unaligned_u32((uint32_t *) p);
85 b += get_unaligned_u32((uint32_t *) (p + 4));
86 c += get_unaligned_u32((uint32_t *) (p + 8));
95 tmp[0] = tmp[1] = tmp[2] = 0;
100 hash_final(&a, &b, &c);