當前位置: 首頁>>代碼示例>>Python>>正文


Python xxhash.xxh32方法代碼示例

本文整理匯總了Python中xxhash.xxh32方法的典型用法代碼示例。如果您正苦於以下問題:Python xxhash.xxh32方法的具體用法?Python xxhash.xxh32怎麽用?Python xxhash.xxh32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xxhash的用法示例。


在下文中一共展示了xxhash.xxh32方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: lh_perturb

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def lh_perturb(real_dist, g, p):
    n = sum(real_dist)
    noisy_samples = np.zeros(n, dtype=object)
    samples_one = np.random.random_sample(n)
    seeds = np.random.randint(0, n, n)

    counter = 0
    for k, v in enumerate(real_dist):
        for _ in range(v):
            y = x = xxhash.xxh32(str(int(k)), seed=seeds[counter]).intdigest() % g

            if samples_one[counter] > p:
                y = np.random.randint(0, g - 1)
                if y >= x:
                    y += 1
            noisy_samples[counter] = tuple([y, seeds[counter]])
            counter += 1
    return noisy_samples 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:20,代碼來源:fo.py

示例2: thread_affinity

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def thread_affinity(url, total_worker_count):
	'''
	Ensure only one client ever works on each netloc.
	This maintains better consistency of user-agents
	'''

	# Only limit netlocs if we actually need to.
	if not getModuleForUrl(url).single_thread_fetch(url):
		return True

	netloc = urllib.parse.urlsplit(url).netloc

	m = xxhash.xxh32()
	m.update(netloc.encode("utf-8"))

	nlhash = m.intdigest()
	thread_aff = nlhash % total_worker_count
	# print("Thread affinity:", self.total_worker_count, self.worker_num, thread_aff, self.worker_num == thread_aff)
	return thread_aff 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:21,代碼來源:misc.py

示例3: perturb

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def perturb():
    global Y
    Y = np.zeros(n)
    for i in range(n):
        v = X[i]
        x = (xxhash.xxh32(str(v), seed=i).intdigest() % g)
        y = x

        p_sample = np.random.random_sample()
        # the following two are equivalent
        # if p_sample > p:
        #     while not y == x:
        #         y = np.random.randint(0, g)
        if p_sample > p - q:
            # perturb
            y = np.random.randint(0, g)
        Y[i] = y 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:19,代碼來源:olh.py

示例4: reduce_thread_id

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def reduce_thread_id(thread_id: int) -> str:
    """Make a shorter thread identifier by hashing the original."""
    return xxhash.xxh32(thread_id.to_bytes(8, "little")).hexdigest()[:4] 
開發者ID:src-d,項目名稱:modelforge,代碼行數:5,代碼來源:slogging.py

示例5: hash_netloc

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def hash_netloc(netloc):

	m = xxhash.xxh32()
	m.update(netloc.encode("utf-8"))
	nlhash = m.intdigest()

	return nlhash 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:9,代碼來源:rewalk_epoch.py

示例6: hash_file2

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def hash_file2(fpath, blocksize=65536, hasher='xx64'):
    r"""
    Hashes the data in a file on disk using xxHash

    xxHash is much faster than sha1, bringing computation time down from .57
    seconds to .12 seconds for a 387M file.

    my_weights_fpath_ = ub.truepath('~/tmp/my_weights.pt')


    xdata = 2 ** np.array([8, 12, 14, 16])
    ydatas = ub.ddict(list)
    for blocksize in xdata:
        print('blocksize = {!r}'.format(blocksize))
        ydatas['sha1'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='sha1', blocksize=blocksize).min())
        ydatas['sha256'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='sha256', blocksize=blocksize).min())
        ydatas['sha512'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='sha512', blocksize=blocksize).min())
        ydatas['md5'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='md5', blocksize=blocksize).min())
        ydatas['xx32'].append(ub.Timerit(2).call(hash_file2, my_weights_fpath_, hasher='xx32', blocksize=blocksize).min())
        ydatas['xx64'].append(ub.Timerit(2).call(hash_file2, my_weights_fpath_, hasher='xx64', blocksize=blocksize).min())

    import netharn as nh
    nh.util.qtensure()
    nh.util.multi_plot(xdata, ydatas)
    """
    import xxhash
    if hasher == 'xx32':
        hasher = xxhash.xxh32()
    elif hasher == 'xx64':
        hasher = xxhash.xxh64()

    with open(fpath, 'rb') as file:
        buf = file.read(blocksize)
        # otherwise hash the entire file
        while len(buf) > 0:
            hasher.update(buf)
            buf = file.read(blocksize)
    # Get the hashed representation
    text = ub.util_hash._digest_hasher(hasher, hashlen=None,
                                       base=ub.util_hash.DEFAULT_ALPHABET)
    return text 
開發者ID:Erotemic,項目名稱:ubelt,代碼行數:43,代碼來源:bench_hash_file.py

示例7: _seed

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def _seed(self, val):
        """Returns a unique seed for val and the (optional) namespace."""
        if self._namespace:
            return xxhash.xxh32(
                self._namespace.encode('utf-8') +
                Magnitude.RARE_CHAR +
                val.encode('utf-8')).intdigest()
        else:
            return xxhash.xxh32(val.encode('utf-8')).intdigest() 
開發者ID:plasticityai,項目名稱:magnitude,代碼行數:11,代碼來源:__init__.py

示例8: _seed

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def _seed(self, val):
        """Returns a unique seed for val and the (optional) namespace."""
        if self._namespace:
            return xxhash.xxh32(self._namespace + Magnitude.RARE_CHAR +
                                val.encode('utf-8')).intdigest()
        else:
            return xxhash.xxh32(val.encode('utf-8')).intdigest() 
開發者ID:plasticityai,項目名稱:magnitude,代碼行數:9,代碼來源:__init__.py

示例9: aggregate

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def aggregate():
    global ESTIMATE_DIST
    ESTIMATE_DIST = np.zeros(domain)
    for i in range(n):
        for v in range(domain):
            if Y[i] == (xxhash.xxh32(str(v), seed=i).intdigest() % g):
                ESTIMATE_DIST[v] += 1
    a = 1.0 * g / (p * g - 1)
    b = 1.0 * n / (p * g - 1)
    ESTIMATE_DIST = a * ESTIMATE_DIST - b 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:12,代碼來源:olh.py

示例10: perturb

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def perturb(self, datas, domain):
        n = len(datas)
        perturbed_datas = np.zeros(n, dtype=object)
        samples_one = np.random.random_sample(n)
        seeds = np.random.randint(0, n, n)
        for i in range(n):
            y = x = xxhash.xxh32(str(int(datas[i])), seed=seeds[i]).intdigest() % self.g
            # y = x = (datas[i] * seeds[i]) % self.g

            if samples_one[i] > self.p:
                y = np.random.randint(0, self.g - 1)
                if y >= x:
                    y += 1
            perturbed_datas[i] = tuple([y, seeds[i]])
        return perturbed_datas 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:17,代碼來源:lh.py

示例11: support_sr

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def support_sr(self, report, value):
        return report[0] == (xxhash.xxh32(str(value), seed=report[1]).intdigest() % self.g)
        # return report[0] == value * report[1] % self.g 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:5,代碼來源:lh.py

示例12: aggregate

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def aggregate(self, domain, perturbed_datas):
        n = len(perturbed_datas)

        ESTIMATE_DIST = np.zeros(domain, dtype=np.int32)
        for i in range(n):
            for v in range(domain):
                x = xxhash.xxh32(str(v), seed=perturbed_datas[i][1]).intdigest() % self.g
                # x = v * perturbed_datas[i][1] % self.g
                if perturbed_datas[i][0] == x:
                    ESTIMATE_DIST[v] += 1

        return ESTIMATE_DIST 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:14,代碼來源:lh.py

示例13: lh_aggregate

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def lh_aggregate(noisy_samples, domain, g, p, q):
    n = len(noisy_samples)

    est = np.zeros(domain, dtype=np.int32)
    for i in range(n):
        for v in range(domain):
            x = xxhash.xxh32(str(v), seed=noisy_samples[i][1]).intdigest() % g
            if noisy_samples[i][0] == x:
                est[v] += 1

    a = 1.0 / (p - q)
    b = n * q / (p - q)
    est = a * est - b

    return est 
開發者ID:vvv214,項目名稱:LDP_Protocols,代碼行數:17,代碼來源:fo.py

示例14: generateLocation1

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def generateLocation1(authticket, lat, lng, alt):
    firstHash = xxhash.xxh32(authticket, seed=static_seed).intdigest()
    locationBytes = d2h(lat) + d2h(lng) + d2h(alt)
    return xxhash.xxh32(locationBytes, seed=firstHash).intdigest() 
開發者ID:seikur0,項目名稱:PGO-mapscan-opt,代碼行數:6,代碼來源:uk6.py

示例15: generateLocation2

# 需要導入模塊: import xxhash [as 別名]
# 或者: from xxhash import xxh32 [as 別名]
def generateLocation2(lat, lng, alt):
    locationBytes = d2h(lat) + d2h(lng) + d2h(alt)
    return xxhash.xxh32(locationBytes, seed=static_seed).intdigest() 
開發者ID:seikur0,項目名稱:PGO-mapscan-opt,代碼行數:5,代碼來源:uk6.py


注:本文中的xxhash.xxh32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。