本文整理汇总了Python中xxhash.xxh64函数的典型用法代码示例。如果您正苦于以下问题:Python xxh64函数的具体用法?Python xxh64怎么用?Python xxh64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xxh64函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, tokens, length=100000):
"""Calculates a Charikar simhash with appropriate bitlength.
Input can be any iterable, but for strings it will automatically
break it into words first, assuming you don't want to iterate
over the individual characters. Returns nothing.
"""
if isinstance(tokens,basestring):
tokens = tokens.split()
v = {}
if isinstance(tokens,dict):
for value,w in tokens.iteritems():
k = xxhash.xxh64(value).intdigest()
x = v.get(k%length,0)
if k & 1 << 63:
v[k%length] = x + w
else:
v[k%length] = x - w
else:
for value in tokens:
k = xxhash.xxh64(value).intdigest()
x = v.get(k%length,0)
if k & 1 << 63:
v[k%length] = x + 1
else:
v[k%length] = x - 1
self.hash = v
self.vector = v
开发者ID:awesome-python,项目名称:similarities,代码行数:32,代码来源:feature_hash.py
示例2: _xxhash
def _xxhash(self):
"""
An xxhash.b64 hash of the array.
Returns
-------------
xx: int, xxhash.xxh64 hash of array.
"""
# repeat the bookkeeping to get a contiguous array inside
# the function to avoid additional function calls
# these functions are called millions of times so everything helps
if self._modified_x or not hasattr(self, '_hashed_xx'):
if self.flags['C_CONTIGUOUS']:
hasher = xxhash.xxh64(self)
self._hashed_xx = hasher.intdigest()
else:
# the case where we have sliced our nice
# contiguous array into a non- contiguous block
# for example (note slice *after* track operation):
# t = util.tracked_array(np.random.random(10))[::-1]
contiguous = np.ascontiguousarray(self)
hasher = xxhash.xxh64(contiguous)
self._hashed_xx = hasher.intdigest()
self._modified_x = False
return self._hashed_xx
开发者ID:mikedh,项目名称:trimesh,代码行数:25,代码来源:caching.py
示例3: __hash_from_argument
def __hash_from_argument(self, argument):
arg_string = ""
if hasattr(argument, 'md5hash'):
return argument.md5hash
if hasattr(argument, 'xxhash64'):
return argument.xxhash64
if type(argument) is numpy.ndarray:
if argument.size > 181440000:
return self.__hash_choice(argument.data)
else:
return str(xxhash.xxh64(argument.data))
if type(argument) is pandas.core.frame.DataFrame:
col_values_list = list(argument.columns.values)
try:
col_values_string = ''.join(col_values_list)
arg_string = col_values_string
if argument.values.size > 181440000:
return str(xxh.hash64(argument.data)) + "+" + str(xxhash.xxh64(arg_string))
else:
return self.__hash_choice(argument.values.data) + "+" + str(xxhash.xxh64(arg_string))
except:
if argument.values.size > 181440000:
return str(xxh.hash64(argument.values.data))
else:
return self.__hash_choice(argument.values.data)
if type(argument) is list or type(argument) is tuple:
arg_string = str(len(argument))
arg_string += str(argument)
return self.__hash_choice(arg_string)
开发者ID:onenoc,项目名称:memo,代码行数:29,代码来源:DecoratorFactory.py
示例4: hashRequests
def hashRequests(authTicket, payload):
baseHash = xxhash.xxh64(
authTicket.SerializeToString(),
seed=0x1B845238
).intdigest()
# Serialize and hash each request
return [xxhash.xxh64(
request.SerializeToString(),
seed=baseHash
).intdigest() for request in payload]
开发者ID:C-Sto,项目名称:pokemongo-api,代码行数:11,代码来源:util.py
示例5: string_hash
def string_hash(value,length=11):
s = ''
for i in range(0,length,11):
s = s + xxhash.xxh64(value+str(i)).hexdigest()
s = encode_hash(int(s,16))[:length]
if len(s) < length:
s = s + "A" * (length - len(s))
return s
开发者ID:awesome-python,项目名称:similarities,代码行数:8,代码来源:functions.py
示例6: string_hash_bits
def string_hash_bits(value,length_in_bits=128):
''' Length must be a multiple of 4'''
hex_length = length_in_bits / 4
s = ''
for i in range(0,length_in_bits,64):
s = s + xxhash.xxh64(value+str(i)).hexdigest()
s = s[:hex_length]
x = int(s,16)
return x
开发者ID:awesome-python,项目名称:similarities,代码行数:9,代码来源:functions.py
示例7: subscribe
def subscribe(request):
"""
Subcribe the given email to the given URL.
TODO BEN: Include Subscription title or description in POST variables
"""
url = request.POST['subscription_url']
email = request.POST['email']
user, created_user = User.objects.get_or_create(email=email)
if created_user:
user_verification_hash = uuid.uuid4().hex
user_verification = Verification.objects.create(
verified=False,
verification_hash=user_verification_hash)
user.verification = user_verification
user.save()
content, created_content = SubscribedContent.objects.get_or_create(url=url)
if created_content:
content_response = requests.get(url)
content_hash = xxhash.xxh64(content_response.text).hexdigest()
content.latest_content_hash = content_hash
if not Subscription.objects.filter(user=user, content=content).exists():
verification_hash = uuid.uuid4().hex
verification_url = request.build_absolute_uri(
reverse(
'verify',
kwargs={
'email': email,
'key': verification_hash}
)
)
verification_item = Verification.objects.create(
verified=False,
verification_hash=verification_hash
)
Subscription.objects.create(
user=user,
content=content,
verification=verification_item
)
email_sent = EMAIL.VERIFY_SUBSCRIPTION.send(
email, {'verification_url': verification_url})
if email_sent:
message = MESSAGES.EMAIL.VERIFICATION_SENT.format(email)
else:
message = MESSAGES.EMAIL.ERROR_SENDING_EMAIL.format(
email)
else:
message = MESSAGES.EMAIL.ALREADY_SUBSCRIBED
messages.add_message(request, messages.INFO, message)
return redirect(request.META['HTTP_REFERER'], {'message': message})
开发者ID:hias234,项目名称:OffenesParlament,代码行数:57,代码来源:subscriptions.py
示例8: xxhash64
def xxhash64(path, block_size=4096):
try:
with open(path, 'rb') as rf:
h = xxhash.xxh64()
for chunk in iter(lambda: rf.read(block_size), b''):
h.update(chunk)
return h.hexdigest(), path
except IOError:
return None, path
开发者ID:nbari,项目名称:ftrunk,代码行数:9,代码来源:read_dir_apply.py
示例9: hash
def hash(self):
"""Return hash of motif.
This is an unique identifier of a motif, regardless of the id.
Returns:
hash : str
"""
return xxhash.xxh64(self._pwm_to_str(3)).hexdigest()
开发者ID:simonvh,项目名称:gimmemotifs,代码行数:9,代码来源:motif.py
示例10: test_XXH64_reset
def test_XXH64_reset(self):
x = xxhash.xxh64()
h = x.intdigest()
for i in range(10, 50):
x.update(os.urandom(i))
x.reset()
self.assertEqual(h, x.intdigest())
开发者ID:pansapiens,项目名称:python-xxhash,代码行数:10,代码来源:test.py
示例11: save
def save(self, *args, **kwargs):
new_hash = xxhash.xxh64(self.content_raw).hexdigest()
mentioned_users = []
if new_hash != self.raw_content_hash or (not self.pk):
# To (re-)render the content if content changed or topic is newly created
self.content_rendered, mentioned_users = render_content(self.content_raw, sender=self.user.username)
super(Topic, self).save(*args, **kwargs)
self.raw_content_hash = new_hash
for to in mentioned_users:
notify.delay(to=to.username, sender=self.user.username, topic=self.pk)
开发者ID:Blackrose,项目名称:niji,代码行数:10,代码来源:models.py
示例12: xxhash_file
def xxhash_file(srcfile, logger, block_size=2**20):
f_name = func_name()
logger.info(f_name+"\t\tCalculating xx-hash on : "+srcfile)
f = open(srcfile, 'r')
x = xxhash.xxh64()
while True:
data = f.read(block_size)
if not data:
break
x.update(data)
return x.hexdigest()
开发者ID:cabrennan,项目名称:s3-boto-tools,代码行数:11,代码来源:b3GetFolder.py
示例13: cached_parse_dhcp
def cached_parse_dhcp(self, lines, cur_time=None):
if cur_time is None:
cur_time = dt.utcnow()
m = xxhash.xxh64()
m.update("".join(lines[:self.dhcp_cache_len]).encode("utf8"))
new_hash = m.digest()
# new_len = len(lines)
if new_hash != self.dhcp_hash:
self.dhcp_cache_len = 0
self.dhcp_cache = []
m = xxhash.xxh64()
lines = lines[self.dhcp_cache_len:]
self.dhcp_cache.extend(self.from_dhcp(lines, cur_time))
m.update("".join(lines).encode("utf8"))
self.dhcp_hash = m.digest()
self.dhcp_cache_len += len(lines)
return self.dhcp_cache
开发者ID:olage,项目名称:iasa-wifi,代码行数:20,代码来源:allow_rev3.py
示例14: generate_content_hashes
def generate_content_hashes(self):
"""
Generate a dictionary which maps parl_ids to their respective hashes
Used for speedy comparison of changes
"""
es_response = json.loads(self.get_content())
content_hashes = {}
for res in es_response['result']:
content_hashes[res['parl_id']] = xxhash.xxh64(
json.dumps(res)).hexdigest()
return json.dumps(content_hashes)
开发者ID:stefanm7,项目名称:OffenesParlament,代码行数:12,代码来源:models.py
示例15: memoize_wrapper
def memoize_wrapper(*args, **kwargs):
hash = xxhash.xxh64(str(args) + str(kwargs)).intdigest()
path = path_pattern.format(hash=hash)
try:
with open(path, 'rb') as file:
logger.debug("Loading pickle %s", path)
data = pickle.load(file)
except (FileNotFoundError, EOFError):
data = fn(*args, **kwargs)
with open(path, 'wb') as file:
pickle.dump(data, file)
return data
开发者ID:huilen,项目名称:hutils,代码行数:12,代码来源:memoize.py
示例16: test_XXH64
def test_XXH64(self):
x = xxhash.xxh64()
x.update('a')
self.assertEqual(xxhash.xxh64('a').digest(), x.digest())
x.update('b')
self.assertEqual(xxhash.xxh64('ab').digest(), x.digest())
x.update('c')
self.assertEqual(xxhash.xxh64('abc').digest(), x.digest())
seed = random.randint(0, 2**32)
x = xxhash.xxh64(seed=seed)
x.update('a')
self.assertEqual(xxhash.xxh64('a', seed).digest(), x.digest())
x.update('b')
self.assertEqual(xxhash.xxh64('ab', seed).digest(), x.digest())
x.update('c')
self.assertEqual(xxhash.xxh64('abc', seed).digest(), x.digest())
开发者ID:pansapiens,项目名称:python-xxhash,代码行数:16,代码来源:test.py
示例17: feature_hash_string
def feature_hash_string(s, window, dim):
start = time.clock()
# Generate window-char Markov chains & create feature hash vector
v = {}
for x in range(0, dim):
v[x] = 0
length = len(s)
max_num = 2.0 ** 64
for x in range(0, length - window):
key = xxhash.xxh64(s[x:x + window]) % dim
v[key] += 0x1
return numpy.asarray(v.values())
开发者ID:jbeisser,项目名称:blarpy,代码行数:16,代码来源:blar.py
示例18: _calculate
def _calculate(reaction, descriptorDict, verbose=False, whitelist=None):
"""Calculate descriptors for this plugin with descriptorDict already created."""
# descriptor Value classes
cat = DRP.models.CatRxnDescriptorValue
perm = DRP.models.CategoricalDescriptorPermittedValue
# reaction space descriptor
heading = 'rxnSpaceHash1'
if whitelist is None or heading in whitelist:
h = xxhash.xxh64() # generates a hash
for reactant in reaction.compounds.order_by('abbrev'):
h.update(reactant.abbrev)
p = perm.objects.get_or_create(descriptor=descriptorDict[
heading], value=h.hexdigest())[0]
cat.objects.update_or_create(defaults={
'value': p}, reaction=reaction, descriptor=descriptorDict['rxnSpaceHash1'])[0]
开发者ID:zhaojhao,项目名称:DRP,代码行数:16,代码来源:rxnhash.py
示例19: parse
def parse(self, response):
soup = BeautifulSoup(response.body)
for script in soup(["script", "style"]):
script.extract()
text = soup.get_text()
response.meta.update(score=KeywordScorer.score(text))
response.meta.update(
content_hash=xxhash.xxh64(text.encode('ascii', 'ignore')).intdigest())
for link in self.link_extractor.extract_links(response):
request = Request(url=link.url)
request.meta.update(link_text=link.text)
link_score = KeywordScorer.score(link.text)
request.meta.update(score=link_score)
yield request
开发者ID:okey,项目名称:aduana,代码行数:16,代码来源:example.py
示例20: wrapper
def wrapper(*args, **kwds):
if not cache:
return f(*args, **kwds)
if key_func:
key = 'django_vimeo_cache:{}'.format(key_func(*args, **kwds))
else:
key = 'django_vimeo_cache:' + f.__name__ + ':' +\
str(list(args) + list(sorted(kwds.items())))
key = xxhash.xxh64(key).hexdigest()
value = cache.get(key)
if value is None:
value = f(*args, **kwds)
cache.set(key, value, expires)
value = cache.get(key)
if value is None:
raise Exception('failed to fetch cached value, try again')
return value
开发者ID:suquant,项目名称:django-vimeo,代码行数:17,代码来源:cache.py
注:本文中的xxhash.xxh64函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论