mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-23 17:27:25 +00:00
standardize distance.py to int.from_bytes
This commit is contained in:
parent
cb9b348828
commit
518c447fef
1 changed files with 2 additions and 4 deletions
|
@ -1,5 +1,3 @@
|
||||||
from binascii import hexlify
|
|
||||||
|
|
||||||
from lbrynet.dht import constants
|
from lbrynet.dht import constants
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,10 +12,10 @@ class Distance:
|
||||||
if len(key) != constants.key_bits // 8:
|
if len(key) != constants.key_bits // 8:
|
||||||
raise ValueError("invalid key length: %i" % len(key))
|
raise ValueError("invalid key length: %i" % len(key))
|
||||||
self.key = key
|
self.key = key
|
||||||
self.val_key_one = int(hexlify(key), 16)
|
self.val_key_one = int.from_bytes(key, 'big')
|
||||||
|
|
||||||
def __call__(self, key_two):
|
def __call__(self, key_two):
|
||||||
val_key_two = int(hexlify(key_two), 16)
|
val_key_two = int.from_bytes(key_two, 'big')
|
||||||
return self.val_key_one ^ val_key_two
|
return self.val_key_one ^ val_key_two
|
||||||
|
|
||||||
def is_closer(self, a, b):
|
def is_closer(self, a, b):
|
||||||
|
|
Loading…
Add table
Reference in a new issue