CodeShare
Have some code. Share some code.
cancel
Showing results for 
Search instead for 
Did you mean: 
Nat_Thirasuttakorn
F5 Employee
F5 Employee

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]"
}
Version history
Last update:
‎17-Mar-2015 13:59
Updated by:
Contributors