[yt-svn] commit/yt: MatthewTurk: Adding a hash cache

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Jan 27 14:27:22 PST 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/481d5a937fb8/
Changeset:   481d5a937fb8
Branch:      yt
User:        MatthewTurk
Date:        2016-01-27 20:57:59+00:00
Summary:     Adding a hash cache
Affected #:  2 files

diff -r 440902ffb795b23c044a09e96c3d1f2e1539273c -r 481d5a937fb8e369949bae0073a7777d71cc952f yt/geometry/selection_routines.pxd
--- a/yt/geometry/selection_routines.pxd
+++ b/yt/geometry/selection_routines.pxd
@@ -37,6 +37,8 @@
     cdef int overlap_cells
     cdef np.float64_t domain_width[3]
     cdef bint periodicity[3]
+    cdef bint _hash_initialized
+    cdef np.int64_t _hash
 
     cdef void recursively_visit_octs(self, Oct *root,
                         np.float64_t pos[3], np.float64_t dds[3],

diff -r 440902ffb795b23c044a09e96c3d1f2e1539273c -r 481d5a937fb8e369949bae0073a7777d71cc952f yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -119,6 +119,7 @@
 cdef class SelectorObject:
 
     def __cinit__(self, dobj, *args):
+        self._hash_initialized = 0
         cdef np.float64_t [:] DLE
         cdef np.float64_t [:] DRE
         self.min_level = getattr(dobj, "min_level", 0)
@@ -613,6 +614,8 @@
 
     def __hash__(self):
         # convert data to be hashed to a byte array, which FNV algorithm expects
+        if self._hash_initialized == 1:
+            return self._hash
         hash_data = bytearray()
         for v in self._hash_vals() + self._base_hash():
             if isinstance(v, tuple):
@@ -620,7 +623,10 @@
                 hash_data.extend(repr(v[1]).encode('ascii'))
             else:
                 hash_data.extend(repr(v).encode('ascii'))
-        return fnv_hash(hash_data)
+        cdef np.int64_t hash_value = fnv_hash(hash_data)
+        self._hash = hash_value
+        self._hash_initialized = 1
+        return hash_value
 
     def _hash_vals(self):
         raise NotImplementedError

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list