mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Improve hashing algorithm
This commit is contained in:
parent
3756605a45
commit
6f9df8db26
2 changed files with 13 additions and 2 deletions
|
@ -17,6 +17,7 @@ from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.directories import get_mobject_data_dir
|
from manimlib.utils.directories import get_mobject_data_dir
|
||||||
from manimlib.utils.images import get_full_vector_image_path
|
from manimlib.utils.images import get_full_vector_image_path
|
||||||
|
from manimlib.utils.iterables import hash_obj
|
||||||
from manimlib.logger import log
|
from manimlib.logger import log
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,8 +64,7 @@ class SVGMobject(VMobject):
|
||||||
self.move_into_position()
|
self.move_into_position()
|
||||||
|
|
||||||
def init_svg_mobject(self):
|
def init_svg_mobject(self):
|
||||||
hasher = hashlib.sha256(str(self.hash_seed).encode())
|
hash_val = hash_obj(self.hash_seed)
|
||||||
hash_val = hasher.hexdigest()
|
|
||||||
if hash_val in SVG_HASH_TO_MOB_MAP:
|
if hash_val in SVG_HASH_TO_MOB_MAP:
|
||||||
mob = SVG_HASH_TO_MOB_MAP[hash_val].copy()
|
mob = SVG_HASH_TO_MOB_MAP[hash_val].copy()
|
||||||
self.add(*mob)
|
self.add(*mob)
|
||||||
|
|
|
@ -139,3 +139,14 @@ def remove_nones(sequence):
|
||||||
|
|
||||||
def concatenate_lists(*list_of_lists):
|
def concatenate_lists(*list_of_lists):
|
||||||
return [item for l in list_of_lists for item in l]
|
return [item for l in list_of_lists for item in l]
|
||||||
|
|
||||||
|
|
||||||
|
def hash_obj(obj):
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
new_obj = {k: hash_obj(v) for k, v in obj.items()}
|
||||||
|
return hash(tuple(frozenset(sorted(new_obj.items()))))
|
||||||
|
|
||||||
|
if isinstance(obj, (set, tuple, list)):
|
||||||
|
return hash(tuple([hash_obj(e) for e in obj]))
|
||||||
|
|
||||||
|
return hash(obj)
|
||||||
|
|
Loading…
Add table
Reference in a new issue