Пример #1
0
Файл: hash.c Проект: sasw/opflex
/* Returns the hash of the 'n' 32-bit words at 'p', starting from 'basis'.
 * 'p' must be properly aligned. */
uint32_t
hash_words(const uint32_t p[], size_t n_words, uint32_t basis)
{
    uint32_t hash;
    size_t i;

    hash = basis;
    for (i = 0; i < n_words; i++) {
        hash = mhash_add(hash, p[i]);
    }
    return mhash_finish(hash, n_words * 4);
}
Пример #2
0
/* Returns a hash value for the bits of 'flow' that are active based on
 * 'wc', given 'basis'. */
uint32_t
flow_hash_in_wildcards(const struct flow *flow,
                       const struct flow_wildcards *wc, uint32_t basis)
{
    const uint32_t *wc_u32 = (const uint32_t *) &wc->masks;
    const uint32_t *flow_u32 = (const uint32_t *) flow;
    uint32_t hash;
    size_t i;

    hash = basis;
    for (i = 0; i < FLOW_U32S; i++) {
        hash = mhash_add(hash, flow_u32[i] & wc_u32[i]);
    }
    return mhash_finish(hash, 4 * FLOW_U32S);
}
Пример #3
0
/* Returns a hash value for the bits of range [start, end) in 'minimatch',
 * given 'basis'.
 *
 * The hash values returned by this function are the same as those returned by
 * flow_hash_in_minimask_range(), only the form of the arguments differ. */
uint32_t
minimatch_hash_range(const struct minimatch *match, uint8_t start, uint8_t end,
                     uint32_t *basis)
{
    const uint32_t *p;
    uint64_t map = miniflow_get_map_in_range(&match->mask.masks, start, end,
                                             &p);
    const ptrdiff_t df = match->mask.masks.values - match->flow.values;
    uint32_t hash = *basis;

    for (; map; map = zero_rightmost_1bit(map)) {
        if (*p) {
            hash = mhash_add(hash, *(p - df) & *p);
        }
        p++;
    }
    *basis = hash; /* Allow continuation from the unfinished value. */
    return mhash_finish(hash, (p - match->mask.masks.values) * 4);
}
Пример #4
0
Файл: hash.c Проект: sasw/opflex
/* Returns the hash of the 'n' bytes at 'p', starting from 'basis'. */
uint32_t
hash_bytes(const void *p_, size_t n, uint32_t basis)
{
    const uint32_t *p = p_;
    size_t orig_n = n;
    uint32_t hash;

    hash = basis;
    while (n >= 4) {
        hash = mhash_add(hash, get_unaligned_u32(p));
        n -= 4;
        p += 1;
    }

    if (n) {
        uint32_t tmp = 0;

        memcpy(&tmp, p, n);
        hash = mhash_add__(hash, tmp);
    }

    return mhash_finish(hash, orig_n);
}
Пример #5
0
Файл: hash.c Проект: sasw/opflex
/* Returns the hash of 'a', 'b', and 'c'. */
uint32_t
hash_3words(uint32_t a, uint32_t b, uint32_t c)
{
    return mhash_finish(mhash_add(mhash_add(mhash_add(a, 0), b), c), 12);
}