Fowler Noll Vo (FNV) Hash Calculation

Problem this snippet solves:

This sample iRule shows how to calculate FNV or Fowler / Noll / Vo Hash.

Code :

when RULE_INIT {
    set fnv_hash 0x811c9dc5
    # 2166136261
    set fnv_prime 0x01000193
    # 16777619

    set fnv_str "teststring"

    for { set fnv_i 0 } { $fnv_i < [string length $fnv_str] } { incr fnv_i } {
        binary scan $fnv_str @${fnv_i}H2 fnv_str_i
        set fnv_hash [expr $fnv_hash ^ 0x$fnv_str_i]
        set fnv_hash [expr $fnv_hash * $fnv_prime]
    }
    set fnv_hash [expr $fnv_hash & 0xffffffff]
    log local0. "FNV HASH = [format 0x%x $fnv_hash]"
}
Published Mar 17, 2015
Version 1.0
No CommentsBe the first to comment