packages feed

DimensionalHash 0.1.1 → 0.1.3

raw patch · 2 files changed

+13/−12 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Data/DimensionalHash.hs view
@@ -13,33 +13,34 @@ 
 -- |Return an element having all bits set to 0, excepting the bit at n
 takeBitAt :: (Bits a) => a -> Int -> a
-takeBitAt x n = x .&. (shift 1 n)
+takeBitAt x n = x .&. (shiftL 1 n)
 
 -- |Return a list have shifted elements by (n + index)
 shiftElements :: (Bits a) => [a] -> Int -> [a]
 shiftElements [] n = []
-shiftElements (x:xs) n = [(shift x n)] ++ (shiftElements xs (n+1))
+shiftElements (x:xs) n = [(shiftL x n)] ++ (shiftElements xs (n+1))
 
 -- |Return a list have been shifted elements by n + index
-concatBits :: (Bits a) => [a] -> Int -> a
-concatBits list n = foldl (\acc x -> acc .|. x) 0 shiftedMap
+concatBits :: (Bits a) => [a] -> Int -> Int -> a
+concatBits list n npos = foldl (\acc x -> acc .|. x) 0 shiftedMap
 	where 	
-		shiftedMap = shiftElements mapList n
+		shiftedMap = shiftElements mapList npos
 		mapList = map (\x -> (takeBitAt x n)) list
 
-hash :: (Bits a) => [a] -> Int -> Int -> a
-hash list n precision
-	| n < precision = (concatBits list n) .|. (hash list (n + 1) precision)
-	| otherwise = concatBits list precision
+hash :: (Bits a) => [a] -> Int -> Int -> Int -> a
+hash list n npos precision
+	| length list == 1 = head list
+	| n < precision = (concatBits list n npos) .|. (hash list (n + 1) (npos + (length list) - 1) precision)
+	| otherwise = 0
 
 -- | recursevely compute the morton number.	
 class (Bits a) => (MortonNumber a) where	
 	dimensionalHash :: (Bits a) => [a] -> a
-	dimensionalHash list = hash list 0 (bitSize (head list))
+	dimensionalHash list = hash list 0 0 (bitSize (head list))
 
 -- Integer haven't a fixed bitsize
 instance MortonNumber Integer where
-	dimensionalHash list = hash list 0 32
+	dimensionalHash list = hash list 0 0 32
 
 -- Types that have a fixed bitsize are instance of MortonNumber
 instance MortonNumber Int8
DimensionalHash.cabal view
@@ -1,5 +1,5 @@ name:          DimensionalHash
-version:       0.1.1
+version:       0.1.3
 build-Type:    Simple
 cabal-version: >= 1.6
 tested-with:   GHC == 7.0.3