-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Provide a simple consistent hashing mechanism -- -- Provide a simple consistent hashing mechanism @package Data-Hash-Consistent @version 0.1.1 -- | Data.Hash.Consistent -- -- 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: -- -- http:en.wikipedia.orgwikiConsistent_hashing -- -- -- http:www.tomkleinpeter.com20080317programmers-toolbox-part-3-consistent-hashing/ -- -- Here is a small program illustrating its use: -- --
-- module Main where -- import qualified Data.Hash.Consistent as CH -- -- main = do -- let hosts = [hi.example.net,bar.example.net,foo.example.net] :: [CH.Host] -- let n = 2 :: Int -- let ch = CH.new -- 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 module Data.Hash.Consistent textCrc32 :: String -> Hash search :: Hash -> ConsistentHash -> Int add :: [Host] -> Int -> ConsistentHash -> ConsistentHash del :: [Host] -> Int -> ConsistentHash -> ConsistentHash new :: ConsistentHash targetHost :: Hash -> ConsistentHash -> HashHost hashHosts :: [Host] -> Int -> ConsistentHash type Host = String type Hash = Word32 type HashHost = (Hash, Host) type ConsistentHash = Vector HashHost