Permalink
Browse files

add objectify and stringify function usage in readme.

  • Loading branch information...
fbzhong committed May 8, 2011
1 parent cdd8bed commit 1819db335ea1bda6e3dd8d7506ad6cc60b0bbafb
Showing with 27 additions and 7 deletions.
  1. +26 −6 README.markdown
  2. +1 −1 test.js
View
@@ -22,20 +22,34 @@ Install Node-CityHash:
64-bit hash object:
{
- low: {unsigned long}, eg 1727229466
- high: {unsigned long}, eg 1535838579
+ low: {unsigned long}, eg 1727229466.
+ high: {unsigned long}, eg 1535838579.
uint64: {boolean} true if hash object is uint64. Otherwise undefined.
- value: {string}, eg "6596376470467341850"
+ value: {string}, eg "6596376470467341850".
}
128-bit hash object:
{
- low: {64-bit hash object}
- high: {64-bit hash object}
+ low: {64-bit hash object}.
+ high: {64-bit hash object}.
uint128: {boolean} true if hash object is uint128. Otherwise undefined.
- value: {string}, "low64,high64", eg "9138004313465017137,12242971252332641544"
+ value: {string}, "low64,high64", eg "9138004313465017137,12242971252332641544".
}
+ /**
+ * convert string or number to hash object.
+ * @param {unsigned long long | string} the string or number to be convered to hash object.
+ * @return {hash} 64-bit hash object or 128-bit hash object.
+ **/
+ function objectify(obj);
+
+ /**
+ * stringify the hash object.
+ * @param {hash} 64-bit hash object or 128-bit hash object.
+ * @return {string} the hash string value, eg "6596376470467341850" or "9138004313465017137,12242971252332641544".
+ **/
+ function stringify(obj);
+
/**
* Compute hash for str by CityHash64().
* @param {string} str The string to compute hash.
@@ -66,6 +80,12 @@ Install Node-CityHash:
var cityhash = require('node-cityhash');
var hash;
+ hash = cityhash.stringify({low:1727229466, high:1535838579});
+ // hash = '6596376470467341850'
+
+ hash = cityhash.objectify('6596376470467341850');
+ // hash = {low: 1727229466, high: 1535838579, uint64: true}
+
hash = cityhash.hash64('Hello');
// hash = {
// low: 1727229466,
View
@@ -43,7 +43,7 @@ function end() {
}
assertEqual('6596376470467341850', cityhash.stringify({low:1727229466, high:1535838579}), 'Stringify for uint64 object');
-assertEqual({low:1727229466, high:1535838579}, cityhash.objectify('6596376470467341850'), 'Objectify for uint64 hash string');
+assertEqual({low:1727229466, high:1535838579, uint64:true}, cityhash.objectify('6596376470467341850'), 'Objectify for uint64 hash string');
assertEqual('9138004313465017137,12242971252332641544', cityhash.stringify({
"low": {

0 comments on commit 1819db3

Please sign in to comment.