3 people like it.

CRC-32 implementation

An implementation of a CRC-32 algorithm, as described in RFC-1952 "GZIP file format specification version 4.3"

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
module private Internal =
    let crcTable = 
        let inline nextValue acc =
            if 0u <> (acc &&& 1u) then 0xedb88320u ^^^ (acc >>> 1) else acc >>> 1
        let rec iter k acc =
            if k = 0 then acc else iter (k-1) (nextValue acc)
        [| 0u .. 255u |] |> Array.map (iter 8)


/// Returns the CRC-32 value of 'name' as specified by RFC1952
let crc32 (name:string) =
    let inline update acc (ch:char) =
        Internal.crcTable.[int32 ((acc ^^^ (uint32 ch)) &&& 0xffu)] ^^^ (acc >>> 8)
    0xFFffFFffu ^^^ Seq.fold update 0xFFffFFffu name
val private crcTable : uint32 []

Full name: Script.Internal.crcTable
val nextValue : (uint32 -> uint32)
val acc : uint32
val iter : (int -> uint32 -> uint32)
val k : int
module Array

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val crc32 : name:string -> uint32

Full name: Script.crc32


 Returns the CRC-32 value of 'name' as specified by RFC1952
val name : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val update : (uint32 -> char -> uint32)
val ch : char
Multiple items
val char : value:'T -> char (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.char

--------------------
type char = System.Char

Full name: Microsoft.FSharp.Core.char
module Internal

from Script
Multiple items
val int32 : value:'T -> int32 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int32

--------------------
type int32 = System.Int32

Full name: Microsoft.FSharp.Core.int32
Multiple items
val uint32 : value:'T -> uint32 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.uint32

--------------------
type uint32 = System.UInt32

Full name: Microsoft.FSharp.Core.uint32
module Seq

from Microsoft.FSharp.Collections
val fold : folder:('State -> 'T -> 'State) -> state:'State -> source:seq<'T> -> 'State

Full name: Microsoft.FSharp.Collections.Seq.fold
Raw view Test code New version

More information

Link:http://fssnip.net/dS
Posted:11 years ago
Author:Henrik Ravn
Tags: crc