Created
May 14, 2012 02:42
-
-
Save hikoma/2691477 to your computer and use it in GitHub Desktop.
A hash function controls the address calculation of linear hashing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://dev.mysql.com/doc/refman/5.5/en/partitioning-linear-hash.html | |
DELIMITER $$ | |
DROP FUNCTION IF EXISTS linearHashing$$ | |
CREATE FUNCTION linearHashing(value INT, num INT) RETURNS INT DETERMINISTIC | |
BEGIN | |
SET @v := POWER(2, CEILING(LOG(2, num))); | |
SET @n := value & (@v - 1); | |
IF @n >= num THEN | |
SET @v := CEILING(@v / 2); | |
SET @n := @n & (@v - 1); | |
END IF; | |
RETURN @n; | |
END; | |
$$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment