packages feed

DimensionalHash (empty) → 0.0

raw patch · 4 files changed

+84/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ Data/DimensionalHash.hs view
@@ -0,0 +1,37 @@+--
+-- Morton number generator
+-- Can be used as a 2 or 3 dimensional hash
+
+module Data.DimensionalHash  
+(
+  MortonNumber(..)
+) where
+
+
+import Data.Bits
+
+class (Bits a) => (MortonNumber a) where
+	-- 3d morton number generation
+	toMortonNumber3d :: a -> a -> a -> a
+	toMortonNumber3d x y z =
+			x4 .|. (shift y 1) .|. (shift z 2)
+		where 
+			x1 = (x  .|. (shift x 16)) .&. 0x030000FF
+			x2 = (x1 .|. (shift x1 8)) .&. 0x0300F00F
+			x3 = (x2 .|. (shift x2 4)) .&. 0x030C30C3
+			x4 = (x3 .|. (shift x3 2)) .&. 0x09249249
+
+	-- 2d morton number generation		
+	toMortonNumber2d :: a -> a -> a
+	toMortonNumber2d x y = x4 .|. (shift y4 1)
+		where
+			x1 = (x  .|. (shift x  8)) .&. 0x00FF00FF
+			x2 = (x1 .|. (shift x1 4)) .&. 0x0F0F0F0F
+			x3 = (x2 .|. (shift x2 2)) .&. 0x33333333
+			x4 = (x3 .|. (shift x3 1)) .&. 0x55555555
+			y1 = (y  .|. (shift y  8)) .&. 0x00FF00FF
+			y2 = (y1 .|. (shift y1 4)) .&. 0x0F0F0F0F
+			y3 = (y2 .|. (shift y2 2)) .&. 0x33333333
+			y4 = (y3 .|. (shift y3 1)) .&. 0x55555555
+
+instance MortonNumber Integer
+ DimensionalHash.cabal view
@@ -0,0 +1,18 @@+name:          DimensionalHash
+version:       0.0
+build-Type:    Simple
+cabal-version: >= 1.6
+tested-with:   GHC == 7.0.3
+license:       BSD3
+license-File:  LICENSE
+author:        Ghassen Hamrouni
+maintainer:    ghamrouni@iptechinside.com
+category:      Data, Algorithms
+synopsis:      2 and 3 dimensional hash using Morton numbers.
+description:   This library compute the Morton numbers in 2d and 3d. 
+			   It transforms integers x, y to a single integer z.
+               The hash z has the property : if (x, y) and (x2, y2) 
+               are close then their Morton numbers are close.
+library				
+  build-Depends:  base >= 3 && < 5
+  exposed-modules:  Data.DimensionalHash
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright 2011, Ghassen Hamrouni.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++- Redistributions of source code must retain the above copyright notice,+this list of conditions and the following disclaimer.+ +- Redistributions in binary form must reproduce the above copyright notice,+this list of conditions and the following disclaimer in the documentation+and/or other materials provided with the distribution.+ +- The names of the contributors may not be used to endorse or promote+products derived from this software without specific prior written+permission.++THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL+THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple
+main = defaultMainWithHooks defaultUserHooks