Data-Hash-Consistent-0.1.1: Provide a simple consistent hashing mechanism

Safe HaskellNone




A consistent hash is a technique to manage the fair distribution of cacheable entities among hosts. Each host identifier has its crc32 hash calculated and stored in a Vector along with its canonical host name. The host identifier may be differentiated from its canonical host name by a multiplying factor, in our case a simple integer appeneded to the hostname to provide it with a number of entries in the consistent hash, all evenly distributed.

This technique is explained in these links:



Here is a small program illustrating its use:

module Main where
  import qualified Data.Hash.Consistent as CH

main = do
    let hosts  = [,,] :: [CH.Host]
    let n = 2 :: Int
    let ch =
    print $ show $ ch
    ch <- return $ CH.add hosts n ch
    print $ show $ ch  
    let fh = [head hosts] :: [CH.Host]
    let hh_fh = CH.hashHosts fh n
    print hh_fh
    ch <- return $ CH.del fh n ch
    print $ show $ ch  
    let i = 770931073
    let tgt = CH.targetHost i ch 
    print tgt
    return ()

License info:

The license is a simple BSD3-style license available here: https:www.b7j0c.orgstufflicense.txt