Support time discretization in scripts

This can be used to ensure parameter refresh times are aligned (as
opposed to using Date.now() - X). It also allows for possible future
optimizations by exploiting the fact that the value of Date.now(X)
remains static for a given amount of time.

The variance value can be used to shift the discretization threshold
points based on the hash of the device ID for load distribution.

The djb2 hashing algorithm has been replaced with MD5 for better
distribution.
This commit is contained in:
Zaid Abdulla committed 2017-11-10 14:34:24 -08:00
1 parent ed873cdd4a
commit 6a9c62b639
6 files changed
+121 -47

No files matched your search

-10
View File
@@ -18,7 +18,6 @@
###
buffer = require 'buffer'
querystring = require 'querystring'
UNDEFINED_TYPE = '[object Undefined]'
NULL_TYPE = '[object Null]'
@@ -224,14 +223,6 @@ escapeRegExp = (str) ->
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
# djb2 hashing algorithm adapted from http://www.cse.yorku.ca/~oz/hash.html
djb2 = (str) ->
hash = 5381
for i in [0...str.length]
hash = ((hash << 5) + hash) ^ str.charCodeAt(i)
return hash
exports.UNDEFINED_TYPE = UNDEFINED_TYPE
exports.NULL_TYPE = NULL_TYPE
exports.NUMBER_TYPE = NUMBER_TYPE
@@ -246,4 +237,3 @@ exports.parsePath = parsePath
exports.addPathMeta = addPathMeta
exports.hammingWeight = hammingWeight
exports.escapeRegExp = escapeRegExp
exports.djb2 = djb2